Comments (2)
Hey thanks for your kind words. This is a good question, it made me realise one extra thing about this project. I shall add an update for it and let you know more about this soon. For starters you can also try using print(model.model) for understanding the structure.
from yolo-v8-cam.
To extract the specific layer within the model object, you will have to loop across its Sequential Block and extract the exact layer you need. You can then use it to generate the heatmap for it.
For example to extract the last Conv layer, you can pass it like this:
from torch.nn import Conv2d
c2f_module = model.model.model[-1]
tgt_layer = []
# # Iterate through the sub-modules of C2f
for sub_module in c2f_module.modules():
if isinstance(sub_module, Conv2d):
if sub_module.in_channels == 80 and sub_module.out_channels == 80 and sub_module.kernel_size == (1, 1) and sub_module.stride == (1, 1):
tgt_layer = sub_module
print(tgt_layer)
You can then pass this extracted layer stored in tgt_layer as a list:
target_layers = [tgt_layer]
cam = EigenCAM(model, target_layers, use_cuda=False)
grayscale_cam = cam(rgb_img)[0, :, :]
cam_image = show_cam_on_image(img, grayscale_cam, use_rgb=True)
Image.fromarray(cam_image)
Rest of the steps remain same. The results may not be as you expect though with regards to the generated heatmaps. You can try experimenting with different layers and see the outputs.
from yolo-v8-cam.
Related Issues (20)
- Add code to handle segmentation and pose detection models as well HOT 1
- Same input as yours but different results HOT 1
- taking too long HOT 1
- My Grad Cam is giving opposite results. HOT 2
- Object detection cam. HOT 1
- I have added other modules in the yolov8 framework, can I generate heat maps with your repository code? HOT 1
- issue with segmentation type HOT 1
- Kernel Restarting The kernel for pytorch_yolov8/code/YOLO-V8-CAM-main/YOLO v8n EigenCAM.ipynb appears to have died. It will restart automatically. HOT 2
- The letterbox processing results are incorrect.
- Which YOLOV8 layer to use to check the model's prediction
- Have to re-run the function for getting accurate output HOT 1
- CAM for YOLO-V8
- Perform Object Detection without resizing original image
- AssertionError in the results.py (ultralytics) HOT 3
- yolov8 classification not working. HOT 1
- gradcam for yolov8-seg HOT 5
- Confused width and height HOT 1
- Inquiry on Object Detection Related Error HOT 2
- Request for Example Complete Notebook - YOLO v8 CAM HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from yolo-v8-cam.