Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -34,7 +34,7 @@ cfg.merge_from_file(model_zoo.get_config_file("COCO-InstanceSegmentation/mask_rc
|
|
| 34 |
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 # set threshold for this model
|
| 35 |
# Find a model from detectron2's model zoo. You can use the https://dl.fbaipublicfiles... url as well
|
| 36 |
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
|
| 37 |
-
|
| 38 |
predictor = DefaultPredictor(cfg)
|
| 39 |
'''
|
| 40 |
os.system(wget http://images.cocodataset.org/val2017/000000439715.jpg -q -O input.jpg)
|
|
@@ -66,10 +66,13 @@ carTransforms = transforms.Compose([transforms.Resize(224),
|
|
| 66 |
|
| 67 |
def classifyCar(im):
|
| 68 |
im = Image.fromarray(im.astype('uint8'), 'RGB')
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
|
|
|
|
|
|
| 73 |
im2 = carTransforms(im).unsqueeze(0) # transform and add batch dimension
|
| 74 |
with torch.no_grad():
|
| 75 |
scores = torch.nn.functional.softmax(DesignModernityModel(im2)[0])
|
|
|
|
| 34 |
cfg.MODEL.ROI_HEADS.SCORE_THRESH_TEST = 0.5 # set threshold for this model
|
| 35 |
# Find a model from detectron2's model zoo. You can use the https://dl.fbaipublicfiles... url as well
|
| 36 |
cfg.MODEL.WEIGHTS = model_zoo.get_checkpoint_url("COCO-InstanceSegmentation/mask_rcnn_R_50_FPN_3x.yaml")
|
| 37 |
+
cfg.MODEL.DEVICE= 'cpu'
|
| 38 |
predictor = DefaultPredictor(cfg)
|
| 39 |
'''
|
| 40 |
os.system(wget http://images.cocodataset.org/val2017/000000439715.jpg -q -O input.jpg)
|
|
|
|
| 66 |
|
| 67 |
def classifyCar(im):
|
| 68 |
im = Image.fromarray(im.astype('uint8'), 'RGB')
|
| 69 |
+
try:
|
| 70 |
+
with torch.no_grad():
|
| 71 |
+
outputs = predictor(im)
|
| 72 |
+
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
|
| 73 |
+
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
|
| 74 |
+
except Exception as err:
|
| 75 |
+
return im, {err: float(0.5)}
|
| 76 |
im2 = carTransforms(im).unsqueeze(0) # transform and add batch dimension
|
| 77 |
with torch.no_grad():
|
| 78 |
scores = torch.nn.functional.softmax(DesignModernityModel(im2)[0])
|