Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -68,33 +68,16 @@ carTransforms = transforms.Compose([transforms.Resize(224),
|
|
| 68 |
|
| 69 |
def classifyCar(im):
|
| 70 |
#im = Image.fromarray(im.astype('uint8'), 'RGB')
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
|
| 82 |
-
except Exception as err:
|
| 83 |
-
return im, {"error2": 0.5}
|
| 84 |
-
try:
|
| 85 |
-
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
|
| 86 |
-
except Exception as err:
|
| 87 |
-
return im, {"error3": 0.5}
|
| 88 |
-
try:
|
| 89 |
-
im2 = carTransforms(im).unsqueeze(0) # transform and add batch dimension
|
| 90 |
-
except:
|
| 91 |
-
return Image.fromarray(np.uint8(out.get_image())).convert('RGB'), {"error4": 0.5}
|
| 92 |
-
try:
|
| 93 |
-
with torch.no_grad():
|
| 94 |
-
scores = torch.nn.functional.softmax(DesignModernityModel(im2)[0])
|
| 95 |
-
except:
|
| 96 |
-
return Image.fromarray(np.uint8(out.get_image())).convert('RGB'), {"error5": 0.5}
|
| 97 |
-
return Image.fromarray(np.uint8(out.get_image())).convert('RGB'), {LABELS[i]: float(scores[i]) for i in range(n_labels)}
|
| 98 |
|
| 99 |
#examples = [[example_img.jpg], [example_img2.jpg]] # must be uploaded in repo
|
| 100 |
|
|
|
|
| 68 |
|
| 69 |
def classifyCar(im):
|
| 70 |
#im = Image.fromarray(im.astype('uint8'), 'RGB')
|
| 71 |
+
im = cv2.imread(im)
|
| 72 |
+
with torch.no_grad():
|
| 73 |
+
outputs = predictor(im)
|
| 74 |
+
v = Visualizer(im[:, :, ::-1], MetadataCatalog.get(cfg.DATASETS.TRAIN[0]), scale=1.2)
|
| 75 |
+
out = v.draw_instance_predictions(outputs["instances"].to("cpu"))
|
| 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])
|
| 79 |
+
#{LABELS[i]: float(scores[i]) for i in range(n_labels)}
|
| 80 |
+
return Image.fromarray(np.uint8(out.get_image())).convert('RGB'), "test"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
#examples = [[example_img.jpg], [example_img2.jpg]] # must be uploaded in repo
|
| 83 |
|