Your Name commited on
Commit
6692a2b
·
1 Parent(s): 41a6ef4

first 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
+ effnet_b2.pt filter=lfs diff=lfs merge=lfs -text
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import os
4
+ from model import create_effnet_b2
5
+ from timeit import default_timer as timer
6
+ from typing import Tuple, Dict
7
+
8
+ class_names = ["pizza", "steak", "sushi"]
9
+
10
+ effbet_b2_model , efftnet_b2_transform = create_effnet_b2()
11
+
12
+ effbet_b2_model.load_state_dict(torch.load(f = "./effnet_b2.pt", map_location = torch.device("cpu")))
13
+
14
+ def predict(img)-> Tuple[Dict,float]:
15
+
16
+ start_time = timer()
17
+ img = efftnet_b2_transform(img).unsqueeze(0)
18
+
19
+ effbet_b2_model.eval()
20
+
21
+ with torch.inference_mode():
22
+ pred_prob = torch.softmax(effbet_b2_model(img), 1)
23
+
24
+ pred_label_probs = {class_names[i] : float(pred_prob[0][i]) for i in range(len(class_names))}
25
+
26
+ end_time = timer()
27
+ pred_time = round(end_time - start_time , 4)
28
+
29
+ return pred_label_probs, pred_time
30
+
31
+
32
+ import os
33
+ # Create separate output components
34
+ exmaple_list = [["examples/" + example] for example in os.listdir("examples")]
35
+ label_output = gr.Label(label="Classification Probabilities")
36
+ number_output = gr.Number(label="Inference Time (seconds)") # Changed label to be more accurate
37
+
38
+ demo = gr.Interface(
39
+ fn=predict,
40
+ inputs="image",
41
+ outputs=[label_output, number_output],
42
+ examples=exmaple_list, # Handle case where image_path might be None
43
+ title="Food Vision Mini 🍕",
44
+ description="Upload an image to see classification probabilities and inference time.Finetuned on effnet_b2 on(pizza,steak,sushi)",
45
+ article="Created By sachin",
46
+ allow_flagging="never"
47
+ )
48
+
49
+ demo.launch(share=True, debug=True)
50
+
51
+
52
+
53
+
effnet_b2.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:7e11a4d8c93f583b364335ba2b333b819489a2a583df792e03abc377ab1ef963
3
+ size 31267706
examples/420409.jpg ADDED
examples/44810.jpg ADDED
examples/930553.jpg ADDED
model.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from torchvision.models import EfficientNet_B2_Weights, efficientnet_b2
3
+ from torch import nn
4
+
5
+ def create_effnet_b2(num_classes:int = 3, seed:int = 42):
6
+
7
+ eff_weights = EfficientNet_B2_Weights.DEFAULT
8
+ efficientnet_transform = eff_weights.transforms()
9
+
10
+ effnet_model = efficientnet_b2(eff_weights)
11
+
12
+
13
+ for params in effnet_model.parameters():
14
+ params.requires_grad = False
15
+
16
+ torch.manual_seed(seed=seed)
17
+
18
+ effnet_model.classifier = nn.Sequential(
19
+ nn.Dropout(p=0.3, inplace=True),
20
+ nn.Linear(in_features=1408, out_features=num_classes, bias=True)
21
+ )
22
+
23
+
24
+ return effnet_model, efficientnet_transform
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch==2.6.0
2
+ torchvision==0.21.0
3
+ gradio==5.16.0
4
+