Anshu13 commited on
Commit
87b3ac1
·
1 Parent(s): b87587e

first commit

Browse files
Files changed (14) hide show
  1. .gitattributes +1 -0
  2. 0pr_food.pth +3 -0
  3. Ex/107871.jpg +0 -0
  4. Ex/2582289.jpg +0 -0
  5. Ex/3622237.jpg +0 -0
  6. Ex/592799.jpg +0 -0
  7. Ex/8093.jpg +0 -0
  8. Ex/81705.jpg +0 -0
  9. Ex/82946.jpg +0 -0
  10. app.py +26 -0
  11. class_names.txt +7 -0
  12. model.py +13 -0
  13. requirements.txt +3 -0
  14. zip +0 -0
.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
+ 0pr_food.pth filter=lfs diff=lfs merge=lfs -text
0pr_food.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:1dda579ec9a9442254372397d99d56a350d047ceead84386afad9a8436728b7f
3
+ size 31296826
Ex/107871.jpg ADDED
Ex/2582289.jpg ADDED
Ex/3622237.jpg ADDED
Ex/592799.jpg ADDED
Ex/8093.jpg ADDED
Ex/81705.jpg ADDED
Ex/82946.jpg ADDED
app.py ADDED
@@ -0,0 +1,26 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import os
3
+ import torch
4
+ from model import create_effnetb2_model
5
+ from timeit import default_timer as timer
6
+ from typing import Tuple,Dict
7
+
8
+ with open("class_names.txt","r") as f:
9
+ class_names = [food_name.strip() for food_name in f.readlines()]
10
+ effnetb2,effnetb2_transforms=create_effnetb2(classes=7)
11
+ effnetb2.load_state_dict(torch.load(f="0pr_food.pth",map_location=torch.device("cpu")))
12
+ def predict(img)-> Tuple[Dict,float]:
13
+ start_timer=timer()
14
+ img=effnetb2_transforms(img).unsqueeze(0)
15
+ effnetb2.eval()
16
+ with torch.inference_mode():
17
+ pred_probs=torch.softmax(effnetb2(img),dim=1)
18
+ pred_labels_and_probs={class_names[i]:float(pred_probs[0][i] for i in range(len(class_names)))}
19
+ pred_time=round(timer()-start_timer,5)
20
+ return pred_labels_and_probs,pred_time
21
+ title="FoodVision"
22
+ description="An EfficientNetB2 feature extractor computer vision model to classify images of & food [samosa,pizza,steak,sushi,cup cakes,french fries,omelette]"
23
+ article="Created at [Foodvision.ipynb]"
24
+ example_list=[["Ex/"+ example] for example in os.listdir("Ex")]
25
+ demo=gr.Interface(fn=predict,inputs=gr.Image(type="pil"),outputs=[gr.Label(num_top_classes=2,label="Preditions"),gr.Number(label="Predcition time(s)")],examples=example_list,title=title,description=description,article=article)
26
+ demo.launch()
class_names.txt ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ cup_cakes
2
+ french_fries
3
+ omelette
4
+ pizza
5
+ samosa
6
+ steak
7
+ sushi
model.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ import torchvision
3
+ from torch import nn
4
+
5
+ def create_effnetb2(classes:int=3,seed:int=42):
6
+ weights=torchvision.models.EfficientNet_B2_Weights.DEFAULT
7
+ transforms=weights.transforms()
8
+ model=torchvision.models.efficientnet_b2(weights=weights)
9
+ for p in model.parameters():
10
+ p.requires_grad=False
11
+ torch.manual_seed(seed)
12
+ model.classifier=nn.Sequential(nn.Dropout(p=0.3,inplace=True),nn.Linear(1408,classes))
13
+ return model,transforms
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ torch==2.5.1
2
+ torchvision==0.20.1
3
+ gradio==5.29.1
zip ADDED
File without changes