PDG commited on
Commit
abfce60
·
1 Parent(s): 2f0508c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -80,12 +80,13 @@ def classifyCar(im):
80
  boxes = list(outputs["instances"].pred_boxes[car_class_true])
81
  max_idx = torch.tensor([(x[2] - x[0])*(x[3] - x[1]) for x in boxes]).argmax().item()
82
 
83
- im2 = Image.fromarray(np.uint8(out.get_image())).convert('RGB').crop(boxes[max_idx].to(torch.int64).numpy())
84
 
85
  carTransforms = transforms.Compose([transforms.Resize((224, 224))])
86
  im2 = carTransforms(im2)
87
 
88
  label = "success"
 
89
  except:
90
  label = "fail2"
91
  #im2 = carTransforms(im).unsqueeze(0) # transform and add batch dimension
@@ -93,12 +94,12 @@ def classifyCar(im):
93
  # scores = torch.nn.functional.softmax(DesignModernityModel(im2)[0])
94
  #{LABELS[i]: float(scores[i]) for i in range(n_labels)}
95
  #Image.fromarray(np.uint8(out.get_image())).convert('RGB')
96
- return label
97
 
98
  #examples = [[example_img.jpg], [example_img2.jpg]] # must be uploaded in repo
99
 
100
  # create interface for model
101
- interface = gr.Interface(classifyCar, inputs='image', outputs=['label'], cache_examples=False, title='VW Up or Fiat 500')
102
  interface.launch()
103
 
104
 
 
80
  boxes = list(outputs["instances"].pred_boxes[car_class_true])
81
  max_idx = torch.tensor([(x[2] - x[0])*(x[3] - x[1]) for x in boxes]).argmax().item()
82
 
83
+ im2 = Image.fromarray(np.uint8(im)).convert('RGB').crop(boxes[max_idx].to(torch.int64).numpy())
84
 
85
  carTransforms = transforms.Compose([transforms.Resize((224, 224))])
86
  im2 = carTransforms(im2)
87
 
88
  label = "success"
89
+ img = Image.toarray(im2)
90
  except:
91
  label = "fail2"
92
  #im2 = carTransforms(im).unsqueeze(0) # transform and add batch dimension
 
94
  # scores = torch.nn.functional.softmax(DesignModernityModel(im2)[0])
95
  #{LABELS[i]: float(scores[i]) for i in range(n_labels)}
96
  #Image.fromarray(np.uint8(out.get_image())).convert('RGB')
97
+ return label, img
98
 
99
  #examples = [[example_img.jpg], [example_img2.jpg]] # must be uploaded in repo
100
 
101
  # create interface for model
102
+ interface = gr.Interface(classifyCar, inputs='image', outputs=['image','label'], cache_examples=False, title='VW Up or Fiat 500')
103
  interface.launch()
104
 
105