setsosie commited on
Commit
5af7084
·
verified ·
1 Parent(s): ea90889

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -25,13 +25,17 @@ def predict(img):
25
  confidences: python dictionary containing confidences
26
  '''
27
  # Transform image to pytorch tensor of shape [1, 3, 224, 224]
 
28
  img = T.PILToTensor()(img).unsqueeze(0)
 
29
  img = T.Resize(size=(224, 224))(img)
 
30
 
31
  # Use model without gradients to reduce computation
32
  with torch.no_grad():
33
  # Get the tensor that contains the predictions
34
- prediction = F.softmax(model(img)[0], dim=0)
 
35
  # Turn the above tensor into a dictionary with the humand-readable label and probability.
36
  confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
37
 
@@ -41,4 +45,4 @@ gr.Interface(fn=predict,
41
  inputs=gr.Image(type="pil"),
42
  outputs=gr.Label(num_top_classes=10),
43
  theme="default",
44
- ).launch()
 
25
  confidences: python dictionary containing confidences
26
  '''
27
  # Transform image to pytorch tensor of shape [1, 3, 224, 224]
28
+ print(type(img))
29
  img = T.PILToTensor()(img).unsqueeze(0)
30
+ print(type(img))
31
  img = T.Resize(size=(224, 224))(img)
32
+ print(type(img))
33
 
34
  # Use model without gradients to reduce computation
35
  with torch.no_grad():
36
  # Get the tensor that contains the predictions
37
+ out = model(img)
38
+ prediction = F.softmax(out[0], dim=0)
39
  # Turn the above tensor into a dictionary with the humand-readable label and probability.
40
  confidences = {labels[i]: float(prediction[i]) for i in range(1000)}
41
 
 
45
  inputs=gr.Image(type="pil"),
46
  outputs=gr.Label(num_top_classes=10),
47
  theme="default",
48
+ ).launch(share=True)