PDG commited on
Commit
d01979a
·
1 Parent(s): 958d113

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -4
app.py CHANGED
@@ -14,7 +14,7 @@ os.system('pip install git+https://github.com/facebookresearch/detectron2.git')
14
  os.system('pip install pyyaml==5.1')
15
 
16
  import detectron2
17
- '''
18
  from detectron2.utils.logger import setup_logger # ????
19
 
20
  from detectron2 import model_zoo
@@ -32,7 +32,7 @@ cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 # set threshold for this model
32
  # Find a model from detectron2's model zoo. You can use the https://dl.fbaipublicfiles... url as well
33
  cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
34
  predictor = DefaultPredictor(cfg)
35
-
36
  os.system(wget http://images.cocodataset.org/val2017/000000439715.jpg -q -O input.jpg)
37
  im = cv2.imread("./input.jpg")
38
  cv2_imshow(im)
@@ -64,13 +64,16 @@ def classifyCar(im):
64
  im = Image.fromarray(im.astype('uint8'), 'RGB')
65
  im = carTransforms(im).unsqueeze(0) # transform and add batch dimension
66
  with torch.no_grad():
 
 
 
67
  scores = torch.nn.functional.softmax(DesignModernityModel(im)[0])
68
- return {LABELS[i]: float(scores[i]) for i in range(n_labels)}
69
 
70
  #examples = [[example_img.jpg], [example_img2.jpg]] # must be uploaded in repo
71
 
72
  # create interface for model
73
- interface = gr.Interface(classifyCar, inputs='image', outputs='label', cache_examples=False, title='VW Up or Fiat 500')
74
  interface.launch()
75
 
76
 
 
14
  os.system('pip install pyyaml==5.1')
15
 
16
  import detectron2
17
+
18
  from detectron2.utils.logger import setup_logger # ????
19
 
20
  from detectron2 import model_zoo
 
32
  # Find a model from detectron2's model zoo. You can use the https://dl.fbaipublicfiles... url as well
33
  cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
34
  predictor = DefaultPredictor(cfg)
35
+ '''
36
  os.system(wget http://images.cocodataset.org/val2017/000000439715.jpg -q -O input.jpg)
37
  im = cv2.imread("./input.jpg")
38
  cv2_imshow(im)
 
64
  im = Image.fromarray(im.astype('uint8'), 'RGB')
65
  im = carTransforms(im).unsqueeze(0) # transform and add batch dimension
66
  with torch.no_grad():
67
+ outputs = predictor(im)
68
+ v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
69
+ out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
70
  scores = torch.nn.functional.softmax(DesignModernityModel(im)[0])
71
+ return Image.fromarray(np.uint8(out.get_image())).convert('RGB'), {LABELS[i]: float(scores[i]) for i in range(n_labels)}
72
 
73
  #examples = [[example_img.jpg], [example_img2.jpg]] # must be uploaded in repo
74
 
75
  # create interface for model
76
+ interface = gr.Interface(classifyCar, inputs='image', outputs=['image','label'], cache_examples=False, title='VW Up or Fiat 500')
77
  interface.launch()
78
 
79