czkaiweb commited on
Commit
d8a104d
·
1 Parent(s): f4d989e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -5
app.py CHANGED
@@ -27,7 +27,7 @@ def inference(input_image):
27
  transforms.Resize(256),
28
  transforms.CenterCrop(224),
29
  transforms.ToTensor(),
30
- transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
31
  ])
32
  input_tensor = preprocess(input_image)
33
  input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model
@@ -42,7 +42,7 @@ def inference(input_image):
42
  with torch.no_grad():
43
  output = model(input_batch)
44
  # The output has unnormalized scores. To get probabilities, you can run a softmax on it.
45
- probabilities = torch.nn.functional.softmax(output[0], dim=1)
46
 
47
  # Read the categories
48
  with open("artist_classes.txt", "r") as f:
@@ -61,14 +61,13 @@ def inference(input_image):
61
  top5_prob, top5_catid = torch.topk(probabilities, 6)
62
  result = {}
63
  for i in range(top5_prob.size(0)):
64
- result[categories[top5_catid[i]]] = top5_prob[i].item()
65
- print(result)
66
  return result
67
 
68
  inputs = gr.Image(type='pil')
69
  outputs = gr.Label(type="confidences",num_top_classes=5)
70
 
71
- title = "MOBILENET V2"
72
  description = "Gradio demo for MOBILENET V2, Efficient networks optimized for speed and memory, with residual blocks. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
73
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1801.04381'>MobileNetV2: Inverted Residuals and Linear Bottlenecks</a> | <a href='https://github.com/pytorch/vision/blob/master/torchvision/models/mobilenet.py'>Github Repo</a></p>"
74
 
 
27
  transforms.Resize(256),
28
  transforms.CenterCrop(224),
29
  transforms.ToTensor(),
30
+ #transforms.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
31
  ])
32
  input_tensor = preprocess(input_image)
33
  input_batch = input_tensor.unsqueeze(0) # create a mini-batch as expected by the model
 
42
  with torch.no_grad():
43
  output = model(input_batch)
44
  # The output has unnormalized scores. To get probabilities, you can run a softmax on it.
45
+ probabilities = torch.nn.functional.softmax(output[0], dim=0)
46
 
47
  # Read the categories
48
  with open("artist_classes.txt", "r") as f:
 
61
  top5_prob, top5_catid = torch.topk(probabilities, 6)
62
  result = {}
63
  for i in range(top5_prob.size(0)):
64
+ result[categories[top5_catid[i],item()]] = top5_prob[i].item()
 
65
  return result
66
 
67
  inputs = gr.Image(type='pil')
68
  outputs = gr.Label(type="confidences",num_top_classes=5)
69
 
70
+ title = "Artist Classifier"
71
  description = "Gradio demo for MOBILENET V2, Efficient networks optimized for speed and memory, with residual blocks. To use it, simply upload your image, or click one of the examples to load them. Read more at the links below."
72
  article = "<p style='text-align: center'><a href='https://arxiv.org/abs/1801.04381'>MobileNetV2: Inverted Residuals and Linear Bottlenecks</a> | <a href='https://github.com/pytorch/vision/blob/master/torchvision/models/mobilenet.py'>Github Repo</a></p>"
73