Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -73,11 +73,18 @@ def classifyCar(im):
|
|
| 73 |
label = "fail"
|
| 74 |
try:
|
| 75 |
outputs = predictor(im)
|
| 76 |
-
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1
|
| 77 |
out = v.draw_instance_predictions(outputs["instances"])
|
|
|
|
| 78 |
car_class_true = outputs["instances"].pred_classes == 2
|
| 79 |
-
boxes = outputs["instances"].pred_boxes[car_class_true]
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
label = "success"
|
| 82 |
except:
|
| 83 |
label = "fail2"
|
|
|
|
| 73 |
label = "fail"
|
| 74 |
try:
|
| 75 |
outputs = predictor(im)
|
| 76 |
+
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1)
|
| 77 |
out = v.draw_instance_predictions(outputs["instances"])
|
| 78 |
+
|
| 79 |
car_class_true = outputs["instances"].pred_classes == 2
|
| 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"
|