CristianLazoQuispe commited on
Commit
b9963e2
1 Parent(s): 6bcf8c8

inference pipeline

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