Manoj779944 commited on
Commit
c294ccf
·
verified ·
1 Parent(s): 0437a68

Delete app.py

Browse files
Files changed (1) hide show
  1. app.py +0 -45
app.py DELETED
@@ -1,45 +0,0 @@
1
-
2
- import gradio as gr
3
- import os
4
- import torch
5
- from model import create_effnetb2_model
6
- from timeit import default_timer as Timer
7
- from typing import Tuple,Dict
8
- class_names=["pizza","steak","sushi"]
9
- effnetb2,effnetb2_transforms=create_effnetb2_model(num_classes=3)
10
- effnetb2.load_state_dict(
11
- torch.load(
12
- f="09_pretrained_effnetb2_feature_extractor_pizza_steak_sushi_20_percent.pth",
13
- map_location=torch.device("cpu")
14
- )
15
- )g
16
-
17
- def predict(img) -> Tuple[Dict,float]:
18
- start_time = timer()
19
- img = effnetb2_transforms(img).unsqueeze(0)
20
-
21
- effnetb2.eval()
22
- with torch.inference_mode():
23
- pred_probs = torch.softmax(effnetb2(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
- pred_time = round(timer() - start_time, 5)
27
- return pred_labels_and_probs, pred_time
28
-
29
-
30
- title = "FoodVision Mini 🍕🥩🍣"
31
- description = "An EfficientNetB2 feature extractor computer vision model to classify images of food as pizza, steak or sushi."
32
- article = "Created at [09. PyTorch Model Deployment](https://www.learnpytorch.io/09_pytorch_model_deployment/)."
33
-
34
- example_list = [["examples/" + example] for example in os.listdir("examples")]
35
-
36
- demo = gr.Interface(fn=predict,
37
- inputs=gr.Image(type="pil"),
38
- outputs=[gr.Label(num_top_classes=3, label="Predictions"),
39
- gr.Number(label="Prediction time (s)")],
40
- examples=example_list,
41
- title=title,
42
- description=description,
43
- article=article)
44
-
45
- demo.launch()