jflo commited on
Commit
069c641
1 Parent(s): 7af369b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -21,7 +21,7 @@ class_names = ['Apple Pie','Bibimbap','Cannoli','Edamame','Falafel','French Toas
21
  # Returns transformed image
22
  def transform_img(img):
23
  return the_transform(img)
24
-
25
  # Returns string with class and probability
26
  def classify_img(img):
27
  # Applying transformation to the image
@@ -35,21 +35,21 @@ def classify_img(img):
35
 
36
  # Converting values to softmax values
37
  result = F.softmax(result,dim=1)
38
-
39
  # Grabbing top 3 indices and probabilities for each index
40
  top3_prob, top3_catid = torch.topk(result,3)
41
 
42
  # Dictionary I will display
43
  model_output = {}
44
  for i in range(top3_prob.size(1)):
45
- model_output[class_names[top3_catid[0][i].item()]] = round(top3_prob[0][i].item())
46
 
 
 
47
  return model_output
48
-
49
  demo = gr.Interface(classify_img,
50
  inputs = gr.inputs.Image(type="pil"),
51
  outputs = gr.outputs.Label(type="confidences",num_top_classes=3),
52
- description="Insert food image you would like to classify! Returns confidence % for top three categories <br> Categories: Apple Pie, Bibimbap, Cannoli, Edamame, Falafel, French Toast, Ice Cream, Ramen, Sushi, Tiramisu"
53
  )
54
 
55
  demo.launch()
 
21
  # Returns transformed image
22
  def transform_img(img):
23
  return the_transform(img)
24
+
25
  # Returns string with class and probability
26
  def classify_img(img):
27
  # Applying transformation to the image
 
35
 
36
  # Converting values to softmax values
37
  result = F.softmax(result,dim=1)
 
38
  # Grabbing top 3 indices and probabilities for each index
39
  top3_prob, top3_catid = torch.topk(result,3)
40
 
41
  # Dictionary I will display
42
  model_output = {}
43
  for i in range(top3_prob.size(1)):
 
44
 
45
+ model_output[class_names[top3_catid[0][i].item()]] = top3_prob[0][i].item()
46
+ print(model_output)
47
  return model_output
48
+
49
  demo = gr.Interface(classify_img,
50
  inputs = gr.inputs.Image(type="pil"),
51
  outputs = gr.outputs.Label(type="confidences",num_top_classes=3),
52
+ description="Insert food image you would like to classify! Returns confidence % for the top three categories <br> Categories: Apple Pie, Bibimbap, Cannoli, Edamame, Falafel, French Toast, Ice Cream, Ramen, Sushi, Tiramisu"
53
  )
54
 
55
  demo.launch()