Commit ·
ffee944
1
Parent(s): b9963e2
Update README.md
Browse files
README.md
CHANGED
|
@@ -10,38 +10,43 @@ metrics:
|
|
| 10 |
pipeline_tag: image-classification
|
| 11 |
---
|
| 12 |
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
This project is about an image classification task of artificial and natural classes.
|
| 16 |
|
|
|
|
| 17 |
Setup:
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
|
| 22 |
Inference:
|
| 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 |
|
|
|
|
| 10 |
pipeline_tag: image-classification
|
| 11 |
---
|
| 12 |
|
| 13 |
+
Fatima 2023 Application
|
| 14 |
+
|
| 15 |
|
| 16 |
This project is about an image classification task of artificial and natural classes.
|
| 17 |
|
| 18 |
+
|
| 19 |
Setup:
|
| 20 |
|
| 21 |
+
pip install -r requirements.txt
|
| 22 |
|
| 23 |
|
| 24 |
Inference:
|
| 25 |
|
| 26 |
|
| 27 |
+
from torchvision import transforms
|
| 28 |
+
from PIL import Image
|
| 29 |
+
import torch
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
inference_transform = transforms.Compose([
|
| 33 |
+
transforms.Resize(128),
|
| 34 |
+
transforms.ToTensor(),
|
| 35 |
+
transforms.Normalize(mean=[0.4914, 0.4822, 0.4465],
|
| 36 |
+
std=[0.2023, 0.1994, 0.2010]),
|
| 37 |
+
])
|
| 38 |
+
|
| 39 |
+
#load image and model
|
| 40 |
+
img_example = Image.open("image_example.png").convert('RGB')
|
| 41 |
+
print("image loaded!")
|
| 42 |
+
model_loaded = torch.load("fatima_challenge_model_exp3.pt")
|
| 43 |
+
model_loaded.eval()
|
| 44 |
+
print("model loaded!")
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
img_example_transformed = inference_transform(img_example)
|
| 48 |
+
out = model_loaded(img_example_transformed.to(torch.device("cuda:0")).unsqueeze(0)) # Generate predictions
|
| 49 |
+
_, outs = torch.max(out, 1)
|
| 50 |
+
prediction = "natural" if int(outs.cpu().numpy())==0 else "artificial"
|
| 51 |
+
print("prediction = ",prediction)
|
| 52 |
|