thtrieu / darkflow

Translate darknet to tensorflow. Load trained weights, retrain/fine-tune using tensorflow, export constant graph def to mobile devices
GNU General Public License v3.0
6.13k stars 2.08k forks source link

AssertionError: Cannot capture source #360

Open JayThibs opened 7 years ago

JayThibs commented 7 years ago

I'm working on Ubuntu 14.04. I can run darknet with openCV, but I'm having problems with darkflow. It works with:

./flow --imgdir sample_img/ --model cfg/yolo.cfg --load bin/yolo.weights --gpu 0.95

But if I run:

./flow --model cfg/yolo.cfg --load bin/yolo.weights --demo uberarizona.avi --gpu 0.95

or

./flow --model cfg/yolo.cfg --load bin/yolo.weights --demo preview.png --gpu 0.95

I get the following message:

Parsing ./cfg/yolo.cfg
Parsing cfg/yolo.cfg
Loading bin/yolo.weights ...
Successfully identified 203934260 bytes
Finished in 0.013549566268920898s
Model has a coco model name, loading coco labels.

Building net ...
Source | Train? | Layer description                | Output size
-------+--------+----------------------------------+---------------
       |        | input                            | (?, 608, 608, 3)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 608, 608, 32)
 Load  |  Yep!  | maxp 2x2p0_2                     | (?, 304, 304, 32)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 304, 304, 64)
 Load  |  Yep!  | maxp 2x2p0_2                     | (?, 152, 152, 64)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 152, 152, 128)
 Load  |  Yep!  | conv 1x1p0_1  +bnorm  leaky      | (?, 152, 152, 64)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 152, 152, 128)
 Load  |  Yep!  | maxp 2x2p0_2                     | (?, 76, 76, 128)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 76, 76, 256)
 Load  |  Yep!  | conv 1x1p0_1  +bnorm  leaky      | (?, 76, 76, 128)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 76, 76, 256)
 Load  |  Yep!  | maxp 2x2p0_2                     | (?, 38, 38, 256)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 38, 38, 512)
 Load  |  Yep!  | conv 1x1p0_1  +bnorm  leaky      | (?, 38, 38, 256)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 38, 38, 512)
 Load  |  Yep!  | conv 1x1p0_1  +bnorm  leaky      | (?, 38, 38, 256)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 38, 38, 512)
 Load  |  Yep!  | maxp 2x2p0_2                     | (?, 19, 19, 512)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 19, 19, 1024)
 Load  |  Yep!  | conv 1x1p0_1  +bnorm  leaky      | (?, 19, 19, 512)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 19, 19, 1024)
 Load  |  Yep!  | conv 1x1p0_1  +bnorm  leaky      | (?, 19, 19, 512)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 19, 19, 1024)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 19, 19, 1024)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 19, 19, 1024)
 Load  |  Yep!  | concat [16]                      | (?, 38, 38, 512)
 Load  |  Yep!  | conv 1x1p0_1  +bnorm  leaky      | (?, 38, 38, 64)
 Load  |  Yep!  | local flatten 2x2                | (?, 19, 19, 256)
 Load  |  Yep!  | concat [27, 24]                  | (?, 19, 19, 1280)
 Load  |  Yep!  | conv 3x3p1_1  +bnorm  leaky      | (?, 19, 19, 1024)
 Load  |  Yep!  | conv 1x1p0_1    linear           | (?, 19, 19, 425)
-------+--------+----------------------------------+---------------
GPU mode with 0.95 usage
2017-07-27 14:30:03.743234: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.1 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-27 14:30:03.743252: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use SSE4.2 instructions, but these are available on your machine and could speed up CPU computations.
2017-07-27 14:30:03.743262: W tensorflow/core/platform/cpu_feature_guard.cc:45] The TensorFlow library wasn't compiled to use AVX instructions, but these are available on your machine and could speed up CPU computations.
2017-07-27 14:30:03.867880: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:893] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2017-07-27 14:30:03.868175: I tensorflow/core/common_runtime/gpu/gpu_device.cc:940] Found device 0 with properties: 
name: GeForce GTX 1060 6GB
major: 6 minor: 1 memoryClockRate (GHz) 1.7085
pciBusID 0000:01:00.0
Total memory: 5.92GiB
Free memory: 5.83GiB
2017-07-27 14:30:03.868193: I tensorflow/core/common_runtime/gpu/gpu_device.cc:961] DMA: 0 
2017-07-27 14:30:03.868201: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0:   Y 
2017-07-27 14:30:03.868214: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1030] Creating TensorFlow device (/gpu:0) -> (device: 0, name: GeForce GTX 1060 6GB, pci bus id: 0000:01:00.0)
Finished in 6.141579627990723s

Traceback (most recent call last):
  File "./flow", line 6, in <module>
    cliHandler(sys.argv)
  File "/home/marco/jaythibs/darkflow/darkflow/cli.py", line 25, in cliHandler
    tfnet.camera()
  File "/home/marco/jaythibs/darkflow/darkflow/net/help.py", line 84, in camera
    'Cannot capture source'
AssertionError: Cannot capture source

I've downloaded ffmpeg, tried the whole path to the file, and with quotes and no quotes. If I remove the video file from the darkflow folder, it says:

Finished in 6.257935285568237s

Traceback (most recent call last):
  File "./flow", line 6, in <module>
    cliHandler(sys.argv)
  File "/home/marco/jaythibs/darkflow/darkflow/cli.py", line 25, in cliHandler
    tfnet.camera()
  File "/home/marco/jaythibs/darkflow/darkflow/net/help.py", line 76, in camera
    'file {} does not exist'.format(file)
AssertionError: file /home/marco/jaythibs/darkflow/uberarizona.avi does not exist

Anybody have any ideas on what I should try next?

jubjamie commented 7 years ago

Can you check that your video is not corrupt etc. That error comes from OpenCv not being able to open the file.

For further troubleshooting you could always try and load the video into OpenCV yourself in a test file to make sure that it works. That should give you some more error information too.

JayThibs commented 7 years ago

@jubjamie Thanks for replying. I ran the exact same video with darknet + openCV and it worked fine!

I'm currently reinstalling openCV to see if it could solve the issue.

jubjamie commented 7 years ago

Hmm that's odd. Did you get any further with this? If not I can give you some test code to run the video through.

EmmanouelP commented 7 years ago

I am assuming that u have installed opencv with the pip install command.This version of opencv is unrecommended as it doesnt provide functions like cv2.imshow(),responsible for captioning feed from webcam or a video.Try find some tutorials on installing opencv from source.

hiankun commented 6 years ago

Hi, I've also ran into the same problem. I'm using Anaconda (conda 4.3.40) in Ubuntu 16.04, and installed OpenCV 3.1.0 via conda (channel = menpo).

After reading @EmmanouelP 's comment, I used the following sample code to test my OpenCV to load the test video:

import cv2

cap = cv2.VideoCapture('test.avi') #use this to load test video
#cap = cv2.VideoCapture(0) #use this to get frames from webcam

while(cap.isOpened()):
    ret, frame = cap.read()
    cv2.imshow('frame', frame)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

It can show frames from my webcam, but do nothing when I fed it the test video.

Then I searched and found the link as follows. It might provide some workaround or solutions: OpenCV video capture from file fails on Linux #121

In short, you may reinstall OpenCV from source, or try using scikit-video as a workaround. (and I myself have not tried any of them yet...)

wangwh0204 commented 6 years ago

i solve this issue, ref this url : https://github.com/ContinuumIO/anaconda-issues/issues/121 pip uninstall opencv-python conda remove opencv conda install -c anaconda opencv

the root cause is opencv-python for linux before 3.3.1 not built with FFMpeg, the newest conda opencv3.3.1 fix this.