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 |
-
cfg.MODEL.DEVICE= 'cpu'
|
| 38 |
predictor = DefaultPredictor(cfg)
|
| 39 |
'''
|
| 40 |
os.system(wget http://images.cocodataset.org/val2017/000000439715.jpg -q -O input.jpg)
|
|
@@ -46,7 +46,7 @@ outputs = predictor(im)
|
|
| 46 |
print(outputs["instances"].pred_classes)
|
| 47 |
print(outputs["instances"].pred_boxes)
|
| 48 |
'''
|
| 49 |
-
# -- load
|
| 50 |
DesignModernityModel = torch.load("DesignModernityModel.pt")
|
| 51 |
|
| 52 |
#INPUT_FEATURES = DesignModernityModel.fc.in_features
|
|
@@ -70,9 +70,9 @@ def classifyCar(im):
|
|
| 70 |
outputs = predictor(im)
|
| 71 |
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
|
| 72 |
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
|
| 73 |
-
|
| 74 |
with torch.no_grad():
|
| 75 |
-
scores = torch.nn.functional.softmax(DesignModernityModel(
|
| 76 |
return Image.fromarray(np.uint8(out.get_image())).convert('RGB'), {LABELS[i]: float(scores[i]) for i in range(n_labels)}
|
| 77 |
|
| 78 |
#examples = [[example_img.jpg], [example_img2.jpg]] # must be uploaded in repo
|
|
|
|
| 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)
|
|
|
|
| 46 |
print(outputs["instances"].pred_classes)
|
| 47 |
print(outputs["instances"].pred_boxes)
|
| 48 |
'''
|
| 49 |
+
# -- load design modernity model for classification
|
| 50 |
DesignModernityModel = torch.load("DesignModernityModel.pt")
|
| 51 |
|
| 52 |
#INPUT_FEATURES = DesignModernityModel.fc.in_features
|
|
|
|
| 70 |
outputs = predictor(im)
|
| 71 |
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
|
| 72 |
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
|
| 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])
|
| 76 |
return Image.fromarray(np.uint8(out.get_image())).convert('RGB'), {LABELS[i]: float(scores[i]) for i in range(n_labels)}
|
| 77 |
|
| 78 |
#examples = [[example_img.jpg], [example_img2.jpg]] # must be uploaded in repo
|