Edesak commited on
Commit
423bf0c
·
1 Parent(s): 55fabdb

init comit

Browse files
EffB2_food_big.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5a815dc64e9e98586947c7b136bb27437abcb7e6064733eb4a805c9e7166ea2c
3
+ size 31829435
Examples/194643.jpg ADDED
Examples/27415.jpg ADDED
Examples/46797.jpg ADDED
Examples/5658.jpg ADDED
__pycache__/model.cpython-310.pyc ADDED
Binary file (739 Bytes). View file
 
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ from timeit import default_timer as timer
3
+ from typing import Tuple, Dict
4
+
5
+ import gradio as gr
6
+ import torch
7
+
8
+ from model import create_model
9
+
10
+ title = "Food Vision Mini by Edesak"
11
+ desc = "EffitientNetB2 for recognition of Food with 101 classes from [Zero To Mastery Course](https://www.udemy.com/course/pytorch-for-deep-learning/). Used Dataset if Food 101"
12
+ article = "My Github page [Edesak](https://github.com/Edesak)"
13
+
14
+ filename = "labels.txt"
15
+
16
+ with open(filename, "r") as file:
17
+ class_names = file.read().split("\n")
18
+ class_names = class_names[:-1]
19
+
20
+ model, transform = create_model()
21
+ model.load_state_dict(torch.load(f="EffB2_food_big.pth", map_location=torch.device('cpu')))
22
+ model.to("cpu")
23
+ example_list = [["Examples/" + example] for example in os.listdir("Examples")]
24
+
25
+
26
+ def predict(img) -> Tuple[Dict, float]:
27
+ start_timer = timer()
28
+ img = transform(img).unsqueeze(0)
29
+
30
+ model.eval()
31
+ with torch.inference_mode():
32
+ y = torch.softmax(model(img), dim=1)
33
+
34
+ pred_labels = {class_names[i]: float(y[0][i]) for i in range(len(class_names))}
35
+ end_time = timer()
36
+ pred_time = round(end_time - start_timer, 4)
37
+ return pred_labels, pred_time
38
+
39
+
40
+ demo = gr.Interface(fn=predict, inputs=gr.Image(type="pil"),
41
+ outputs=[gr.Label(num_top_classes=3, label="Predictions"), gr.Number(label="Prediction time (s)")],
42
+ title=title,
43
+ description=desc,
44
+ article=article,
45
+ examples=example_list)
46
+
47
+ demo.launch()
labels.txt ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Apple pie
2
+ Baby back ribs
3
+ Baklava
4
+ Beef carpaccio
5
+ Beef tartare
6
+ Beet salad
7
+ Beignets
8
+ Bibimbap
9
+ Bread pudding
10
+ Breakfast burrito
11
+ Bruschetta
12
+ Caesar salad
13
+ Cannoli
14
+ Caprese salad
15
+ Carrot cake
16
+ Ceviche
17
+ Cheesecake
18
+ Cheese plate
19
+ Chicken curry
20
+ Chicken quesadilla
21
+ Chicken wings
22
+ Chocolate cake
23
+ Chocolate mousse
24
+ Churros
25
+ Clam chowder
26
+ Club sandwich
27
+ Crab cakes
28
+ Creme brulee
29
+ Croque madame
30
+ Cup cakes
31
+ Deviled eggs
32
+ Donuts
33
+ Dumplings
34
+ Edamame
35
+ Eggs benedict
36
+ Escargots
37
+ Falafel
38
+ Filet mignon
39
+ Fish and chips
40
+ Foie gras
41
+ French fries
42
+ French onion soup
43
+ French toast
44
+ Fried calamari
45
+ Fried rice
46
+ Frozen yogurt
47
+ Garlic bread
48
+ Gnocchi
49
+ Greek salad
50
+ Grilled cheese sandwich
51
+ Grilled salmon
52
+ Guacamole
53
+ Gyoza
54
+ Hamburger
55
+ Hot and sour soup
56
+ Hot dog
57
+ Huevos rancheros
58
+ Hummus
59
+ Ice cream
60
+ Lasagna
61
+ Lobster bisque
62
+ Lobster roll sandwich
63
+ Macaroni and cheese
64
+ Macarons
65
+ Miso soup
66
+ Mussels
67
+ Nachos
68
+ Omelette
69
+ Onion rings
70
+ Oysters
71
+ Pad thai
72
+ Paella
73
+ Pancakes
74
+ Panna cotta
75
+ Peking duck
76
+ Pho
77
+ Pizza
78
+ Pork chop
79
+ Poutine
80
+ Prime rib
81
+ Pulled pork sandwich
82
+ Ramen
83
+ Ravioli
84
+ Red velvet cake
85
+ Risotto
86
+ Samosa
87
+ Sashimi
88
+ Scallops
89
+ Seaweed salad
90
+ Shrimp and grits
91
+ Spaghetti bolognese
92
+ Spaghetti carbonara
93
+ Spring rolls
94
+ Steak
95
+ Strawberry shortcake
96
+ Sushi
97
+ Tacos
98
+ Takoyaki
99
+ Tiramisu
100
+ Tuna tartare
101
+ Waffles
model.py ADDED
@@ -0,0 +1,18 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+ from torch.nn import Dropout, Linear
3
+ from torchvision.models import EfficientNet_B2_Weights, efficientnet_b2
4
+
5
+
6
+ def create_model():
7
+ weights = EfficientNet_B2_Weights.DEFAULT
8
+ model = efficientnet_b2(weights=weights)
9
+ transform = weights.transforms()
10
+
11
+ classifier = torch.nn.Sequential(
12
+ Dropout(p=0.3, inplace=True),
13
+ Linear(in_features=1408, out_features=101)
14
+ )
15
+ for layer in model.features:
16
+ layer.requires_grad_(False)
17
+ model.classifier = classifier
18
+ return model, transform
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio==3.33.1
2
+ torch==1.13.0
3
+ torchvision==0.14.0