Code Monkey home page Code Monkey logo

Comments (2)

rigvedrs avatar rigvedrs commented on August 20, 2024

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.

rigvedrs avatar rigvedrs commented on August 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.