File size: 1,557 Bytes
330d92f
 
 
 
 
356ab9f
 
 
330d92f
 
 
 
41032e7
76f813b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9fb8739
 
76f813b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
license: mit
datasets:
- microsoft/cats_vs_dogs
---
# Report Issue
If you encounter any problems with downloading or using the model, please report the issue by creating one at the following GitHub repository: https://github.com/parneetsingh022/dog-cat-classification.git 

# Demo

https://huggingface.co/spaces/parneetsingh022/cat-vs-dog

# Loading and using the model.
In order to download and use the model follow these steps:
1. Clone this reposetory:
```
git clone https://github.com/parneetsingh022/dog-cat-classification.git
```

2. Download transformers liberary
```
pip install transformers
```
3.
After installation, you can utilize the model in other scripts outside of this directory `custom_classifier` as described below:

Required Imports:
```python
import torch
from PIL import Image
from torchvision import transforms

from custom_classifier.configuration import CustomModelConfig
from custom_classifier.model import CustomClassifier
```

Loading the model:
```python
model_name = "parneetsingh022/dog-cat-classification"
config = CustomModelConfig.from_pretrained(model_name)
model = CustomClassifier.from_pretrained(model_name, config=config)
```

Pridicting probability of individual class:
```python
# Load an example image
image_path = "dog.jpeg"
outputs = model.predict(image_path)
print(outputs)
```
Output: {'cat': 0.003, 'dog': 0.997}

Getting class name instead of probabilities:
```python
# Load an example image
image_path = "dog_new.jpeg"
outputs = model.predict(image_path, get_class=True)

print(output)
```
Output: 'dog'