akarasman / yolo-heatmaps

A utility for generating heatmaps of YOLOv8 using Layerwise Relevance Propagation (LRP/CRP).
47 stars 13 forks source link

Python lib versions #5

Closed MaxwellHogan closed 2 years ago

MaxwellHogan commented 2 years ago

Heyo

I have been having trouble using this repo in a colab environment, I have not been able to run the explain script as there are incompatible modules - this is likely just due to the naming conventions being changed from yolov5 versions.

I am also not able to run the training script, there are a lot of reasons for this - the route cause I attribute to having the wrong requirements installed.

In order to help me can you let me know the verion of yolov5 you have used, and the pytorch/torchvision versions you have used,

Thanks in advance

akarasman commented 2 years ago

Hi, I run my test using the yolov5s-x versions available in the official yolov5 repo and everything was compatible last I checked. For the incompatible modules, you mentioned I would recommend that you look closely into which modules produce an error and attempt to implement your own relevance propagation methods for them. You may find thread https://github.com/akarasman/yolo-heatmaps/issues/4 useful.

You can check the requirements.txt provided in the repo for all the package versions you need and auto-install them using pip. Either that or try running the script inside the docker container. If trouble persists I suggest you just clone the ultralytics yolov5 repo and just train your model using their script.

MaxwellHogan commented 2 years ago

Thanks for your response,

There are a lot of differences between yolo-heatmap and the current implementation of yolov5, which means I can't take a model trained in yolov5 (V6.2) and use your repo. I believe a lot of these changes arose due to a compatibility problem when Pytorch 1.11 was released, I noticed your version requirement is torch 1.10.2, so I think you are using a yolov5 before these changes were made.

I haven't tried the docker yet as I have never used docker before.

In the requirements there are a lot of packages which are not available, such as: astropy==5.0.4 (there are other versions)

there are also packages which are incompatible with colab itself: ipython==8.0.1 (currently colab needs ipython v7.9.x)

there are also packages I do not believe are actual requirements such as: cryptography and textdistance

It also has absolute paths where packages should be installed to: olefile @ file:///Users/[your username]/demo/mc3/conda-bld/olefile_1629805411829/work

Hence I was hoping to find out the original requirements.txt from whichever Yolov5 you were using.

I have been able to run train.py by making some significant changes and downgrading pytorch and torchvision, however, I still cannot run explain.py still with the trained network. I am still debugging this but the current error i get is:

{path}/lrp/common.py", line 77, in prop_Detect
msg = torch.cat([msg[..., i] for i in range(msg.size(-1))], dim=1)
IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)

If you are familiar with this error it would help me right now :)

MaxwellHogan commented 2 years ago

I am in business now!

using the requirements.txt I have made available here: https://drive.google.com/file/d/1FNdWAjq2QestUoiUYtpAYDfJmeuYIzQj/view?usp=sharing

For those wishing to run this in google colab, they can do the following:

  1. replace the requirements.txt in your yolo-heatmaps dir with the one I have linked to above. (I have this on my google drive so I can store the results without losing them if colab resets)
  2. On colab run the following to install compatible pytorch versions: !pip install torch==1.10.1+cu111 torchvision==0.11.2+cu111 torchaudio==0.10.1 -f https://download.pytorch.org/whl/torch_stable.html
  3. Navigate to the yolo-heatmaps dir using %cd [path to dir] then install the requirements: !pip install -r requirements.txt

Note: this allows one to train a compatible model and then run explain.py, not use the latest yolov5, one can run the following to launch tensorboard during training:

%load_ext tensorboard
%tensorboard --logdir runs/train