wu@wu-X555LF:~/YOLOv3_TensorFlow-master$ python video_test.py ./data/demo_data/video.mp4
2019-07-26 23:20:59.087061: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-07-26 23:20:59.211459: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-26 23:20:59.211931: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties:
name: GeForce 930M major: 5 minor: 0 memoryClockRate(GHz): 0.941
pciBusID: 0000:04:00.0
totalMemory: 1.96GiB freeMemory: 1.79GiB
2019-07-26 23:20:59.211955: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0
2019-07-26 23:21:00.990866: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1558 MB memory) -> physical GPU (device: 0, name: GeForce 930M, pci bus id: 0000:04:00.0, compute capability: 5.0)
2019-07-26 23:21:11.568484: E tensorflow/stream_executor/cuda/cuda_dnn.cc:378] Loaded runtime CuDNN library: 7500 (compatibility version 7500) but source was compiled with 7004 (compatibility version 7000). If using a binary install, upgrade your CuDNN library to match. If building from sources, make sure the library loaded at runtime matches a compatible version specified during compile configuration.
2019-07-26 23:21:11.569469: F tensorflow/core/kernels/conv_ops.cc:717] Check failed: stream->parent()->GetConvolveAlgorithms( conv_parameters.ShouldIncludeWinogradNonfusedAlgo<T>(), &algorithms)
Aborted (core dumped)
wu@wu-X555LF:~/YOLOv3_TensorFlow-master$ python video_test.py ./data/demo_data/video.mp4
2019-07-26 23:20:59.087061: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-07-26 23:20:59.211459: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-26 23:20:59.211931: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties:
name: GeForce 930M major: 5 minor: 0 memoryClockRate(GHz): 0.941
pciBusID: 0000:04:00.0
totalMemory: 1.96GiB freeMemory: 1.79GiB
2019-07-26 23:20:59.211955: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0
2019-07-26 23:21:00.990866: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1558 MB memory) -> physical GPU (device: 0, name: GeForce 930M, pci bus id: 0000:04:00.0, compute capability: 5.0)
2019-07-26 23:21:11.568484: E tensorflow/stream_executor/cuda/cuda_dnn.cc:378] Loaded runtime CuDNN library: 7500 (compatibility version 7500) but source was compiled with 7004 (compatibility version 7000). If using a binary install, upgrade your CuDNN library to match. If building from sources, make sure the library loaded at runtime matches a compatible version specified during compile configuration.
2019-07-26 23:21:11.569469: F tensorflow/core/kernels/conv_ops.cc:717] Check failed: stream->parent()->GetConvolveAlgorithms( conv_parameters.ShouldIncludeWinogradNonfusedAlgo<T>(), &algorithms)
Aborted (core dumped)
該錯誤爲 cuDNN的版本號不匹配,導致命令中止。本程序需要 cuDNN的版本號 7000版本,而本機安裝的cuDNN的版本號7500,所以需要卸載cuDNN 7500,安裝cuDNN 7000
相關命令:
查看cuda版本 : nvcc -V
查看位置 : which nvcc
查看NVIDIA動態使用情況: watch -n 1 nvidia-smi
cuda 版本 : cat /usr/local/cuda/version.txt
cudnn 版本 : cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
NVIDIA 驅動版本 : cat /proc/driver/nvidia/version
查看環境變量 : env
LD_DEBUG=all cat
卸載cuda : sudo /usr/local/cuda-8.0/bin/uninstall_cuda_8.0.pl
卸載NVIDIA Driver : sudo /usr/bin/nvidia-uninstall
wu@wu-X555LF:~/YOLOv3_TensorFlow-master$ cat /usr/local/cuda/version.txt
CUDA Version 9.0.176
wu@wu-X555LF:~/YOLOv3_TensorFlow-master$ cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2
#define CUDNN_MAJOR 7
#define CUDNN_MINOR 5
#define CUDNN_PATCHLEVEL 0
--
#define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)
#include "driver_types.h"
CuDNN版本爲 7.5.0
卸載cudnn 7.5.0:
wu@wu-X555LF:~/YOLOv3_TensorFlow-master$ sudo rm -rf /usr/local/cuda/include/cudnn.h
wu@wu-X555LF:~/YOLOv3_TensorFlow-master$ sudo rm -rf /usr/local/cuda/lib64/libcudnn*
wu@wu-X555LF:~/YOLOv3_TensorFlow-master$
執行安裝命令cudnn 7.0.5 :
sudo dpkg -i libcudnn7_7.0.5.15-1+cuda9.0_amd64.deb
sudo dpkg -i libcudnn7-dev_7.0.5.15-1+cuda9.0_amd64.deb
sudo dpkg -i libcudnn7-doc_7.0.5.15-1+cuda9.0_amd64.deb
wu@wu-X555LF:~/YOLOv3_TensorFlow-master$ cd ..
wu@wu-X555LF:~$ cd Downloads/
wu@wu-X555LF:~/Downloads$ ls
libcudnn7_7.0.5.15-1+cuda9.0_amd64.deb
libcudnn7-dev_7.0.5.15-1+cuda9.0_amd64.deb
libcudnn7-doc_7.0.5.15-1+cuda9.0_amd64.deb
wu@wu-X555LF:~/Downloads$ sudo dpkg -i libcudnn7_7.0.5.15-1+cuda9.0_amd64.deb
dpkg: warning: downgrading libcudnn7 from 7.5.0.56-1+cuda9.0 to 7.0.5.15-1+cuda9.0
(Reading database ... 237222 files and directories currently installed.)
Preparing to unpack libcudnn7_7.0.5.15-1+cuda9.0_amd64.deb ...
Unpacking libcudnn7 (7.0.5.15-1+cuda9.0) over (7.5.0.56-1+cuda9.0) ...
Setting up libcudnn7 (7.0.5.15-1+cuda9.0) ...
Processing triggers for libc-bin (2.23-0ubuntu10) ...
wu@wu-X555LF:~/Downloads$ sudo dpkg -i libcudnn7-dev_7.0.5.15-1+cuda9.0_amd64.deb
dpkg: warning: downgrading libcudnn7-dev from 7.5.0.56-1+cuda9.0 to 7.0.5.15-1+cuda9.0
(Reading database ... 237223 files and directories currently installed.)
Preparing to unpack libcudnn7-dev_7.0.5.15-1+cuda9.0_amd64.deb ...
update-alternatives: removing manually selected alternative - switching libcudnn to auto mode
Unpacking libcudnn7-dev (7.0.5.15-1+cuda9.0) over (7.5.0.56-1+cuda9.0) ...
Setting up libcudnn7-dev (7.0.5.15-1+cuda9.0) ...
update-alternatives: using /usr/include/x86_64-linux-gnu/cudnn_v7.h to provide /usr/include/cudnn.h (libcudnn) in auto mode
wu@wu-X555LF:~/Downloads$ sudo dpkg -i libcudnn7-doc_7.0.5.15-1+cuda9.0_amd64.deb
dpkg: warning: downgrading libcudnn7-doc from 7.5.0.56-1+cuda9.0 to 7.0.5.15-1+cuda9.0
(Reading database ... 237223 files and directories currently installed.)
Preparing to unpack libcudnn7-doc_7.0.5.15-1+cuda9.0_amd64.deb ...
Unpacking libcudnn7-doc (7.0.5.15-1+cuda9.0) over (7.5.0.56-1+cuda9.0) ...
Setting up libcudnn7-doc (7.0.5.15-1+cuda9.0) ...
https://developer.nvidia.com/rdp/cudnn-archive
點 cuDNN v7.0.5 Library for Linyx
下載 cudnn-9.0-linux-x64-v7.tgz
wu@wu-X555LF:~$ cd Downloads/
wu@wu-X555LF:~/Downloads$ ls
cudnn-9.0-linux-x64-v7.tgz
wu@wu-X555LF:~/Downloads$ tar -zxvf cudnn-9.0-linux-x64-v7.tgz
cuda/include/cudnn.h
cuda/NVIDIA_SLA_cuDNN_Support.txt
cuda/lib64/libcudnn.so
cuda/lib64/libcudnn.so.7
cuda/lib64/libcudnn.so.7.0.5
cuda/lib64/libcudnn_static.a
wu@wu-X555LF:~/Downloads$ sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
[sudo] password for wu:
wu@wu-X555LF:~/Downloads$ sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/ -d
wu@wu-X555LF:~/Downloads$ sudo chmod a+r /usr/local/cuda/include/cudnn.h
wu@wu-X555LF:~/Downloads$ sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
wu@wu-X555LF:~/Downloads$
如果運行cuDNN出現錯誤,確認libcudnn*.so*文件是否已經存在於 /usr/local/cuda/lib64,cudnn.h文件是否已經存在於/usr/local/cuda/include
下載完cuDNN7.5的壓縮包之後解壓,然後將相關文件拷貝到cuda的系統路徑下即可:
tar -zxvf cudnn-9.0-linux-x64-v7.tgz
sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/ -d
sudo chmod a+r /usr/local/cuda/include/cudnn.h
sudo chmod a+r /usr/local/cuda/lib64/libcudnn*
然後重新測試、成功:
cd /usr/src/cudnn_samples_v7/mnistCUDNN
sudo make clean
sudo make
./mnistCUDNN
wu@wu-X555LF:~$ cd /usr/src/cudnn_samples_v7/mnistCUDNN
wu@wu-X555LF:/usr/src/cudnn_samples_v7/mnistCUDNN$ sudo make clean
[sudo] password for wu:
rm -rf *o
rm -rf mnistCUDNN
wu@wu-X555LF:/usr/src/cudnn_samples_v7/mnistCUDNN$ sudo make
/usr/local/cuda/bin/nvcc -ccbin g++ -I/usr/local/cuda/include -IFreeImage/include -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_53,code=compute_53 -o fp16_dev.o -c fp16_dev.cu
g++ -I/usr/local/cuda/include -IFreeImage/include -o fp16_emu.o -c fp16_emu.cpp
g++ -I/usr/local/cuda/include -IFreeImage/include -o mnistCUDNN.o -c mnistCUDNN.cpp
In file included from /usr/local/cuda/include/channel_descriptor.h:62:0,
from /usr/local/cuda/include/cuda_runtime.h:90,
from /usr/include/cudnn.h:64,
from mnistCUDNN.cpp:30:
/usr/local/cuda/include/cuda_runtime_api.h:1683:101: error: use of enum ‘cudaDeviceP2PAttr’ without previous declaration
__ cudaError_t CUDARTAPI cudaDeviceGetP2PAttribute(int *value, enum cudaDeviceP
^
/usr/local/cuda/include/cuda_runtime_api.h:2930:102: error: use of enum ‘cudaFuncAttribute’ without previous declaration
_ cudaError_t CUDARTAPI cudaFuncSetAttribute(const void *func, enum cudaFuncAtt
^
In file included from /usr/local/cuda/include/channel_descriptor.h:62:0,
from /usr/local/cuda/include/cuda_runtime.h:90,
from /usr/include/cudnn.h:64,
from mnistCUDNN.cpp:30:
/usr/local/cuda/include/cuda_runtime_api.h:5770:92: error: use of enum ‘cudaMemoryAdvise’ without previous declaration
or_t CUDARTAPI cudaMemAdvise(const void *devPtr, size_t count, enum cudaMemoryA
^
/usr/local/cuda/include/cuda_runtime_api.h:5827:98: error: use of enum ‘cudaMemRangeAttribute’ without previous declaration
UDARTAPI cudaMemRangeGetAttribute(void *data, size_t dataSize, enum cudaMemRang
^
/usr/local/cuda/include/cuda_runtime_api.h:5864:102: error: use of enum ‘cudaMemRangeAttribute’ without previous declaration
TAPI cudaMemRangeGetAttributes(void **data, size_t *dataSizes, enum cudaMemRang
^
Makefile:200: recipe for target 'mnistCUDNN.o' failed
make: *** [mnistCUDNN.o] Error 1
wu@wu-X555LF:/usr/src/cudnn_samples_v7/mnistCUDNN$ sudo make clean
rm -rf *o
rm -rf mnistCUDNN
wu@wu-X555LF:/usr/src/cudnn_samples_v7/mnistCUDNN$ sudo make
/usr/local/cuda/bin/nvcc -ccbin g++ -I/usr/local/cuda/include -IFreeImage/include -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_53,code=compute_53 -o fp16_dev.o -c fp16_dev.cu
g++ -I/usr/local/cuda/include -IFreeImage/include -o fp16_emu.o -c fp16_emu.cpp
g++ -I/usr/local/cuda/include -IFreeImage/include -o mnistCUDNN.o -c mnistCUDNN.cpp
In file included from /usr/local/cuda/include/channel_descriptor.h:62:0,
from /usr/local/cuda/include/cuda_runtime.h:90,
from /usr/include/cudnn.h:64,
from mnistCUDNN.cpp:30:
/usr/local/cuda/include/cuda_runtime_api.h:1683:101: error: use of enum ‘cudaDeviceP2PAttr’ without previous declaration
__ cudaError_t CUDARTAPI cudaDeviceGetP2PAttribute(int *value, enum cudaDeviceP
^
/usr/local/cuda/include/cuda_runtime_api.h:2930:102: error: use of enum ‘cudaFuncAttribute’ without previous declaration
_ cudaError_t CUDARTAPI cudaFuncSetAttribute(const void *func, enum cudaFuncAtt
^
In file included from /usr/local/cuda/include/channel_descriptor.h:62:0,
from /usr/local/cuda/include/cuda_runtime.h:90,
from /usr/include/cudnn.h:64,
from mnistCUDNN.cpp:30:
/usr/local/cuda/include/cuda_runtime_api.h:5770:92: error: use of enum ‘cudaMemoryAdvise’ without previous declaration
or_t CUDARTAPI cudaMemAdvise(const void *devPtr, size_t count, enum cudaMemoryA
^
/usr/local/cuda/include/cuda_runtime_api.h:5827:98: error: use of enum ‘cudaMemRangeAttribute’ without previous declaration
UDARTAPI cudaMemRangeGetAttribute(void *data, size_t dataSize, enum cudaMemRang
^
/usr/local/cuda/include/cuda_runtime_api.h:5864:102: error: use of enum ‘cudaMemRangeAttribute’ without previous declaration
TAPI cudaMemRangeGetAttributes(void **data, size_t *dataSizes, enum cudaMemRang
^
Makefile:200: recipe for target 'mnistCUDNN.o' failed
make: *** [mnistCUDNN.o] Error 1
wu@wu-X555LF:/usr/src/cudnn_samples_v7/mnistCUDNN$ sudo make
[sudo] password for wu:
g++ -I/usr/local/cuda/include -IFreeImage/include -o mnistCUDNN.o -c mnistCUDNN.cpp
In file included from /usr/local/cuda/include/channel_descriptor.h:62:0,
from /usr/local/cuda/include/cuda_runtime.h:90,
from /usr/include/cudnn.h:64,
from mnistCUDNN.cpp:30:
/usr/local/cuda/include/cuda_runtime_api.h:1683:101: error: use of enum ‘cudaDeviceP2PAttr’ without previous declaration
__ cudaError_t CUDARTAPI cudaDeviceGetP2PAttribute(int *value, enum cudaDeviceP
^
/usr/local/cuda/include/cuda_runtime_api.h:2930:102: error: use of enum ‘cudaFuncAttribute’ without previous declaration
_ cudaError_t CUDARTAPI cudaFuncSetAttribute(const void *func, enum cudaFuncAtt
^
In file included from /usr/local/cuda/include/channel_descriptor.h:62:0,
from /usr/local/cuda/include/cuda_runtime.h:90,
from /usr/include/cudnn.h:64,
from mnistCUDNN.cpp:30:
/usr/local/cuda/include/cuda_runtime_api.h:5770:92: error: use of enum ‘cudaMemoryAdvise’ without previous declaration
or_t CUDARTAPI cudaMemAdvise(const void *devPtr, size_t count, enum cudaMemoryA
^
/usr/local/cuda/include/cuda_runtime_api.h:5827:98: error: use of enum ‘cudaMemRangeAttribute’ without previous declaration
UDARTAPI cudaMemRangeGetAttribute(void *data, size_t dataSize, enum cudaMemRang
^
/usr/local/cuda/include/cuda_runtime_api.h:5864:102: error: use of enum ‘cudaMemRangeAttribute’ without previous declaration
TAPI cudaMemRangeGetAttributes(void **data, size_t *dataSizes, enum cudaMemRang
^
Makefile:200: recipe for target 'mnistCUDNN.o' failed
make: *** [mnistCUDNN.o] Error 1
wu@wu-X555LF:/usr/src/cudnn_samples_v7/mnistCUDNN$ sudo make clean
[sudo] password for wu:
rm -rf *o
rm -rf mnistCUDNN
wu@wu-X555LF:/usr/src/cudnn_samples_v7/mnistCUDNN$ sudo make
/usr/local/cuda/bin/nvcc -ccbin g++ -I/usr/local/cuda/include -IFreeImage/include -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_53,code=compute_53 -o fp16_dev.o -c fp16_dev.cu
g++ -I/usr/local/cuda/include -IFreeImage/include -o fp16_emu.o -c fp16_emu.cpp
g++ -I/usr/local/cuda/include -IFreeImage/include -o mnistCUDNN.o -c mnistCUDNN.cpp
/usr/local/cuda/bin/nvcc -ccbin g++ -m64 -gencode arch=compute_30,code=sm_30 -gencode arch=compute_35,code=sm_35 -gencode arch=compute_50,code=sm_50 -gencode arch=compute_53,code=sm_53 -gencode arch=compute_53,code=compute_53 -o mnistCUDNN fp16_dev.o fp16_emu.o mnistCUDNN.o -LFreeImage/lib/linux/x86_64 -LFreeImage/lib/linux -lcudart -lcublas -lcudnn -lfreeimage -lstdc++ -lm
wu@wu-X555LF:/usr/src/cudnn_samples_v7/mnistCUDNN$ ./mnistCUDNN
cudnnGetVersion() : 7005 , CUDNN_VERSION from cudnn.h : 7005 (7.0.5)
Host compiler version : GCC 5.4.0
There are 1 CUDA capable devices on your machine :
device 0 : sms 3 Capabilities 5.0, SmClock 941.0 Mhz, MemSize (Mb) 2002, MemClock 900.0 Mhz, Ecc=0, boardGroupID=0
Using device 0
Testing single precision
Loading image data/one_28x28.pgm
Performing forward propagation ...
Testing cudnnGetConvolutionForwardAlgorithm ...
Fastest algorithm is Algo 1
Testing cudnnFindConvolutionForwardAlgorithm ...
^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.036256 time requiring 0 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 1: 0.046464 time requiring 3464 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.064576 time requiring 57600 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.584576 time requiring 2057744 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 5: 0.764416 time requiring 203008 memory
Resulting weights from Softmax:
0.0000000 0.9999399 0.0000000 0.0000000 0.0000561 0.0000000 0.0000012 0.0000017 0.0000010 0.0000000
Loading image data/three_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000000 0.0000000 0.9999288 0.0000000 0.0000711 0.0000000 0.0000000 0.0000000 0.0000000
Loading image data/five_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 0.9999820 0.0000154 0.0000000 0.0000012 0.0000006
Result of classification: 1 3 5
Test passed!
Testing half precision (math in single precision)
Loading image data/one_28x28.pgm
Performing forward propagation ...
Testing cudnnGetConvolutionForwardAlgorithm ...
Fastest algorithm is Algo 1
Testing cudnnFindConvolutionForwardAlgorithm ...
^^^^ CUDNN_STATUS_SUCCESS for Algo 0: 0.039328 time requiring 0 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 1: 0.051072 time requiring 3464 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 2: 0.061184 time requiring 28800 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 7: 0.585856 time requiring 2057744 memory
^^^^ CUDNN_STATUS_SUCCESS for Algo 5: 0.781312 time requiring 203008 memory
Resulting weights from Softmax:
0.0000001 1.0000000 0.0000001 0.0000000 0.0000563 0.0000001 0.0000012 0.0000017 0.0000010 0.0000001
Loading image data/three_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 0.0000714 0.0000000 0.0000000 0.0000000 0.0000000
Loading image data/five_28x28.pgm
Performing forward propagation ...
Resulting weights from Softmax:
0.0000000 0.0000008 0.0000000 0.0000002 0.0000000 1.0000000 0.0000154 0.0000000 0.0000012 0.0000006
Result of classification: 1 3 5
Test passed!
wu@wu-X555LF:/usr/src/cudnn_samples_v7/mnistCUDNN$
wu@wu-X555LF:~/YOLOv3_TensorFlow-master$ python video_test.py ./data/demo_data/video.mp4
2019-07-27 09:34:14.335434: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-07-27 09:34:14.439262: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-27 09:34:14.439718: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties:
name: GeForce 930M major: 5 minor: 0 memoryClockRate(GHz): 0.941
pciBusID: 0000:04:00.0
totalMemory: 1.96GiB freeMemory: 1.75GiB
2019-07-27 09:34:14.439745: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0
2019-07-27 09:34:16.096983: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1510 MB memory) -> physical GPU (device: 0, name: GeForce 930M, pci bus id: 0000:04:00.0, compute capability: 5.0)
Traceback (most recent call last):
File "video_test.py", line 68, in <module>
img, resize_ratio, dw, dh = letterbox_resize(img_ori, args.new_size[0], args.new_size[1])
File "/home/wu/YOLOv3_TensorFlow-master/utils/data_aug.py", line 278, in letterbox_resize
ori_height, ori_width = img.shape[:2]
AttributeError: 'NoneType' object has no attribute 'shape'
python video_test.py ./data/demo_data/video.mp4
執行視頻檢測,出現程序執行錯誤。因爲讀取的視頻每一幀有些視頻幀讀取發生錯誤或者本身視頻幀就是錯誤幀,在讀取的幀是NoneType類型,沒有shape屬性,所以程序執行錯誤。正常的幀讀出的屬性是numpy類,有shape類型,所以只需要跳過對NoneType類型的處理,就可以處理程序故障。
Traceback (most recent call last):
File "video_test.py", line 68, in <module>
img, resize_ratio, dw, dh = letterbox_resize(img_ori, args.new_size[0], args.new_size[1])
File "/home/wu/YOLOv3_TensorFlow-master/utils/data_aug.py", line 278, in letterbox_resize
ori_height, ori_width = img.shape[:2]
AttributeError: 'NoneType' object has no attribute 'shape'
只需輸入以下,跳過執行的程序代碼即可:
if img_ori is None:
continue
# coding: utf-8
from __future__ import division, print_function
import tensorflow as tf
import numpy as np
import argparse
import cv2
import time
from utils.misc_utils import parse_anchors, read_class_names
from utils.nms_utils import gpu_nms
from utils.plot_utils import get_color_table, plot_one_box
from utils.data_aug import letterbox_resize
from model import yolov3
parser = argparse.ArgumentParser(description="YOLO-V3 video test procedure.")
parser.add_argument("input_video", type=str,
help="The path of the input video.")
parser.add_argument("--anchor_path", type=str, default="./data/yolo_anchors.txt",
help="The path of the anchor txt file.")
parser.add_argument("--new_size", nargs='*', type=int, default=[416, 416],
help="Resize the input image with `new_size`, size format: [width, height]")
parser.add_argument("--letterbox_resize", type=lambda x: (str(x).lower() == 'true'), default=True,
help="Whether to use the letterbox resize.")
parser.add_argument("--class_name_path", type=str, default="./data/coco.names",
help="The path of the class names.")
parser.add_argument("--restore_path", type=str, default="./data/darknet_weights/yolov3.ckpt",
help="The path of the weights to restore.")
parser.add_argument("--save_video", type=lambda x: (str(x).lower() == 'true'), default=False,
help="Whether to save the video detection results.")
args = parser.parse_args()
args.anchors = parse_anchors(args.anchor_path)
args.classes = read_class_names(args.class_name_path)
args.num_class = len(args.classes)
color_table = get_color_table(args.num_class)
vid = cv2.VideoCapture(args.input_video)
video_frame_cnt = int(vid.get(7))
video_width = int(vid.get(3))
video_height = int(vid.get(4))
video_fps = int(vid.get(5))
if args.save_video:
fourcc = cv2.VideoWriter_fourcc('m', 'p', '4', 'v')
videoWriter = cv2.VideoWriter('video_result.mp4', fourcc, video_fps, (video_width, video_height))
with tf.Session() as sess:
input_data = tf.placeholder(tf.float32, [1, args.new_size[1], args.new_size[0], 3], name='input_data')
yolo_model = yolov3(args.num_class, args.anchors)
with tf.variable_scope('yolov3'):
pred_feature_maps = yolo_model.forward(input_data, False)
pred_boxes, pred_confs, pred_probs = yolo_model.predict(pred_feature_maps)
pred_scores = pred_confs * pred_probs
boxes, scores, labels = gpu_nms(pred_boxes, pred_scores, args.num_class, max_boxes=200, score_thresh=0.3, nms_thresh=0.45)
saver = tf.train.Saver()
saver.restore(sess, args.restore_path)
for i in range(video_frame_cnt):
ret, img_ori = vid.read()
if img_ori is None:
continue
if args.letterbox_resize:
img, resize_ratio, dw, dh = letterbox_resize(img_ori, args.new_size[0], args.new_size[1])
else:
height_ori, width_ori = img_ori.shape[:2]
img = cv2.resize(img_ori, tuple(args.new_size))
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = np.asarray(img, np.float32)
img = img[np.newaxis, :] / 255.
start_time = time.time()
boxes_, scores_, labels_ = sess.run([boxes, scores, labels], feed_dict={input_data: img})
end_time = time.time()
# rescale the coordinates to the original image
if args.letterbox_resize:
boxes_[:, [0, 2]] = (boxes_[:, [0, 2]] - dw) / resize_ratio
boxes_[:, [1, 3]] = (boxes_[:, [1, 3]] - dh) / resize_ratio
else:
boxes_[:, [0, 2]] *= (width_ori/float(args.new_size[0]))
boxes_[:, [1, 3]] *= (height_ori/float(args.new_size[1]))
for i in range(len(boxes_)):
x0, y0, x1, y1 = boxes_[i]
plot_one_box(img_ori, [x0, y0, x1, y1], label=args.classes[labels_[i]] + ', {:.2f}%'.format(scores_[i] * 100), color=color_table[labels_[i]])
cv2.putText(img_ori, '{:.2f}ms'.format((end_time - start_time) * 1000), (40, 40), 0,
fontScale=1, color=(0, 255, 0), thickness=2)
cv2.imshow('image', img_ori)
if args.save_video:
videoWriter.write(img_ori)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
vid.release()
if args.save_video:
videoWriter.release()
wu@wu-X555LF:~/YOLOv3_TensorFlow-master$ python video_test.py ./data/demo_data/video.mp4
2019-07-27 09:49:05.441906: I tensorflow/core/platform/cpu_feature_guard.cc:140] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 FMA
2019-07-27 09:49:05.531408: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:898] successful NUMA node read from SysFS had negative value (-1), but there must be at least one NUMA node, so returning NUMA node zero
2019-07-27 09:49:05.531856: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1212] Found device 0 with properties:
name: GeForce 930M major: 5 minor: 0 memoryClockRate(GHz): 0.941
pciBusID: 0000:04:00.0
totalMemory: 1.96GiB freeMemory: 1.73GiB
2019-07-27 09:49:05.531889: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1312] Adding visible gpu devices: 0
2019-07-27 09:49:06.158903: I tensorflow/core/common_runtime/gpu/gpu_device.cc:993] Creating TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 1493 MB memory) -> physical GPU (device: 0, name: GeForce 930M, pci bus id: 0000:04:00.0, compute capability: 5.0)
wu@wu-X555LF:~/YOLOv3_TensorFlow-master$