shinyice commited on
Commit
6f668a4
1 Parent(s): 4a5c602

Push model using huggingface_hub.

Browse files
Files changed (3) hide show
  1. README.md +2 -79
  2. config.json +1 -1
  3. model.safetensors +2 -2
README.md CHANGED
@@ -2,85 +2,8 @@
2
  tags:
3
  - model_hub_mixin
4
  - pytorch_model_hub_mixin
5
- - image-classification
6
- - densenet121
7
- language:
8
- - ja
9
  ---
10
 
11
  This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
12
-
13
- # Densenet121-Dog-Emotions Model Card
14
-
15
- - **学習データでの正答率:** 0.6451
16
- - **テストデータでの正答率:** 0.5938
17
-
18
- # モデルについて
19
- このモデルはPytorchのdensenet121をdevzohaib/dog-emotions-predictionデータセットで微調整し、犬の画像を[angry, happy, relaxed, sad]の4つのカテゴリに分類するモデルです。<br>
20
- 使い方は以下のようになっています。
21
-
22
-
23
- ## 使い方
24
- 1. モデルの読み込み
25
- ```sh
26
- from huggingface_hub import PyTorchModelHubMixin
27
- import torch
28
- import torch.nn as nn
29
- from torchvision import models, transforms
30
- from PIL import Image
31
- import requests
32
-
33
- class CustomDenseNet(nn.Module, PyTorchModelHubMixin):
34
- def __init__(self, class_names):
35
- super().__init__()
36
- self.densenet = models.densenet121(pretrained=True)
37
- num_features = self.densenet.classifier.in_features
38
- self.densenet.classifier = nn.Linear(num_features, 1000)
39
- self.class_names = class_names
40
-
41
- def forward(self, x):
42
- outputs = self.densenet(x)
43
- _, preds = torch.max(outputs, 1)
44
- probabilities = torch.nn.functional.softmax(outputs, dim=1).squeeze(0)
45
-
46
- predicted_class = self.class_names[preds.item()]
47
- predicted_probabilities = {self.class_names[i]: probabilities[i].item() for i in range(len(self.class_names))}
48
-
49
- return predicted_class, predicted_probabilities
50
-
51
- model_id = "shinyice/densenet121-dog-emotions"
52
- class_names = ['angry', 'happy', 'relaxed', 'sad']
53
- model = CustomDenseNet(class_names)
54
- model = model.from_pretrained(model_id)
55
-
56
- device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
57
- model.to(device)
58
- ```
59
-
60
- 2. 画像分類
61
- ```sh
62
- def dog_emotion(model, url_mode=False, input_image=None):
63
- img_transforms = transforms.Compose([
64
- transforms.Resize(224),
65
- transforms.ToTensor(),
66
- transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225])])
67
- if url_mode:
68
- image = Image.open(requests.get(input_image, stream=True).raw).convert('RGB')
69
- else:
70
- image = Image.open(input_image).convert('RGB')
71
- image_tensor = img_transforms(image).unsqueeze(0)
72
- image_tensor = image_tensor.to(device)
73
-
74
- model.eval()
75
- with torch.no_grad():
76
- predicted_class, predicted_probabilities = model(image_tensor)
77
-
78
- return predicted_class, predicted_probabilities, image
79
-
80
- url_mode = True
81
- input_image = ""
82
-
83
- emotion,probabilities, image = dog_emotion(model=model, url_mode=url_mode, input_image=input_image)
84
- print(emotion,probabilities)
85
- image
86
- ```
 
2
  tags:
3
  - model_hub_mixin
4
  - pytorch_model_hub_mixin
 
 
 
 
5
  ---
6
 
7
  This model has been pushed to the Hub using the [PytorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) integration:
8
+ - Library: [More Information Needed]
9
+ - Docs: [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
config.json CHANGED
@@ -5,5 +5,5 @@
5
  "relaxed",
6
  "sad"
7
  ],
8
- "num_classes": 4
9
  }
 
5
  "relaxed",
6
  "sad"
7
  ],
8
+ "pretrained_path": "/content/drive/MyDrive/\u79d1\u5b66\u5927\u30cf\u30c3\u30ab\u30bd\u30f3/model.pth"
9
  }
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:13e36f599649e2754d43dcae498d605d2a4fbcf99bfc06cba44a61f1b0ca09f2
3
- size 32340976
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:03df04d4dc62935dd86a44f525498e8739d9e0fbdaf5268dfcab95e7ba02af03
3
+ size 32357544