Giter Site home page Giter Site logo

eirikmn / ultralytics-yolov8_gradcam Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ultralytics/ultralytics

0.0 0.0 0.0 36.82 MB

Fork of Ultralytics repository. Aim to add gradcam functionality

Home Page: https://docs.ultralytics.com

License: GNU Affero General Public License v3.0

Shell 0.36% Python 93.67% Dockerfile 0.22% HTML 0.21% CSS 0.08% CMake 0.04% C++ 0.79% Jupyter Notebook 4.63%

ultralytics-yolov8_gradcam's Introduction

Grad-CAM for YOLO (version 8)

This repository contains a modified version of the 8th version of You Only Look Once (YOLO), created by Ultralytics, for which the Grad-CAMs can be computed.

This implementation is similar to that of xiaowk5516 whom implemented Grad-CAM for YOLOv5.

This project was done as part of the Norwegian Artificial Intelligence Research Consortium (NORA) 2023 summer school interpretability in Deep Learning.

Installation

To get started, clone this repository. Then, from the root folder load the modified ultralytics package as follows.

sys.path.append('ultralytics')
from ultralytics import YOLO

Make sure that no other ultralytics packages are downloaded in the environment.

If you want to use the pre-trained weights used in the examples in this repository they can be downloaded from Dropbox using this link.

Applications

First load the (pre-trained) YOLOv8 model and an image you want to apply Grad-CAM to, for example:

model = YOLO("yolov8x.pt")
catimg = Image.open("cats.jpg")

Then, you have to tell the model where the label file, here cats.txt, is located. I have not yet implemented a way to pass this information into the model call so for now you have to enter this into the source code of the package. The file you should change is:

"./ultralytics/ultralytics/yolo/engine/predictor.py" At line 382, where I have left a comment, you should place the path to the label file:

labpath = "./cats.txt"

Then, run the prediction with visualize = True:

results = model.predict(source=catimg, save=False, visualize = True, imgsz=1280)

The resulting heat maps are stored in runs/detect/ as .npy files.

A demonstration is available in yolo8-gradcam.ipynb.

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.