Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZeroDivisionError/OpenCV Error Opening File during Demo Code #430

Closed
parth-agrawal opened this issue Sep 29, 2019 · 6 comments
Closed

ZeroDivisionError/OpenCV Error Opening File during Demo Code #430

parth-agrawal opened this issue Sep 29, 2019 · 6 comments
Labels

Comments

@parth-agrawal
Copy link

@parth-agrawal parth-agrawal commented Sep 29, 2019

Operating system and DeepLabCut version
OS: Windows 10
env: dlc-windowsCPU
DLC version: 2.0.9

The problem

I'm attempting to work through the reaching data demo set. I completed training of the dataset and it seems to have analyzed the video. However, it seems there are several issues. Highlighted:

(1) "The video was not analyzed with this scorer: DeepCut_resnet50_ReachingAug30shuffle1_300
Other scorers were found, however:"
(2) "False 0 832 0 747
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:901)"
(3) "duration = nframes/fps
ZeroDivisionError: float division by zero"

Full log:

..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\config.yaml
..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos\reachingvideo1.avi
start Analyzing the video!
Using snapshot-300 for model C:\Users\parth\Dropbox\Research\Sahin 
Research\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\dlc-models\iteration-
0\ReachingAug30-trainset95shuffle1
Starting to analyze %  ..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos\reachingvideo1.avi
Video already analyzed! ..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos\reachingvideo1DeepCut_resnet50_ReachingAug30shuffle1_300.h5
The videos are analyzed. Now your research can truly start!
You can create labeled videos with 'create_labeled_video'.
If the tracking is not satisfactory for some videos, consider expanding the training set. You can use the function 'extract_outlier_frames' to extract any outlier frames!
Starting %  ..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos ['..\\DeepLabCut\\examples\\Reaching-Mackenzie-2018-08-30\\videos\\reachingvideo1.avi']
Loading  ..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos\reachingvideo1.avi and data.
The video was not analyzed with this scorer: DeepCut_resnet50_ReachingAug30shuffle1_300
Other scorers were found, however:['reachingvideo1DeepCut_resnet50_ReachingAug30shuffle1_300.h5']
Creating labeled video for: DeepCut_resnet50_ReachingAug30shuffle1_300  instead.
False 0 832 0 747
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:901)
warning: ..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos\reachingvideo1.avi (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:902)
0
Traceback (most recent call last):
  File "vidDemo.py", line 13, in <module>
    deeplabcut.create_labeled_video(path_config_file, [videofile_path], draw_skeleton=True)
  File "C:\Users\parth\Anaconda3\envs\dlc-windowsCPU\lib\site-packages\deeplabcut\utils\make_labeled_video.py", line 404, in create_labeled_video
    CreateVideo(clip,Dataframe,cfg["pcutoff"],cfg["dotsize"],cfg["colormap"],DLCscorer,bodyparts,trailpoints,cropping,x1,x2,y1,y2,bodyparts2connect,skeleton_color,draw_skeleton,displaycropped)
  File "C:\Users\parth\Anaconda3\envs\dlc-windowsCPU\lib\site-packages\deeplabcut\utils\make_labeled_video.py", line 71, in CreateVideo
    duration = nframes/fps
ZeroDivisionError: float division by zero

I searched the forum for the ZeroDivisionError and found two relevant issues, #197 and #273 . I tried the solution for #273 and reinstalled ffmpeg in case that was the issue (conda install -c conda-forge ffmpeg). However, that did not resolve it. I'm not sure if #197's solution applies to me, since I'm using the demo data you guys provide and don't need to convert between formats. I'm also using brackets in my code.

I get 3 file outputs in /examples/../videos:
image

However, when I try to play the labeled video file I get an "invalid file type error" (0xc10100be). I've tried this with VLC which should be able to read the file - I think it might be that the file itself wasn't generated properly as a result of the errors.

My script:

import deeplabcut
import os
path_config_file = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "DeepLabCut/examples/Reaching-Mackenzie-2018-08-30/config.yaml"))
print (path_config_file)
videofile_path = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "DeepLabCut/examples/Reaching-Mackenzie-2018-08-30/videos/reachingvideo1.avi"))
print(videofile_path)
print ("start Analyzing the video!")
deeplabcut.analyze_videos(path_config_file,[videofile_path], videotype=".avi")
deeplabcut.create_labeled_video(path_config_file, [videofile_path], draw_skeleton=True)
deeplabcut.extract_outlier_frames(path_config_file, videofile_path, outlieralgorithm='uncertain',p_bound=0.2)

I made only two intentional changes to the demo code - I added the config file path to sys.path as my demo script is not in the same directory as the "examples" folder, which was the only place I could successfully import the deeplabcut module. The second was the addition of videotype=".avi" as a possible solution from #197 (which had no effect).

Would you be able to explain why issue (1) happens, and the next steps to resolve issue (2)? My guess is that issue (3) is derived from (2).

@MMathisLab

This comment has been minimized.

Copy link
Collaborator

@MMathisLab MMathisLab commented Sep 29, 2019

[1]: I'm not clear how the brackets are being read in here:

The video was not analyzed with this scorer: DeepCut_resnet50_ReachingAug30shuffle1_300
Other scorers were found, however:['reachingvideo1DeepCut_resnet50_ReachingAug30shuffle1_300.h5']

[2/3]:
for some unclear reasons to me, sometimes how the video downloads for the demo data it fails to load the meta-data correctly, and you get the zerodivisionerror; literally I can re-download it and it works... if you want to grab my original data, it is here: https://www.cell.com/neuron/fulltext/S0896-6273(17)30157-5#secsectitle0205

@parth-agrawal

This comment has been minimized.

Copy link
Author

@parth-agrawal parth-agrawal commented Sep 29, 2019

(1): Which brackets are you referring to? (This output is copied straight from the terminal).

(2/3): So I redownloaded the file from your original paper, and I'm running into the same problem.

New log:

..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\config.yaml
..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos\mmc2.mp4
start Analyzing the video!
Using snapshot-300 for model C:\Users\parth\Dropbox\Research\Sahin Research\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\dlc-models\iteration-0\ReachingAug30-trainset95shuffle1
Starting to analyze %  ..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos\mmc2.mp4
Loading  ..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos\mmc2.mp4
Duration of video [s]:  8.53 , recorded with  30.0 fps!
Overall # of frames:  256  found with (before cropping) frame dimensions:  802 720
Starting to extract posture
260it [07:47,  1.74s/it]                                                           Detected frames:  256
260it [08:01,  1.85s/it]
Saving results in ..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos...
The videos are analyzed. Now your research can truly start!
 You can create labeled videos with 'create_labeled_video'.
If the tracking is not satisfactory for some videos, consider expanding the training set. You can use the function 'extract_outlier_frames' to extract any outlier frames!
Starting %  ..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos ['..\\DeepLabCut\\examples\\Reaching-Mackenzie-2018-08-30\\videos\\mmc2.mp4']
Loading  ..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos\mmc2.mp4 and data.
The video was not analyzed with this scorer: DeepCut_resnet50_ReachingAug30shuffle1_300
Other scorers were found, however: ['mmc2DeepCut_resnet50_ReachingAug30shuffle1_300.h5']
Creating labeled video for: DeepCut_resnet50_ReachingAug30shuffle1_300  instead.
False 0 802 0 720
warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:901)
warning: ..\DeepLabCut\examples\Reaching-Mackenzie-2018-08-30\videos\mmc2.mp4 (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:902)
0
Traceback (most recent call last):
  File "vidDemo.py", line 13, in <module>
    deeplabcut.create_labeled_video(path_config_file, [videofile_path], draw_skeleton=True)
  File "C:\Users\parth\Anaconda3\envs\dlc-windowsCPU\lib\site-packages\deeplabcut\utils\make_labeled_video.py", line 404, in create_labeled_video
    CreateVideo(clip,Dataframe,cfg["pcutoff"],cfg["dotsize"],cfg["colormap"],DLCscorer,bodyparts,trailpoints,cropping,x1,x2,y1,y2,bodyparts2connect,skeleton_color,draw_skeleton,displaycropped)
  File "C:\Users\parth\Anaconda3\envs\dlc-windowsCPU\lib\site-packages\deeplabcut\utils\make_labeled_video.py", line 71, in CreateVideo
    duration = nframes/fps
ZeroDivisionError: float division by zero

New code:

import deeplabcut
import os

path_config_file = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "DeepLabCut/examples/Reaching-Mackenzie-2018-08-30/config.yaml"))
print (path_config_file)

videofile_path = os.path.normpath(os.path.join(os.path.dirname(__file__), "..", "DeepLabCut/examples/Reaching-Mackenzie-2018-08-30/videos/mmc2.mp4"))
print(videofile_path)

print ("start Analyzing the video!")
deeplabcut.analyze_videos(path_config_file,[videofile_path], videotype=".mp4")

deeplabcut.create_labeled_video(path_config_file, [videofile_path], draw_skeleton=True)

# %matplotlib notebook

# deeplabcut.plot_trajectories(path_config_file, [videofile_path],showfigures=True)


deeplabcut.extract_outlier_frames(path_config_file, videofile_path, outlieralgorithm='uncertain',p_bound=0.2)

I downloaded the video using the link in the paper, moved it to the same folder, and changed the path to point to it in line 7. Using the snapshot from yesterday, it analyzed the video, but again it ran into a problem while creating the new video - a video was output into the folder along with the the H5 and PICKLE files, but it is unreadable.

I'm also using numpy 1.17.6 instead of 1.14.5 (I was trying to use the libraries supplied by the conda environment, but was running into problems cause by the old numpy, so I manually installed the latest version), in case that's relevant information.

@MMathisLab

This comment has been minimized.

Copy link
Collaborator

@MMathisLab MMathisLab commented Sep 30, 2019

^ did you try opening the new video in VLC?

@parth-agrawal

This comment has been minimized.

Copy link
Author

@parth-agrawal parth-agrawal commented Sep 30, 2019

Yes, unfortunately.
image

@AlexEMG

This comment has been minimized.

Copy link
Owner

@AlexEMG AlexEMG commented Oct 1, 2019

Either the video is corrupt or codec not found. The main error was: "Error opening file (warning: Error opening file (/build/opencv/modules/videoio/src/cap_ffmpeg_impl.hpp:901) in openCV"

Check out e.g. https://stackoverflow.com/questions/21773850/error-opening-file-home-vaibhav-opencv-modules-highgui-src-cap-ffmpeg-impl-hpp

@AlexEMG AlexEMG added the Installation label Oct 1, 2019
@AlexEMG AlexEMG closed this Oct 4, 2019
@tbenst

This comment has been minimized.

Copy link

@tbenst tbenst commented Nov 8, 2019

@parth-agrawal I think that opencv needs to be compiled against ffmpeg. Just installing ffmpeg is not the same thing. Unfortunately, the opencv that comes via conda is not compiled against ffmpeg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.