Smaranjit Ghose
commited on
Commit
•
e66e641
1
Parent(s):
bc86e54
Added Usage Guide
Browse files
README.md
CHANGED
@@ -50,7 +50,34 @@ A visual transformer is used as the base model. After fine-tuning, the classifie
|
|
50 |
> - Since the model has been trained on a small dataset of approximately 500 images (in total), testing on various subspecies found among the populations of each member of the big cats is to be done. For example, The robustness of the model to classify all Bengal Tigers, Siberian Tigers, Indochinese Tigers, and Malayan Tigers as Tigers
|
51 |
> - Lastly, the performance of the model in categorizing certain rare variants in the populations of big cats such as white tigers, snow leopards or black jaguar has not been determined exclusively.
|
52 |
|
|
|
53 |
|
54 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
55 |
|
56 |
[Hugging Pics](https://github.com/nateraw/huggingpics)
|
|
|
50 |
> - Since the model has been trained on a small dataset of approximately 500 images (in total), testing on various subspecies found among the populations of each member of the big cats is to be done. For example, The robustness of the model to classify all Bengal Tigers, Siberian Tigers, Indochinese Tigers, and Malayan Tigers as Tigers
|
51 |
> - Lastly, the performance of the model in categorizing certain rare variants in the populations of big cats such as white tigers, snow leopards or black jaguar has not been determined exclusively.
|
52 |
|
53 |
+
## Usage
|
54 |
|
55 |
+
```python
|
56 |
+
from PIL import Image
|
57 |
+
import matplotlib.pyplot as plt
|
58 |
+
from transformers import ViTFeatureExtractor, ViTForImageClassification
|
59 |
+
|
60 |
+
def identify_big_cat(img_path:str)->str:
|
61 |
+
"""
|
62 |
+
Function that reads an image of a big cat (belonging to Panthera family) and returns the corresponding species
|
63 |
+
"""
|
64 |
+
img = Image.open(img_path)
|
65 |
+
model_panthera = ViTForImageClassification.from_pretrained("smaranjitghose/big-cat-classifier")
|
66 |
+
feature_extractor = ViTFeatureExtractor.from_pretrained('smaranjitghose/big-cat-classifier')
|
67 |
+
inputs = feature_extractor(images=image, return_tensors="pt")
|
68 |
+
outputs = model_panthera(**inputs)
|
69 |
+
logits = outputs.logits
|
70 |
+
predicted_class_idx = logits.argmax(-1).item()
|
71 |
+
return model_panthera.config.id2label[predicted_class_idx]
|
72 |
+
|
73 |
+
|
74 |
+
our_big_cat = identify_big_cat("path_of_the_image")
|
75 |
+
print(f"Predicted species: {our_big_cat}" )
|
76 |
+
|
77 |
+
|
78 |
+
|
79 |
+
```
|
80 |
+
|
81 |
+
## Reference and Acknowledgement:
|
82 |
|
83 |
[Hugging Pics](https://github.com/nateraw/huggingpics)
|