rigvedrs / YOLO-V8-CAM

Wanna know what your model sees? Here's a package for applying EigenCAM on the new YOLO V8 model
MIT License
100 stars 17 forks source link

issue with segmentation type #16

Open fatemeh-mohseni-AI opened 2 months ago

fatemeh-mohseni-AI commented 2 months ago
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 commented 1 month ago

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)))