Aditya Sah commited on
Commit ·
8021009
1
Parent(s): 895a6fe
Initial GoVed-AI model upload
Browse files- Readme.md +18 -0
- bovine_model.pth +3 -0
- inference.py +47 -0
Readme.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🐄 GoVed-AI: Indian Cattle & Buffalo Breed Classifier
|
| 2 |
+
|
| 3 |
+
GoVed-AI is a deep learning model trained to classify 40+ Indian cattle and buffalo breeds using **ResNet-18**.
|
| 4 |
+
|
| 5 |
+
## 🚀 Usage
|
| 6 |
+
You can use the Hugging Face Inference API:
|
| 7 |
+
|
| 8 |
+
```python
|
| 9 |
+
from huggingface_hub import InferenceClient
|
| 10 |
+
from PIL import Image
|
| 11 |
+
|
| 12 |
+
client = InferenceClient("username/GoVed-AI")
|
| 13 |
+
|
| 14 |
+
result = client.post(
|
| 15 |
+
json={"inputs": "https://example.com/cow.jpg"}
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
print(result)
|
bovine_model.pth
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:0f56d9712d45af4f1e7dded9c6dc07243a95ae586445aa0e987057124669efea
|
| 3 |
+
size 16540501
|
inference.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import torch.nn as nn
|
| 3 |
+
import torchvision.models as models
|
| 4 |
+
import torchvision.transforms as transforms
|
| 5 |
+
from PIL import Image
|
| 6 |
+
|
| 7 |
+
# ----------------------------
|
| 8 |
+
# Labels (all breeds)
|
| 9 |
+
# ----------------------------
|
| 10 |
+
breeds = [
|
| 11 |
+
"Alambadi", "Amritmahal", "Ayrshire", "Banni", "Bargur", "Bhadawari", "Brown_Swiss",
|
| 12 |
+
"Dangi", "Deoni", "Gir", "Guernsey", "Hallikar", "Hariana", "Holstein_Friesian",
|
| 13 |
+
"Jaffrabadi", "Jersey", "Kangayam", "Kankrej", "Kasargod", "Kenkatha", "Kherigarh",
|
| 14 |
+
"Khillari", "Krishna_Valley", "Malnad_gidda", "Mehsana", "Murrah", "Nagori", "Nagpuri",
|
| 15 |
+
"Nili_Ravi", "Nimari", "Ongole", "Pulikulam", "Rathi", "Red_Dane", "Red_Sindhi",
|
| 16 |
+
"Sahiwal", "Surti", "Tharparkar", "Toda", "Umblachery", "Vechur"
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
# ----------------------------
|
| 20 |
+
# Load Model
|
| 21 |
+
# ----------------------------
|
| 22 |
+
def load_model():
|
| 23 |
+
model = models.resnet18(pretrained=False)
|
| 24 |
+
model.fc = nn.Linear(model.fc.in_features, len(breeds))
|
| 25 |
+
model.load_state_dict(torch.load("bovine_model.pth", map_location="cpu"))
|
| 26 |
+
model.eval()
|
| 27 |
+
return model
|
| 28 |
+
|
| 29 |
+
model = load_model()
|
| 30 |
+
|
| 31 |
+
# ----------------------------
|
| 32 |
+
# Image Preprocessing
|
| 33 |
+
# ----------------------------
|
| 34 |
+
transform = transforms.Compose([
|
| 35 |
+
transforms.Resize((224, 224)),
|
| 36 |
+
transforms.ToTensor(),
|
| 37 |
+
])
|
| 38 |
+
|
| 39 |
+
# ----------------------------
|
| 40 |
+
# Prediction Function
|
| 41 |
+
# ----------------------------
|
| 42 |
+
def predict(image: Image.Image):
|
| 43 |
+
img = transform(image).unsqueeze(0)
|
| 44 |
+
with torch.no_grad():
|
| 45 |
+
outputs = model(img)
|
| 46 |
+
_, predicted = torch.max(outputs, 1)
|
| 47 |
+
return {"breed": breeds[predicted.item()]}
|