Closed msadoun closed 11 months ago
Yes you will have this issue since the output will come wrong on every first run. Since you are not running this in a notebook, a temporary fix for this can be by running the model twice on the image and outputting the second output generated. The first output will always be inaccurate, but all the subsequent outputs will be the same and accurate.
# Run this twice
grayscale_cam = cam(rgb_img)[0, :, :]
grayscale_cam = cam(rgb_img)[0, :, :]
# Rest remains the same
cam_image = show_cam_on_image(img, grayscale_cam, use_rgb=True)
plt.imshow(cam_image)
plt.show()
I tried to implement your exact GRAD-CAM on the "puppies" image with your attached "yolov8n.pt".
But some how I seem to get different heatmap. Here is my implementation script
`if name == 'main': from ultralytics import YOLO from yolo_cam.eigen_cam import EigenCAM from yolo_cam.utils.image import show_cam_on_image, scale_cam_image import warnings warnings.filterwarnings('ignore') warnings.simplefilter('ignore') import torch
import cv2 import numpy as np import matplotlib.pyplot as plt import requests import torchvision.transforms as transforms from PIL import Image import io
When I uncomment
results = model(source = test ,device = 0, line_width = 3, save = True) # return a list of Results objects
the generated image is
in both cases "yolov8n.pt" detects the image as follows
so my question: what went wrong here?