Ojimi commited on
Commit
607d375
·
1 Parent(s): d6cdb78

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +55 -1
README.md CHANGED
@@ -4,4 +4,58 @@ pipeline_tag: image-classification
4
  tags:
5
  - pytorch
6
  - vision
7
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  tags:
5
  - pytorch
6
  - vision
7
+ ---
8
+
9
+ This model is the product of curiosity—imagine a choice that allows you to label anime images!
10
+
11
+ **Disclaimer**: The model has been trained on an entirely new dataset. Predictions made by the model *prior to 2023 might be off*. It's advisable to fine-tune the model according to your specific use case.
12
+
13
+ # Quick setup guide:
14
+
15
+ ```python
16
+ from transformers.modeling_outputs import ImageClassifierOutput
17
+ from transformers import ViTImageProcessor, ViTForImageClassification
18
+ import torch
19
+ from PIL import Image
20
+
21
+ model_name_or_path = "vit-anime-base/"
22
+ processor = ViTImageProcessor.from_pretrained(model_name_or_path)
23
+ model = ViTForImageClassification.from_pretrained(model_name_or_path)
24
+ threshold = 0.3
25
+
26
+ device = torch.device('cuda')
27
+
28
+ image = Image.open(YOUR_IMAGE_PATH)
29
+
30
+ inputs = processor(image, return_tensors='pt')
31
+
32
+ model.to(device=device)
33
+ model.eval()
34
+
35
+
36
+ with torch.no_grad():
37
+ pixel_values = inputs['pixel_values'].to(device=device)
38
+
39
+ outputs : ImageClassifierOutput = model(pixel_values=pixel_values)
40
+
41
+ logits = outputs.logits # The raw scores before applying any activation
42
+ sigmoid = torch.nn.Sigmoid() # Sigmoid function to convert logits to probabilities
43
+ logits : torch.FloatTensor = sigmoid(logits) # Applying sigmoid activation
44
+
45
+ predictions = [] # List to store predictions
46
+
47
+ for idx, p in enumerate(logits[0]):
48
+ if p > threshold: # Applying a threshold of 0.3 to consider a class prediction
49
+ predictions.append((model.config.id2label[idx], p.item())) # Storing class label and probability
50
+
51
+ for tag in predictions:
52
+ print(tag)
53
+
54
+
55
+ ```
56
+
57
+ Why the `Sigmoid`?
58
+ - Sigmoid turns boring scores into fun probabilities, so you can use thresholds and find more cool tags.
59
+ - It's like a wizard turning regular stuff into magic potions!
60
+
61
+ [Training guide](/training_guide.md)