LucyintheSky commited on
Commit
baae411
·
verified ·
1 Parent(s): a017238

Rename README (2).md to README.md

Browse files
Files changed (2) hide show
  1. README (2).md +0 -44
  2. README.md +68 -0
README (2).md DELETED
@@ -1,44 +0,0 @@
1
- ---
2
- license: apache-2.0
3
- base_model: google/vit-base-patch16-224-in21k
4
- tags:
5
- - generated_from_trainer
6
- metrics:
7
- - accuracy
8
- model-index:
9
- - name: pose-estimation-front-side-back
10
- results: []
11
- ---
12
-
13
- # Pose Estimation: front,side,back
14
-
15
- ## Model description
16
- This model predicts the person's body position relative to the camera: **front, side, back**. It was trained on [Lucy in the Sky](https://www.lucyinthesky.com/shop) images.
17
-
18
- This model is a fine-tuned version of [google/vit-base-patch16-224-in21k](https://huggingface.co/google/vit-base-patch16-224-in21k).
19
-
20
- ## Training and evaluation data
21
- It achieves the following results on the evaluation set:
22
- - Loss: 0.2524
23
- - Accuracy: 0.9355
24
-
25
- ### Training hyperparameters
26
-
27
- The following hyperparameters were used during training:
28
- - learning_rate: 5e-05
29
- - train_batch_size: 16
30
- - eval_batch_size: 16
31
- - seed: 42
32
- - gradient_accumulation_steps: 4
33
- - total_train_batch_size: 64
34
- - optimizer: Adam with betas=(0.9,0.999) and epsilon=1e-08
35
- - lr_scheduler_type: linear
36
- - lr_scheduler_warmup_ratio: 0.1
37
- - num_epochs: 20
38
-
39
- ### Framework versions
40
-
41
- - Transformers 4.34.0
42
- - Pytorch 2.0.1+cu118
43
- - Datasets 2.14.5
44
- - Tokenizers 0.14.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
README.md ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: swin_s3_base_224
4
+ ---
5
+
6
+ # Feature Prediction
7
+
8
+ ## Model description
9
+
10
+
11
+ ## How to use
12
+
13
+ ```python
14
+ import torch
15
+ import torchvision.transforms as transforms
16
+ from PIL import Image
17
+ from safetensors.torch import load_model
18
+ from huggingface_hub import hf_hub_download
19
+ from timm import list_models, create_model
20
+ import os
21
+ import numpy as np
22
+
23
+ # Download model from hub
24
+ os.makedirs('/content/swin_s3_base_224', exist_ok=True)
25
+ hf_hub_download(repo_id="LucyintheSky/lucy-feature-prediction", filename="model.safetensors", local_dir="/content/swin_s3_base_224")
26
+
27
+ # Intialize the model
28
+ model_name='swin_s3_base_224'
29
+ model = create_model(
30
+ model_name,
31
+ num_classes=36
32
+ )
33
+ load_model(model,f'./{model_name}/model.safetensors')
34
+
35
+ # Define class names
36
+ class_names = ["3/4 Sleeve", "Accessory", "Babydoll", "Closed Back", "Corset", "Crochet", "Cutouts", "Draped", "Floral", "Gloves", "Halter", "Lace", "Long", "Long Sleeve", "Midi", "No Slit", "Off The Shoulder", "One Shoulder", "Open Back", "Pockets", "Print", "Puff Sleeve", "Ruched", "Satin", "Sequins", "Shimmer", "Short", "Short Sleeve", "Side Slit", "Square Neck", "Strapless", "Sweetheart Neck", "Tight", "V-Neck", "Velvet", "Wrap"]
37
+ label2id = {c:idx for idx,c in enumerate(class_names)}
38
+ id2label = {idx:c for idx,c in enumerate(class_names)}
39
+
40
+ def predict_features(image_path):
41
+ # Load PIL image
42
+ pil_image = Image.open(image_path).convert('RGB')
43
+
44
+ # Define transformations to resize and convert image to tensor
45
+ transform = transforms.Compose([
46
+ transforms.Resize((224, 224)),
47
+ transforms.ToTensor()
48
+ ])
49
+ tensor_image = transform(pil_image)
50
+
51
+ inputs = tensor_image.unsqueeze(0)
52
+
53
+ with torch.no_grad():
54
+ logits = model(inputs)
55
+
56
+ # apply sigmoid activation to convert logits to probabilities
57
+ # getting labels with confidence threshold of 0.5
58
+ predictions = logits.sigmoid() > 0.5
59
+
60
+ # converting one-hot encoded predictions back to list of labels
61
+ predictions = predictions.float().numpy().flatten() # convert boolean predictions to float
62
+ pred_labels = np.where(predictions==1)[0] # find indices where prediction is 1
63
+ pred_labels = ([id2label[label] for label in pred_labels]) # converting integer labels to string
64
+
65
+ return pred_labels
66
+
67
+ predict_features('image.jpg')
68
+ ```