noelsinghsr commited on
Commit
d88ab8c
1 Parent(s): bd722fa

initial commit

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ airplane_uncompiled.pth filter=lfs diff=lfs merge=lfs -text
airplane_uncompiled.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:28c3c11a6aba10b22eac86bccabcd23e56bb2a3258f380ba9f6c258b173e4ddb
3
+ size 31356145
airplanes.zip ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:b14163fcf18a027d04c245c56f525076a26c37799c95a7688c1f4cf2d3f99f19
3
+ size 30536510
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import torch
4
+
5
+ from model import load_model
6
+ from timeit import default_timer as timer
7
+ from typing import Tuple, Dict
8
+
9
+ # class names
10
+ class_names = ['A-10', 'C-130', 'F-16']
11
+
12
+ model, transform = load_model()
13
+
14
+ # predict function
15
+ def predict(img):
16
+
17
+ start_time = timer()
18
+
19
+ img = transform(img).unsqueeze(0)
20
+
21
+ model.eval()
22
+ with torch.inference_mode():
23
+ pred_probs = torch.softmax(model(img), dim=1)
24
+
25
+ pred_labels_and_probs = {class_names[i]: float(pred_probs[0][i]) for i in range(len(class_names))}
26
+
27
+ end_time = timer()
28
+
29
+ pred_time = round(end_time - start_time, 4)
30
+
31
+ return pred_labels_and_probs, pred_time
32
+
33
+
34
+
35
+ title = "Military Aircraft predictor - Efficinet_B2 Computer Vision Model (PyTorch)"
36
+
37
+ description = "An EfficientNetB2 feature extractor computer vision model to classify Custom Dataset of F-16 Fighter Jet, C-130 Hercules, A-10 Warthog"
38
+
39
+ article = "Created in SageMaker Studio"
40
+
41
+ example_list = [["examples/" + example] for example in os.listdir("examples")]
42
+
43
+ # Gradio app
44
+ demo = gr.Interface(fn=predict,
45
+ inputs=gr.Image(type="pil"),
46
+ outputs=[gr.Label(num_top_classes=10, label="Predictions"),
47
+ gr.Number(label="Prediction time (s)")],
48
+ examples=example_list,
49
+ title=title,
50
+ description=description,
51
+ article=article)
examples/f16.jpg ADDED
examples/warthog.jpg ADDED
model.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torchvision
3
+ from torch import nn
4
+
5
+ def load_model():
6
+
7
+ loaded_model = torch.load('demo/airplanes/airplane_uncompiled.pth', map_location=torch.device('cpu'))
8
+ model_weights = torchvision.models.EfficientNet_B2_Weights.DEFAULT
9
+ transforms = model_weights.transforms()
10
+
11
+ return loaded_model, transforms
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch
2
+ torchvision
3
+ gradio