Spaces:
Sleeping
Sleeping
Commit
·
7885866
1
Parent(s):
3ebb262
Update app.py
Browse files
app.py
CHANGED
|
@@ -84,15 +84,31 @@ with gr.Blocks() as demo:
|
|
| 84 |
nms_boxes_output = []
|
| 85 |
|
| 86 |
# process the input image for inference/gradcam
|
| 87 |
-
input_img = cv2.resize(input_img, (416, 416))
|
| 88 |
-
input_img_copy = input_img.copy()
|
| 89 |
-
input_img = np.float32(input_img) / 255
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
transform = transforms.ToTensor()
|
| 91 |
-
|
| 92 |
|
| 93 |
# infer the image
|
| 94 |
inference_model.eval()
|
| 95 |
-
test_img_out = inference_model(
|
| 96 |
|
| 97 |
# process the outputs to create bounding boxes
|
| 98 |
for i in range(3):
|
|
@@ -124,13 +140,13 @@ with gr.Blocks() as demo:
|
|
| 124 |
|
| 125 |
target_layers = [inference_model.model]
|
| 126 |
cam = EigenCAM(inference_model, target_layers, use_cuda=False,reshape_transform=yolov3_reshape_transform)
|
| 127 |
-
grayscale_cam = cam(input_tensor =
|
| 128 |
grayscale_cam = grayscale_cam[0, :]
|
| 129 |
-
visualization = show_cam_on_image(input_img_copy
|
| 130 |
|
| 131 |
return (visualization,sections)
|
| 132 |
else:
|
| 133 |
-
return (np.array(
|
| 134 |
|
| 135 |
# app GUI
|
| 136 |
with gr.Row():
|
|
|
|
| 84 |
nms_boxes_output = []
|
| 85 |
|
| 86 |
# process the input image for inference/gradcam
|
| 87 |
+
# input_img = cv2.resize(input_img, (416, 416))
|
| 88 |
+
# input_img_copy = input_img.copy()
|
| 89 |
+
# input_img = np.float32(input_img) / 255
|
| 90 |
+
# transform = transforms.ToTensor()
|
| 91 |
+
# input_img = transform(input_img).unsqueeze(0)
|
| 92 |
+
|
| 93 |
+
# image transformation
|
| 94 |
+
test_transforms = Al.Compose(
|
| 95 |
+
[
|
| 96 |
+
Al.LongestMaxSize(max_size=416),
|
| 97 |
+
Al.PadIfNeeded(
|
| 98 |
+
min_height=416, min_width=416, border_mode=cv2.BORDER_CONSTANT
|
| 99 |
+
),
|
| 100 |
+
Al.Normalize(mean=[0, 0, 0], std=[1, 1, 1], max_pixel_value=255,),
|
| 101 |
+
#ToTensorV2(),
|
| 102 |
+
]
|
| 103 |
+
)
|
| 104 |
+
|
| 105 |
+
input_img_copy = test_transforms(image=input_img)['image']
|
| 106 |
transform = transforms.ToTensor()
|
| 107 |
+
input_img_tensor = transform(input_img_copy).unsqueeze(0)
|
| 108 |
|
| 109 |
# infer the image
|
| 110 |
inference_model.eval()
|
| 111 |
+
test_img_out = inference_model(input_img_tensor)
|
| 112 |
|
| 113 |
# process the outputs to create bounding boxes
|
| 114 |
for i in range(3):
|
|
|
|
| 140 |
|
| 141 |
target_layers = [inference_model.model]
|
| 142 |
cam = EigenCAM(inference_model, target_layers, use_cuda=False,reshape_transform=yolov3_reshape_transform)
|
| 143 |
+
grayscale_cam = cam(input_tensor = input_img_tensor, targets= targets)
|
| 144 |
grayscale_cam = grayscale_cam[0, :]
|
| 145 |
+
visualization = show_cam_on_image(input_img_copy, grayscale_cam, use_rgb=True, image_weight=gradcam_opa)
|
| 146 |
|
| 147 |
return (visualization,sections)
|
| 148 |
else:
|
| 149 |
+
return (np.array(input_img_tensor.squeeze(0).permute(1,2,0)),sections)
|
| 150 |
|
| 151 |
# app GUI
|
| 152 |
with gr.Row():
|