Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue with segmentation type #16

Open
fatemeh-mohseni-AI opened this issue Apr 23, 2024 · 1 comment
Open

issue with segmentation type #16

fatemeh-mohseni-AI opened this issue Apr 23, 2024 · 1 comment

Comments

@fatemeh-mohseni-AI
Copy link

fatemeh-mohseni-AI commented Apr 23, 2024

img = cv2.imread(f'/home/fatemeh/Documents/training datasets/adsf/train/images/{img_name}')
img = cv2.resize(img, (640, 640))

rgb_img = img.copy()
img = np.float32(img) / 255
target_layers =[model.model.model[-4]]
cam = EigenCAM(model, target_layers,task='seg')
grayscale_cam = cam(rgb_img)[0, :, :]
cam_image = show_cam_on_image(img, grayscale_cam, use_rgb=True)
plt.imshow(cam_image)
plt.show()
im = cv2.cvtColor(rgb_img, cv2.COLOR_RGB2BGR)
Image.fromarray(np.hstack((im, cam_image)))

File "/home/fatemeh/develop/YOLO_/YOLO-V8-CAM/yolo_cam/base_cam.py", line 87, in forward
targets = [ClassifierOutputTarget(category) for category in target_categories]
UnboundLocalError: local variable 'target_categories' referenced before assignment

@sujaykumarmag
Copy link

sujaykumarmag commented May 25, 2024

Yolo-v8 Segmentation also consists of bbox

you can change the task to "od" instead of "see" which helps to solve the error.

img = cv2.imread(f'/home/fatemeh/Documents/training datasets/adsf/train/images/{img_name}')
img = cv2.resize(img, (640, 640))
rgb_img = img.copy()
img = np.float32(img) / 255
target_layers =[model.model.model[-4]]
cam = EigenCAM(model, target_layers,task='od')
grayscale_cam = cam(rgb_img)[0, :, :]
cam_image = show_cam_on_image(img, grayscale_cam, use_rgb=True)
plt.imshow(cam_image)
plt.show()
im = cv2.cvtColor(rgb_img, cv2.COLOR_RGB2BGR)
Image.fromarray(np.hstack((im, cam_image)))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants