Skip to content

Commit

Permalink
Fix an RGB conversion issue. (jacobgil#89)
Browse files Browse the repository at this point in the history
* Fixes an RGB conversion issue.

1. The input image is RGB so use_rgb must be set to True in ``show_cam_on_image``
2. The returned cam_image is RGB encoded whereas cv2.imwrite requires BGR. Switch encoding of cam_image from RGB to BGR prior to writing.

* Change BGR2RGB -> RGB2BGR
  • Loading branch information
ujjwalx authored May 28, 2021
1 parent 5a4ae6f commit c6e820d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion cam.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ def get_args():
# Here grayscale_cam has only one image in the batch
grayscale_cam = grayscale_cam[0, :]

cam_image = show_cam_on_image(rgb_img, grayscale_cam)
cam_image = show_cam_on_image(rgb_img, grayscale_cam, use_rgb=True)

# cam_image is RGB encoded whereas "cv2.imwrite" requires BGR encoding.
cam_image = cv2.cvtColor(cam_image, cv2.COLOR_RGB2BGR)

gb_model = GuidedBackpropReLUModel(model=model, use_cuda=args.use_cuda)
gb = gb_model(input_tensor, target_category=target_category)
Expand Down

0 comments on commit c6e820d

Please sign in to comment.