spmallick / learnopencv

Learn OpenCV : C++ and Python Examples
https://www.learnopencv.com/
21.09k stars 11.58k forks source link

Error how can i resolve it #902

Open Tech3467 opened 5 months ago

brmarkus commented 5 months ago

Can you provide more details, please? Which sample, which file(s) are you working with and see the compilation problem? Are you following a blog from "Learn-OpenCV", if yes, which? Do you have more console output?

It looks like you need to install "http://torch.ch/".

brmarkus commented 5 months ago

So you are running this JupyterNotebook, "https://github.com/spmallick/learnopencv/blob/master/Object-Tracking-and-Reidentification-with-FairMOT/Tracking_using_FairMOT.ipynb", right?

Are you sure you have executed the second cell, and it finished successfully?

# Clone the FairMOT repository, and instell the required libraries.
!git clone https://github.com/ifzhang/FairMOT.git
!pip install torch==1.7.0 torchvision==0.8.0
!pip install cython
!pip install -r FairMOT/requirements.txt

It installs "torch" (in version v1.7.0), which contains the header "TH/TH.h".

brmarkus commented 5 months ago

Can you provide more details, please? Is there a chance that you can share what results you get from each cell?

If you open "https://github.com/spmallick/learnopencv/blob/master/Object-Tracking-and-Reidentification-with-FairMOT/Tracking_using_FairMOT.ipynb" in a separate browser window in parallel to what you are running in your Colab environment?

Which of the cells look different? The original version of this JupyterNotebook is more than 2 years old... your environment might have newer versions of some of the components; not all dependencies in this JupyterNotebook has an explicit version number...

brmarkus commented 5 months ago

Yes i am running this code no this line doesnt exectued .updated version is downloaded not this one

Can you provide more details, please?

Which line do you mean, can you split the multiple lines into separate lines and execute each line separately - and then show the results you are getting?

brmarkus commented 5 months ago

From e.g. "https://pypi.org/pypi/torch/json", a recent version seems to be "2.2.2".

$>pip index versions torch
torch (2.2.2)
Available versions: 2.2.2, 2.2.1, 2.2.0, 2.1.2, 2.1.1, 2.1.0, 2.0.1, 2.0.0, 1.13.1, 1.13.0, 1.12.1, 1.12.0, 1.11.0, 1.10.2, 1.10.1, 1.10.0, 1.9.1, 1.9.0, 1.8.1, 1.8.0, 1.7.1

As the code of this sample is old, don't try the latest version.

Try with e.g.

!pip install torch==1.7.1

ajax619 commented 4 months ago

Any solution as i am encountering same problem

brmarkus commented 4 months ago

Can you provide more details, please? The same missing header-file? Where you able to install an older version (the notebook is quite old, there were a lot of updates to the dependencies in the meantime).

brmarkus commented 4 months ago

I needed to modify a few cells:

remove version numbers:

# Clone the FairMOT repository, and instell the required libraries.
!git clone https://github.com/ifzhang/FairMOT.git
!pip install torch torchvision
!pip install cython
!pip install -r FairMOT/requirements.txt

and

using a different repo and different branch name:

# Clone and install DCNv2.
%cd /content/FairMOT
%rm -rf /content/FairMOT/DCNv2
!git clone -b pytorch_2.0.1 https://github.com/lbin/DCNv2
%cd /content/FairMOT/DCNv2
!chmod +x ./make.sh
!./make.sh

import sys
sys.path.append('/content/FairMOT/DCNv2')

and

comment-out a download (doesn't exist anylonger):

# Download all the trained FairMOT models.
!mkdir -p /content/FairMOT/models
%cd /content/FairMOT/models/
!gdown --fuzzy https://drive.google.com/file/d/1MEvsRPyoAqYSCdKaS5Ofrl7ZfKbBZ1Jb/view
!gdown --fuzzy https://drive.google.com/file/d/1HVzDTrYSSZiVqExqG9rou3zZXX1-GGQn/view
!gdown --fuzzy https://drive.google.com/file/d/1dJDGSa6-FMq33XY-cOd_nYxuilv30YDM/view
!gdown --fuzzy https://drive.google.com/file/d/1SFOhg_vos_xSYHLMTDGFVZBYjo8cr2fG/view
!gdown --fuzzy https://drive.google.com/file/d/1iqRQjsG9BawIl8SlFomMg5iwkb6nqSpi/view
#!gdown --fuzzy https://drive.google.com/file/d/1pl_-ael8wERdUREEnaIfqOV_VF2bEVRT/view
!gdown --fuzzy https://drive.google.com/file/d/1Ur3_pa9r3KRY-5qM2cdFhFJ5exghRJvh/view

How far do you get with those changes?

brmarkus commented 4 months ago

(I needed to apply some smaller modifications inside two Python files in FairMOT/src/lib/tracker/ due to numpy deprecated the type np.float; so wherever np.float was used in the sources I changed it to np.double) (the used video file consists of 1500 frames; processing all frames in Google colab can take quite a long time... processing at around 9fps...)

(when changing files used in the Jupyter notebook, then I needed to restart the Google colab runtime manually so that the modified Python files would be used)

Inside the Google Colab notebook I modified these files: from FairMOT: "src/lib/tracker/matching.py" and "src/lib/tracker/multitracker.py" (cloned https://github.com/ifzhang/FairMOT/blob/master/src/lib/tracker/matching.py and https://github.com/ifzhang/FairMOT/blob/master/src/lib/tracker/multitracker.py) => every np.float I changed to np.double

The files can be opened and modified inside the colab.

brmarkus commented 4 months ago

I'm getting this, finally:

INFO:root:Starting tracking...
2024-05-30 15:34:06 [INFO]: Starting tracking...
Fix size testing.
training chunk_sizes: [6, 6]
The output will be saved to  /content/FairMOT/src/lib/../../exp/mot/default
heads {'hm': 1, 'wh': 4, 'id': 128, 'reg': 2}
Lenth of the video: 1500 frames
Creating model...
loaded /content/FairMOT/models/fairmot_dla34.pth, epoch 30
INFO:root:Processing frame 0 (100000.00 fps)
2024-05-30 15:34:07 [INFO]: Processing frame 0 (100000.00 fps)
INFO:root:Processing frame 20 (7.88 fps)
... ...
INFO:root:Processing frame 1460 (9.00 fps)
2024-05-30 15:39:43 [INFO]: Processing frame 1460 (9.00 fps)
INFO:root:Processing frame 1480 (9.00 fps)
2024-05-30 15:39:48 [INFO]: Processing frame 1480 (9.00 fps)
INFO:root:save results to /content/FairMOT/tests/MOT16-03.txt
2024-05-30 15:39:53 [INFO]: save results to /content/FairMOT/tests/MOT16-03.txt

Every frame gets the bounding boxes drawn into it. First processed frame looks like this: image

The file "/content/FairMOT/tests/MOT16-03.txt" starts like this:

1,1,493.5321350097656,68.95755004882812,60.27572631835937,165.18722534179688,1,-1,-1,-1
1,2,727.6353759765625,639.0201416015625,101.7655029296875,239.0374755859375,1,-1,-1,-1
1,3,1843.5057373046875,541.5244750976562,76.12744140625,202.57000732421875,1,-1,-1,-1
1,4,1576.8380126953125,237.37307739257812,65.1553955078125,189.41873168945312,1,-1,-1,-1
1,5,1798.78857421875,203.35467529296875,60.578369140625,173.3404541015625,1,-1,-1,-1
1,6,1314.087158203125,480.53668212890625,81.9610595703125,221.36370849609375,1,-1,-1,-1
1,7,54.18689727783203,603.6111450195312,82.54642486572266,231.30126953125,1,-1,-1,-1
1,8,1007.3807373046875,58.848365783691406,69.66015625,189.54800415039062,1,-1,-1,-1
1,9,983.64697265625,317.5620422363281,74.702880859375,200.46499633789062,1,-1,-1,-1
1,10,521.401611328125,163.27479553222656,60.09906005859375,166.3485870361328,1,-1,-1,-1
1,11,876.5536499023438,110.1990966796875,61.20794677734376,157.6925048828125,1,-1,-1,-1
... ...
brmarkus commented 4 months ago

This Jupyter notebook (its used dependencies) need some updates to get it working again, now in the year 2024... it was created long time ago and with the dependencies outdated in the meantime...

Tech3467 commented 4 months ago
Screenshot 2024-05-31 102230 2

i am encountring this error at the last line

brmarkus commented 4 months ago

Looks like something went wrong cloning the repo "https://github.com/ifzhang/FairMOT/" in cell number 2:

# Clone the FairMOT repository, and instell the required libraries.
!git clone https://github.com/ifzhang/FairMOT.git

The method LoadVideo can be found in the repo here: "https://github.com/ifzhang/FairMOT/blob/master/src/lib/datasets/dataset/jde.py#L86"

Have you applied changes to files (or deleted, moved, renamed files&folders) and repos in your notebook environment (locally? Google-Colab?)? You might need to start with a fresh environment. If you run cells multiple times, then e.g. Git doesn't clone the repo again (error message like "there is already a non-empty-folder").

You might need to add a "delete folder" instruction to the cells which clone repos, e.g.

# Clone the FairMOT repository, and instell the required libraries.
!rm -rf FairMOT
!git clone https://github.com/ifzhang/FairMOT.git
... ...
brmarkus commented 4 months ago

You might try a more recent implementation... this notebook's dependencies need some updates...

You might try something like this:

Hemilibeatriz commented 3 months ago

(Eu preciso aplicar algumas modificações dentro de dois arquivos Python em FairMOT/src/lib/tracker/ devido ao numpy ter obsoleto o tipo np.float; então, onde quer que np.floatfosse usado nas fontes, eu o alterei para np.double) (o arquivo de vídeo usado consiste em 1500 quadros; processar todos os frames no Google colab pode levar muito tempo... processar em torno de 9fps...)

(ao alterar os arquivos usados ​​no notebook Jupyter, preciso reiniciar o tempo de execução do Google Colab manualmente para que os arquivos Python modificados fossem usados)

Dentro do notebook Google Colab modifiquei estes arquivos: do FairMOT: "src/lib/tracker/matching.py" e "src/lib/tracker/multitracker.py" (clonado https://github.com/ifzhang/FairMOT/ blob /master/src/lib/tracker/matching.py e https://github.com/ifzhang/FairMOT/blob/master/src/lib/tracker/multitracker.py ) => todo np.floateu mudei paranp.double

Os arquivos podem ser abertos e modificados dentro do colab.

These steps with the changes mentioned previously (remove the version of torch and torchvision, comment the line #!gdown --fuzzy https://drive.google.com/file/d/1pl_-ael8wERdUREEnaIfqOV_VF2bEVRT/view and use a different repository and a different branch name) made it work perfectly ... is it possible to make its output be a video file instead of several frames?

brmarkus commented 3 months ago

These steps with the changes mentioned previously (remove the version of torch and torchvision, comment the line #!gdown --fuzzy https://drive.google.com/file/d/1pl_-ael8wERdUREEnaIfqOV_VF2bEVRT/view and use a different repository and a different branch name) made it work perfectly ... is it possible to make its output be a video file instead of several frames?

Yes, sure, the output could be a video as well.

Have a look at the method def demo(opt): (cell 7?) - add opt.output_format = 'video' to the next cell (cell 8?) with the array of argument-options.

The last section (last sentence at the bottom of the notebook) mentions:

Checkout the opts.py file for more arguments.

=> there are many mopre options possible, see "https://github.com/ifzhang/FairMOT/blob/master/src/lib/opts.py".

Hemilibeatriz commented 3 months ago

Estas etapas com as alterações mencionadas anteriormente (remova a versão do torch e torchvision, comente a linha #!gdown --fuzzy https://drive.google.com/file/d/1pl_-ael8wERdUREEnaIfqOV_VF2bEVRT/view e use um repositório diferente e um nome de branch diferente) fez com que funcionasse perfeitamente ... é possível fazer com que sua saída seja um arquivo de vídeo em vez de vários quadros?

Sim, claro, a saída também pode ser um vídeo.

Dê uma olhada no método def demo(opt):(célula 7?) - adicione opt.output_format = 'video'à próxima célula (célula 8?) Com a matriz de opções de argumento.

A última seção (última frase no final do caderno) menciona:

Confira o arquivo opts.py para mais argumentos.

=> existem muitas opções de mopre possíveis, consulte " https://github.com/ifzhang/FairMOT/blob/master/src/lib/opts.py ".

Thank you very much for the clarifications! In the end it actually generated a video... thank you. I needed to load two videos for it, and concatenate the two videos to simulate a single video. Do you know if it supports two inputs? I looked at the options and it doesn't mention anything... without wanting to take advantage of your good will too, do you know if this way is the most appropriate for doing multi-camera tracking? I'm trying to get a good tracker for this function, if you also know of a model that addresses this function... it would be of great help

brmarkus commented 3 months ago

Haven't looked more closer into the underlying repos other than to get this notebook working again...

You might want to have a look into multi-camera-tracker projects, like

Use-cases can be different, very specific on e.g. re-identification, classification, a simple cosine-distance?

Tech3467 commented 3 months ago

Is this project able to reidentify the individual comes after some seconds in the frame?

On Tue, Jun 4, 2024, 6:52 PM markusbr @.***> wrote:

Haven't looked more closer into the underlying repos other than to get this notebook working again...

You might want to have a look into multi-camera-tracker projects, like

- https://docs.openvino.ai/2024/omz_demos_multi_camera_multi_target_tracking_demo_python.html

https://github.com/openvinotoolkit/open_model_zoo/tree/master/demos/multi_camera_multi_target_tracking_demo/python

Use-cases can be different, very specific on e.g. re-identification, classification, a simple cosine-distance?

— Reply to this email directly, view it on GitHub https://github.com/spmallick/learnopencv/issues/902#issuecomment-2147595279, or unsubscribe https://github.com/notifications/unsubscribe-auth/BG7NXX7PNQRNVL3KO242AF3ZFXBBTAVCNFSM6AAAAABF2J2TIOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDCNBXGU4TKMRXHE . You are receiving this because you authored the thread.Message ID: @.***>

brmarkus commented 3 months ago

From the output shown earlier:

INFO:root:Starting tracking... 2024-05-30 15:34:06 [INFO]: Starting tracking... Fix size testing. training chunk_sizes: [6, 6] The output will be saved to /content/FairMOT/src/lib/../../exp/mot/default heads {'hm': 1, 'wh': 4, 'id': 128, 'reg': 2} Lenth of the video: 1500 frames Creating model... loaded /content/FairMOT/models/fairmot_dla34.pth, epoch 30 INFO:root:Processing frame 0 (100000.00 fps) 2024-05-30 15:34:07 [INFO]: Processing frame 0 (100000.00 fps) INFO:root:Processing frame 20 (7.88 fps) ... ... INFO:root:Processing frame 1460 (9.00 fps) 2024-05-30 15:39:43 [INFO]: Processing frame 1460 (9.00 fps) INFO:root:Processing frame 1480 (9.00 fps) 2024-05-30 15:39:48 [INFO]: Processing frame 1480 (9.00 fps) INFO:root:save results to /content/FairMOT/tests/MOT16-03.txt 2024-05-30 15:39:53 [INFO]: save results to /content/FairMOT/tests/MOT16-03.txt

Between the first timestamp "2024-05-30 15:34:07" and the last "2024-05-30 15:39:48" of the processed frames (or video sequence) you can watch many persons and cyclists being tracked "all the time".

I haven't looked closer into the frames whether there are different use-cases like people disappear and re-appear, persons getting covered and re-appear, whether people suddenly get a new ID...

Hemilibeatriz commented 2 months ago

This Colab was working perfectly until last Friday... when I ran the code on Monday, I started getting an error while downloading the file... I thought it was a site instability (I tried accessing the link through the browser, but also without success), but I keep getting the same error. Any idea how to "fix" this?

image image

brmarkus commented 2 months ago

Seems like "http://dl.yf.io/dla/models/imagenet/dla34-ba72cf86.pth" (even "http://dl.yf.io/") is not available (anymore?) (at the moment?). You don't have a "local" copy of the environment (e.g. in a local cache), everything online in Colab only?

It might be required to have a more closer look into the used repos.

Maybe use the mentioned pre-trained models from the mentioned URLs (pointing to Google-Drive and Baidu) from the section "https://github.com/ifzhang/FairMOT?tab=readme-ov-file#pretrained-models-and-baseline-model"... but I haven't looked closer into the repos...

Hemilibeatriz commented 2 months ago

I even have the file, the problem is changing the code so it doesn't download and loads directly from the directory.

brmarkus commented 2 months ago

Do I see it right that it boils down to:

starting with eval_seq() in def demo(opt)

JDETracker: https://github.com/ifzhang/FairMOT/blob/master/src/lib/tracker/multitracker.py#L180C22-L180C32

calling load_model(): https://github.com/ifzhang/FairMOT/blob/master/src/lib/models/model.py#L35C5-L35C15

?

Hemilibeatriz commented 2 months ago

I will test it and get back to you if it works :) , thank you very much.