1. 程式人生 > >tx2_cuda9_刷機_keras環境安裝及測試環境

tx2_cuda9_刷機_keras環境安裝及測試環境

TX2cuda-9.0環境配置:
使用nvidia賬號:

1.安裝pip
apt install python3-pip
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
sudo apt install python3-pip
安裝成功, 使用pip3 list
You are using pip version 8.1.1, however version 18.1 is available.
You should consider upgrading via the ‘pip install --upgrade pip’ command.
pip3 install --upgrade pip
Traceback (most recent call last):
File “/usr/bin/pip3”, line 9, in
from pip import main
ImportError: cannot import name ‘main’
解決方法:

				將 /usr/bin/pip 檔案中:

				from pip import  main
				if __name__ == '__main__':
				    sys.exit(main())

				改為:

				from pip import __main__
				if __name__ == '__main__':
				    sys.exit(__main__._main())
  1. 安裝各種配置
    sudo pip3 install numpy
    sudo pip3 install scipy

     python3 -m pip install scipy
     #pip3 install scikit-learn
     sudo pip3 install pillow
     sudo pip3 install h5py
     sudo pip3 install matplotlib
     
     #pip3 install tensorflow
     參考: https://www.jianshu.com/p/56c85e29523d
     		https://developer.nvidia.com/embedded/downloads
     sudo pip3 install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp33 tensorflow-gpu
     sudo pip3 install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp33 tensorflow-gpu
     
     sudo pip3 install keras
     
     sudo pip3 install Flask
     sudo pip3 install Flask-RESTful
     
     scipy安裝:
     Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-lxaghvd9/scipy/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-rrpjpoly/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-lxaghvd9/scipy/
     	需要更新setuptools
     		setuptools 20.7.0 更新
     		sudo pip3 install setuptools==40.5.0
     		
     		sudo apt-get install python3-scipy
     h5py安裝:
     Command "/usr/bin/python3 -u -c "import setuptools, tokenize;__file__='/tmp/pip-install-clhvns2m/h5py/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-record-hu823puj/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-install-clhvns2m/h5py/
    
     sudo apt-get install python3-h5py
     	
     matplotlib安裝:
     Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-lva84fcd/matplotlib/
     	sudo apt-get install python3-matplotlib
    

    sudo dpkg -i libcudnn7_7.1.5.14-1+cuda9.0_arm64.deb
    sudo dpkg -i libcudnn7-dev_7.1.5.14-1+cuda9.0_arm64.deb
    [email protected]:~/restful/cudnn7$ sudo dpkg -i libcudnn7-dev_7.1.5.14-1+cuda9.0_arm64.deb
    (Reading database … 164663 files and directories currently installed.)
    Preparing to unpack libcudnn7-dev_7.1.5.14-1+cuda9.0_arm64.deb …
    update-alternatives: removing manually selected alternative - switching libcudnn to auto mode
    Unpacking libcudnn7-dev (7.1.5.14-1+cuda9.0) over (7.1.5.14-1+cuda9.0) …
    Setting up libcudnn7-dev (7.1.5.14-1+cuda9.0) …
    update-alternatives: using /usr/include/aarch64-linux-gnu/cudnn_v7.h to provide /usr/include/cudnn.h (libcudnn) in auto mode

    cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

     	sudo cp cuda/include/cudnn.h /usr/local/cuda/include/
     	sudo cp cuda/lib64/libcudnn* /usr/local/cuda/lib64/
    

    TX2手動安裝cudnn
    cd /home/nvidia/Downloads
    sudo tar xvf cudnn-9.0-linux-x64-v7.1.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.1.1
     	#cuda/lib64/libcudnn_static.a
    

    cd /home/nvidia/restful/cudnn7/cuda
    cd /usr/local/cuda/include
    cd /usr/local/cuda/lib64

    sudo cp include/cudnn.h /usr/local/cuda/include/
    sudo cp lib64/* /usr/local/cuda/lib64/
    cd /usr/local/cuda/lib64/
    ls -a(檢視libcudnn版本;很多地方需要根據檔案的版本然後操作,後面不再提示)
    sudo chmod +r libcudnn.so.7.1.1

    後面很多地方需要檢視檔名稱。學會使用 ls -a(檢視當前目錄下所有檔案)

    sudo rm -rf libcudnn.so libcudnn.so.7
    sudo ln -s libcudnn.so.7.1.1 libcudnn.so.7
    sudo ln -s libcudnn.so.7 libcudnn.so
    sudo ldconfig

    [email protected]:~/restful/cudnn7$ cat /usr/include/aarch64-linux-gnu/cudnn_v7.h | grep CUDNN_MAJOR -A 2
    #define CUDNN_MAJOR 7
    #define CUDNN_MINOR 1
    #define CUDNN_PATCHLEVEL 5

    #define CUDNN_VERSION (CUDNN_MAJOR * 1000 + CUDNN_MINOR * 100 + CUDNN_PATCHLEVEL)

     	#include "driver_types.h"
    

    [email protected]:~/restful/cudnn7$ cat /usr/local/cuda/version.txt
    CUDA Version 9.0.252

安裝過程及部分報錯及解決程式記錄:

[email protected]:~$ sudo apt-get install python3-h5py
	Reading package lists... Done
	Building dependency tree       
	Reading state information... Done
	The following packages were automatically installed and are no longer required:
	  apt-clone archdetect-deb dmeventd dmraid dpkg-repack gir1.2-timezonemap-1.0 gir1.2-xkl-1.0 kpartx kpartx-boot libappstream3
	  libdebian-installer4 libdevmapper-event1.02.1 libdmraid1.0.0.rc16 liblockfile-bin liblockfile1 liblvm2app2.2 liblvm2cmd2.02
	  libparted-fs-resize0 libreadline5 lockfile-progs lvm2 os-prober pmount python3-icu python3-pam rdate ubiquity-casper
	  ubiquity-ubuntu-artwork
	Use 'sudo apt autoremove' to remove them.
	The following additional packages will be installed:
	  libaec0 libhdf5-10 libsz2
	The following NEW packages will be installed:
	  libaec0 libhdf5-10 libsz2 python3-h5py
	0 upgraded, 4 newly installed, 0 to remove and 640 not upgraded.
	Need to get 1,210 kB of archives.
	After this operation, 5,452 kB of additional disk space will be used.
	Do you want to continue? [Y/n] Y
	Get:1 http://ports.ubuntu.com/ubuntu-ports xenial/universe arm64 libaec0 arm64 0.3.2-1 [16.5 kB]
	Get:2 http://ports.ubuntu.com/ubuntu-ports xenial/universe arm64 libsz2 arm64 0.3.2-1 [4,916 B]
	Get:3 http://ports.ubuntu.com/ubuntu-ports xenial-updates/universe arm64 libhdf5-10 arm64 1.8.16+docs-4ubuntu1.1 [776 kB]
	Get:4 http://ports.ubuntu.com/ubuntu-ports xenial/universe arm64 python3-h5py arm64 2.6.0-1 [412 kB]                            
	Fetched 1,210 kB in 36s (32.9 kB/s)                                                                                             
	Selecting previously unselected package libaec0:arm64.
	(Reading database ... 163561 files and directories currently installed.)
	Preparing to unpack .../libaec0_0.3.2-1_arm64.deb ...
	Unpacking libaec0:arm64 (0.3.2-1) ...
	Selecting previously unselected package libsz2:arm64.
	Preparing to unpack .../libsz2_0.3.2-1_arm64.deb ...
	Unpacking libsz2:arm64 (0.3.2-1) ...
	Selecting previously unselected package libhdf5-10:arm64.
	Preparing to unpack .../libhdf5-10_1.8.16+docs-4ubuntu1.1_arm64.deb ...
	Unpacking libhdf5-10:arm64 (1.8.16+docs-4ubuntu1.1) ...
	Selecting previously unselected package python3-h5py.
	Preparing to unpack .../python3-h5py_2.6.0-1_arm64.deb ...
	Unpacking python3-h5py (2.6.0-1) ...
	Processing triggers for libc-bin (2.23-0ubuntu3) ...
	Setting up libaec0:arm64 (0.3.2-1) ...
	Setting up libsz2:arm64 (0.3.2-1) ...
	Setting up libhdf5-10:arm64 (1.8.16+docs-4ubuntu1.1) ...
	Setting up python3-h5py (2.6.0-1) ...
	Processing triggers for libc-bin (2.23-0ubuntu3) ...
[email protected]:~$ pip3 list
	Package                       Version
	----------------------------- -------
	apt-clone                     0.2.1  
	apturl                        0.5.2  
	beautifulsoup4                4.4.1  
	blinker                       1.3    
	Brlapi                        0.6.4  
	chardet                       2.3.0  
	checkbox-support              0.22   
	command-not-found             0.3    
	cryptography                  1.2.3  
	decorator                     4.0.6  
	defer                         1.0.6  
	feedparser                    5.1.3  
	guacamole                     0.9.2  
	h5py                          2.6.0  
	html5lib                      0.999  
	httplib2                      0.9.1  
	idna                          2.0    
	Jinja2                        2.8    
	language-selector             0.1    
	louis                         2.6.4  
	lxml                          3.5.0  
	Mako                          1.0.3  
	MarkupSafe                    0.23   
	numpy                         1.15.4 
	oauthlib                      1.0.3  
	onboard                       1.2.0  
	padme                         1.1.1  
	PAM                           0.4.2  
	pexpect                       4.0.1  
	Pillow                        3.1.2  
	pip                           18.1   
	plainbox                      0.25   
	ptyprocess                    0.5    
	pyasn1                        0.1.9  
	pycups                        1.9.73 
	pycurl                        7.43.0 
	pygobject                     3.20.0 
	PyICU                         1.9.2  
	PyJWT                         1.3.0  
	pyparsing                     2.0.3  
	python-apt                    1.1.0b1
	python-debian                 0.1.27 
	python-systemd                231    
	pyxdg                         0.25   
	reportlab                     3.3.0  
	requests                      2.9.1  
	scipy                         0.17.0 
	sessioninstaller              0.0.0  
	setuptools                    40.5.0 
	six                           1.10.0 
	ssh-import-id                 5.5    
	system-service                0.3    
	ubuntu-drivers-common         0.0.0  
	unattended-upgrades           0.1    
	unity-scope-calculator        0.1    
	unity-scope-chromiumbookmarks 0.1    
	unity-scope-colourlovers      0.1    
	unity-scope-devhelp           0.1    
	unity-scope-firefoxbookmarks  0.1    
	unity-scope-gdrive            0.7    
	unity-scope-manpages          0.1    
	unity-scope-openclipart       0.1    
	unity-scope-texdoc            0.1    
	unity-scope-tomboy            0.1    
	unity-scope-virtualbox        0.1    
	unity-scope-yelp              0.1    
	unity-scope-zotero            0.1    
	urllib3                       1.13.1 
	wheel                         0.29.0 
	xdiagnose                     3.8.4  
	xkit                          0.0.0  
	XlsxWriter                    0.7.3  
[email protected]:~$ sudo pip3 install --extra-index-url https://developer.download.nvidia.com/compute/redist/jp33 tensorflow-gpu
	The directory '/home/nvidia/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
	The directory '/home/nvidia/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
	Looking in indexes: https://pypi.org/simple, https://developer.download.nvidia.com/compute/redist/jp33
	Collecting tensorflow-gpu
	  Downloading https://developer.download.nvidia.com/compute/redist/jp33/tensorflow-gpu/tensorflow_gpu-1.9.0+nv18.8-cp35-cp35m-linux_aarch64.whl (91.1MB)
		100% |████████████████████████████████| 91.2MB 734kB/s 
	Collecting termcolor>=1.1.0 (from tensorflow-gpu)
	  Downloading https://files.pythonhosted.org/packages/8a/48/a76be51647d0eb9f10e2a4511bf3ffb8cc1e6b14e9e4fab46173aa79f981/termcolor-1.1.0.tar.gz
	Requirement already satisfied: six>=1.10.0 in /usr/lib/python3/dist-packages (from tensorflow-gpu) (1.10.0)
	Collecting tensorboard<1.10.0,>=1.9.0 (from tensorflow-gpu)
	  Downloading https://files.pythonhosted.org/packages/9e/1f/3da43860db614e294a034e42d4be5c8f7f0d2c75dc1c428c541116d8cdab/tensorboard-1.9.0-py3-none-any.whl (3.3MB)
		100% |████████████████████████████████| 3.3MB 10kB/s 
	Collecting setuptools<=39.1.0 (from tensorflow-gpu)
	  Downloading https://files.pythonhosted.org/packages/8c/10/79282747f9169f21c053c562a0baa21815a8c7879be97abd930dbcf862e8/setuptools-39.1.0-py2.py3-none-any.whl (566kB)
		100% |████████████████████████████████| 573kB 228kB/s 
	Collecting grpcio>=1.8.6 (from tensorflow-gpu)
	  Downloading https://files.pythonhosted.org/packages/be/84/9afa550ae7bfc65a7150f66ecdbf267617a2d584d9f845b4ef7d026a24ad/grpcio-1.16.0.tar.gz (14.5MB)
		100% |████████████████████████████████| 14.5MB 2.4MB/s 
	Collecting gast>=0.2.0 (from tensorflow-gpu)
	  Downloading https://files.pythonhosted.org/packages/5c/78/ff794fcae2ce8aa6323e789d1f8b3b7765f601e7702726f430e814822b96/gast-0.2.0.tar.gz
	Collecting astor>=0.6.0 (from tensorflow-gpu)
	  Downloading https://files.pythonhosted.org/packages/35/6b/11530768cac581a12952a2aad00e1526b89d242d0b9f59534ef6e6a1752f/astor-0.7.1-py2.py3-none-any.whl
	Requirement already satisfied: wheel>=0.26 in /usr/lib/python3/dist-packages (from tensorflow-gpu) (0.29.0)
	Collecting protobuf>=3.4.0 (from tensorflow-gpu)
	  Downloading https://files.pythonhosted.org/packages/77/78/a7f1ce761e2c738e209857175cd4f90a8562d1bde32868a8cd5290d58926/protobuf-3.6.1-py2.py3-none-any.whl (390kB)
		100% |████████████████████████████████| 399kB 9.3MB/s 
	Collecting absl-py>=0.1.6 (from tensorflow-gpu)
	  Downloading https://files.pythonhosted.org/packages/0c/63/f505d2d4c21db849cf80bad517f0065a30be6b006b0a5637f1b95584a305/absl-py-0.6.1.tar.gz (94kB)
		100% |████████████████████████████████| 102kB 4.5MB/s 
	Requirement already satisfied: numpy>=1.11.0 in /usr/local/lib/python3.5/dist-packages (from tensorflow-gpu) (1.15.4)
	Collecting markdown>=2.6.8 (from tensorboard<1.10.0,>=1.9.0->tensorflow-gpu)
	  Downloading https://files.pythonhosted.org/packages/7a/6b/5600647404ba15545ec37d2f7f58844d690baf2f81f3a60b862e48f29287/Markdown-3.0.1-py2.py3-none-any.whl (89kB)
		100% |████████████████████████████████| 92kB 4.9MB/s 
	Collecting werkzeug>=0.11.10 (from tensorboard<1.10.0,>=1.9.0->tensorflow-gpu)
	  Downloading https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
		100% |████████████████████████████████| 327kB 604kB/s 
	Installing collected packages: termcolor, markdown, werkzeug, setuptools, protobuf, tensorboard, grpcio, gast, astor, absl-py, tensorflow-gpu
	  Running setup.py install for termcolor ... done
	  Found existing installation: setuptools 40.5.0
		Uninstalling setuptools-40.5.0:
		  Successfully uninstalled setuptools-40.5.0
	  Running setup.py install for grpcio ... done
	  Running setup.py install for gast ... done
	  Running setup.py install for absl-py ... done
	Successfully installed absl-py-0.6.1 astor-0.7.1 gast-0.2.0 grpcio-1.16.0 markdown-3.0.1 protobuf-3.6.1 setuptools-39.1.0 tensorboard-1.9.0 tensorflow-gpu-1.9.0+nv18.8 termcolor-1.1.0 werkzeug-0.14.1
[email protected]:~$ sudo pip3 install keras
	The directory '/home/nvidia/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
	The directory '/home/nvidia/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
	Collecting keras
	  Downloading https://files.pythonhosted.org/packages/5e/10/aa32dad071ce52b5502266b5c659451cfd6ffcbf14e6c8c4f16c0ff5aaab/Keras-2.2.4-py2.py3-none-any.whl (312kB)
		100% |████████████████████████████████| 317kB 2.2MB/s 
	Collecting keras-preprocessing>=1.0.5 (from keras)
	  Downloading https://files.pythonhosted.org/packages/fc/94/74e0fa783d3fc07e41715973435dd051ca89c550881b3454233c39c73e69/Keras_Preprocessing-1.0.5-py2.py3-none-any.whl
	Requirement already satisfied: numpy>=1.9.1 in /usr/local/lib/python3.5/dist-packages (from keras) (1.15.4)
	Collecting keras-applications>=1.0.6 (from keras)
	  Downloading https://files.pythonhosted.org/packages/3f/c4/2ff40221029f7098d58f8d7fb99b97e8100f3293f9856f0fb5834bef100b/Keras_Applications-1.0.6-py2.py3-none-any.whl (44kB)
		100% |████████████████████████████████| 51kB 3.1MB/s 
	Requirement already satisfied: h5py in /usr/lib/python3/dist-packages (from keras) (2.6.0)
	Requirement already satisfied: scipy>=0.14 in /usr/lib/python3/dist-packages (from keras) (0.17.0)
	Requirement already satisfied: six>=1.9.0 in /usr/lib/python3/dist-packages (from keras) (1.10.0)
	Collecting pyyaml (from keras)
	  Downloading https://files.pythonhosted.org/packages/9e/a3/1d13970c3f36777c583f136c136f804d70f500168edc1edea6daa7200769/PyYAML-3.13.tar.gz (270kB)
		100% |████████████████████████████████| 276kB 639kB/s 
	Installing collected packages: keras-preprocessing, keras-applications, pyyaml, keras
	  Running setup.py install for pyyaml ... done
	Successfully installed keras-2.2.4 keras-applications-1.0.6 keras-preprocessing-1.0.5 pyyaml-3.13
[email protected]:~$ sudo pip3 install Flask
	The directory '/home/nvidia/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
	The directory '/home/nvidia/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
	Collecting Flask
	  Downloading https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl (91kB)
		100% |████████████████████████████████| 92kB 58kB/s 
	Requirement already satisfied: Werkzeug>=0.14 in /usr/local/lib/python3.5/dist-packages (from Flask) (0.14.1)
	Collecting Jinja2>=2.10 (from Flask)
	  Downloading https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl (126kB)
		100% |████████████████████████████████| 133kB 39kB/s 
	Collecting itsdangerous>=0.24 (from Flask)
	  Downloading https://files.pythonhosted.org/packages/76/ae/44b03b253d6fade317f32c24d100b3b35c2239807046a4c953c7b89fa49e/itsdangerous-1.1.0-py2.py3-none-any.whl
	Collecting click>=5.1 (from Flask)
	  Downloading https://files.pythonhosted.org/packages/fa/37/45185cb5abbc30d7257104c434fe0b07e5a195a6847506c074527aa599ec/Click-7.0-py2.py3-none-any.whl (81kB)
		100% |████████████████████████████████| 81kB 64kB/s 
	Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python3/dist-packages (from Jinja2>=2.10->Flask) (0.23)
	Installing collected packages: Jinja2, itsdangerous, click, Flask
	  Found existing installation: Jinja2 2.8
		Uninstalling Jinja2-2.8:
		  Successfully uninstalled Jinja2-2.8
	Successfully installed Flask-1.0.2 Jinja2-2.10 click-7.0 itsdangerous-1.1.0
[email protected]:~$ sudo pip3 install Flask-RESTful
	The directory '/home/nvidia/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
	The directory '/home/nvidia/.cache/pip' or its parent directory is not owned by the current user and caching wheels has been disabled. check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
	Collecting Flask-RESTful
	  Downloading https://files.pythonhosted.org/packages/47/08/89cf8594735392cd71752f7cf159fa63765eac3e11b0da4324cdfeaea137/Flask_RESTful-0.3.6-py2.py3-none-any.whl
	Collecting aniso8601>=0.82 (from Flask-RESTful)
	  Downloading https://files.pythonhosted.org/packages/69/9b/f2ae61c0c90181b62e15ca09d283d2aab42c7c2c3bbd7c548dd0cfd8bf3e/aniso8601-4.0.1-py2.py3-none-any.whl
	Requirement already satisfied: six>=1.3.0 in /usr/lib/python3/dist-packages (from Flask-RESTful) (1.10.0)
	Requirement already satisfied: Flask>=0.8 in /usr/local/lib/python3.5/dist-packages (from Flask-RESTful) (1.0.2)
	Collecting pytz (from Flask-RESTful)
	  Downloading https://files.pythonhosted.org/packages/f8/0e/2365ddc010afb3d79147f1dd544e5ee24bf4ece58ab99b16fbb465ce6dc0/pytz-2018.7-py2.py3-none-any.whl (506kB)
		100% |████████████████████████████████| 512kB 14kB/s 
	Requirement already satisfied: Jinja2>=2.10 in /usr/local/lib/python3.5/dist-packages (from Flask>=0.8->Flask-RESTful) (2.10)
	Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.5/dist-packages (from Flask>=0.8->Flask-RESTful) (1.1.0)
	Requirement already satisfied: Werkzeug>=0.14 in /usr/local/lib/python3.5/dist-packages (from Flask>=0.8->Flask-RESTful) (0.14.1)
	Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.5/dist-packages (from Flask>=0.8->Flask-RESTful) (7.0)
	Requirement already satisfied: MarkupSafe>=0.23 in /usr/lib/python3/dist-packages (from Jinja2>=2.10->Flask>=0.8->Flask-RESTful) (0.23)
	Installing collected packages: aniso8601, pytz, Flask-RESTful
	Successfully installed Flask-RESTful-0.3.6 aniso8601-4.0.1 pytz-2018.7
[email protected]:~$ python3
	Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
	[GCC 5.4.0 20160609] on linux
	Type "help", "copyright", "credits" or "license" for more information.
	>>> import numpy
	>>> import scipy
	>>> import PIL
	>>> import h5py
	>>> import flask
	>>> import tensorflow
	>>> import keras
	Using TensorFlow backend.
	>>> exit()	
pip3 list
	[email protected]:~$ pip3 list
	Package                       Version     
	----------------------------- ------------
	absl-py                       0.6.1       
	aniso8601                     4.0.1       
	apt-clone                     0.2.1       
	apturl                        0.5.2       
	astor                         0.7.1       
	beautifulsoup4                4.4.1       
	blinker                       1.3         
	Brlapi                        0.6.4       
	chardet                       2.3.0       
	checkbox-support              0.22        
	Click                         7.0         
	command-not-found             0.3         
	cryptography                  1.2.3       
	decorator                     4.0.6       
	defer                         1.0.6       
	feedparser                    5.1.3       
	Flask                         1.0.2       
	Flask-RESTful                 0.3.6       
	gast                          0.2.0       
	grpcio                        1.16.0      
	guacamole                     0.9.2       
	h5py                          2.6.0       
	html5lib                      0.999       
	httplib2                      0.9.1       
	idna                          2.0         
	itsdangerous                  1.1.0       
	Jinja2                        2.10        
	Keras                         2.2.4       
	Keras-Applications            1.0.6       
	Keras-Preprocessing           1.0.5       
	language-selector             0.1         
	louis                         2.6.4       
	lxml                          3.5.0       
	Mako                          1.0.3       
	Markdown                      3.0.1       
	MarkupSafe                    0.23        
	numpy                         1.15.4      
	oauthlib                      1.0.3       
	onboard                       1.2.0       
	padme                         1.1.1       
	PAM                           0.4.2       
	pexpect                       4.0.1       
	Pillow                        3.1.2       
	pip                           18.1        
	plainbox                      0.25        
	protobuf                      3.6.1       
	ptyprocess                    0.5         
	pyasn1                        0.1.9       
	pycups                        1.9.73      
	pycurl                        7.43.0      
	pygobject                     3.20.0      
	PyICU                         1.9.2       
	PyJWT                         1.3.0       
	pyparsing                     2.0.3       
	python-apt                    1.1.0b1     
	python-debian                 0.1.27      
	python-systemd                231         
	pytz                          2018.7      
	pyxdg                         0.25        
	PyYAML                        3.13        
	reportlab                     3.3.0       
	requests                      2.9.1       
	scipy                         0.17.0      
	sessioninstaller              0.0.0       
	setuptools                    39.1.0      
	six                           1.10.0      
	ssh-import-id                 5.5         
	system-service                0.3         
	tensorboard                   1.9.0       
	tensorflow-gpu                1.9.0+nv18.8
	termcolor                     1.1.0       
	ubuntu-drivers-common         0.0.0       
	unattended-upgrades           0.1         
	unity-scope-calculator        0.1         
	unity-scope-chromiumbookmarks 0.1         
	unity-scope-colourlovers      0.1         
	unity-scope-devhelp           0.1         
	unity-scope-firefoxbookmarks  0.1         
	unity-scope-gdrive            0.7         
	unity-scope-manpages          0.1         
	unity-scope-openclipart       0.1         
	unity-scope-texdoc            0.1         
	unity-scope-tomboy            0.1         
	unity-scope-virtualbox        0.1         
	unity-scope-yelp              0.1         
	unity-scope-zotero            0.1         
	urllib3                       1.13.1      
	Werkzeug                      0.14.1      
	wheel                         0.29.0      
	xdiagnose                     3.8.4       
	xkit                          0.0.0       
	XlsxWriter                    0.7.3       
	[email protected]:~$ 

程式報錯:tensorflow.python.framework.errors_impl.InternalError: GPU sync failed
經過分析,這個錯誤有可能是cudnn沒安裝對,或者是沒裝,或者是TF框架自己的bug

2018年11月8日 程式碼測試:
1.test_nogpu_noflask.py 416*416 ok
[email protected]:~/restful$ python3 test_nogpu_noflask.py
Using TensorFlow backend.
2018-11-08 12:03:49.057255: E tensorflow/stream_executor/cuda/cuda_driver.cc:397] failed call to cuInit: CUDA_ERROR_NO_DEVICE
2018-11-08 12:03:49.057335: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:145] kernel driver does not appear to be running on this host (tegra-ubuntu): /proc/driver/nvidia/version does not exist
model_data/yolov3_20181031_best.h5 model, anchors, and classes loaded.
Found 1 boxes for img
arrow2fen 1.00 (314, 80) (671, 712)
Cost time:7.367642339000668
-1
Found 1 boxes for img
arrow2I 1.00 (486, 428) (563, 504)
Cost time:3.478246026001216
1
Found 1 boxes for img
ball2I 0.92 (71, 285) (282, 467)
Cost time:3.489461442999527
1
Found 1 boxes for img
light2he 0.99 (120, 101) (301, 367)
Cost time:3.496631759999218
1
Found 6 boxes for img
jiediV2fen 0.99 (304, 761) (330, 788)
jiediV2fen 1.00 (511, 193) (565, 259)
jiediV2fen 1.00 (233, 159) (286, 231)
square2he 0.88 (281, 560) (333, 606)
square2he 0.97 (234, 748) (272, 783)
square2he 0.99 (362, 168) (435, 235)
Cost time:3.467399684999691
-1
true
false

2. test_gpu_noflask.py
	[email protected]:~/restful$ python3 test_gpu_noflask.py
	Using TensorFlow backend.
	2018-11-08 12:10:04.219790: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:864] ARM64 does not support NUMA - returning NUMA node zero
	2018-11-08 12:10:04.219932: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1392] Found device 0 with properties: 
	name: NVIDIA Tegra X2 major: 6 minor: 2 memoryClockRate(GHz): 1.3005
	pciBusID: 0000:00:00.0
	totalMemory: 7.67GiB freeMemory: 4.59GiB
	2018-11-08 12:10:04.219986: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1471] Adding visible gpu devices: 0
	2018-11-08 12:10:04.944193: I tensorflow/core/common_runtime/gpu/gpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix:
	2018-11-08 12:10:04.944268: I tensorflow/core/common_runtime/gpu/gpu_device.cc:958]      0 
	2018-11-08 12:10:04.944295: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0:   N 
	2018-11-08 12:10:04.944445: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1084] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4202 MB memory) -> physical GPU (device: 0, name: NVIDIA Tegra X2, pci bus id: 0000:00:00.0, compute capability: 6.2)
	2018-11-08 12:10:05.175807: E tensorflow/stream_executor/cuda/cuda_driver.cc:1108] could not synchronize on CUDA context: CUDA_ERROR_UNKNOWN :: *** Begin stack trace ***
		stream_executor::cuda::CUDADriver::SynchronizeContext(stream_executor::cuda::CudaContext*)
		stream_executor::StreamExecutor::SynchronizeAllActivity()
		tensorflow::GPUUtil::SyncAll(tensorflow::Device*)
	*** End stack trace ***

	Traceback (most recent call last):
		  File "/home/nvidia/restful/YOLO.py", line 103, in generate
			self.yolo_model = load_model(model_path, compile=False)
		  File "/usr/local/lib/python3.5/dist-packages/keras/engine/saving.py", line 419, in load_model
			model = _deserialize_model(f, custom_objects, compile)
		  File "/usr/local/lib/python3.5/dist-packages/keras/engine/saving.py", line 221, in _deserialize_model
			model_config = f['model_config']
		  File "/usr/local/lib/python3.5/dist-packages/keras/utils/io_utils.py", line 302, in __getitem__
			raise ValueError('Cannot create group in read only mode.')
		ValueError: Cannot create group in read only mode.

		During handling of the above exception, another exception occurred:

		Traceback (most recent call last):
		  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1322, in _do_call
			return fn(*args)
		  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1307, in _run_fn
			options, feed_dict, fetch_list, target_list, run_metadata)
		  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun
			run_metadata)
		tensorflow.python.framework.errors_impl.InternalError: GPU sync failed

		During handling of the above exception, another exception occurred:

		Traceback (most recent call last):
		  File "test_gpu_noflask.py", line 29, in <module>
			anchors_path=anchors_path,Use_Soft_NMS=False)
		  File "/home/nvidia/restful/YOLO.py", line 56, in __init__
			self.boxes, self.scores, self.classes = self.generate()
		  File "/home/nvidia/restful/YOLO.py", line 106, in generate
			if is_tiny_version else yolo_body(Input(shape=(None,None,3)), num_anchors//3, num_classes)
		  File "/home/nvidia/restful/yolo3/model.py", line 74, in yolo_body
			darknet = Model(inputs, darknet_body(inputs))
		  File "/home/nvidia/restful/yolo3/model.py", line 49, in darknet_body
			x = DarknetConv2D_BN_Leaky(32, (3,3))(x)
		  File "/home/nvidia/restful/yolo3/utils.py", line 17, in <lambda>
			return reduce(lambda f, g: lambda *a, **kw: g(f(*a, **kw)), funcs)
		  File "/home/nvidia/restful/yolo3/utils.py", line 17, in <lambda>
			return reduce(lambda f, g: lambda *a, **kw: g(f(*a, **kw)), funcs)
		  File "/usr/local/lib/python3.5/dist-packages/keras/engine/base_layer.py", line 457, in __call__
			output = self.call(inputs, **kwargs)
		  File "/usr/local/lib/python3.5/dist-packages/keras/layers/normalization.py", line 185, in call
			epsilon=self.epsilon)
		  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 1858, in normalize_batch_in_training
			if not _has_nchw_support() and list(reduction_axes) == [0, 2, 3]:
		  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 292, in _has_nchw_support
			gpus_available = len(_get_available_gpus()) > 0
		  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 278, in _get_available_gpus
			_LOCAL_DEVICES = get_session().list_devices()
		  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 199, in get_session
			[tf.is_variable_initialized(v) for v in candidate_vars])
		  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 900, in run
			run_metadata_ptr)
		  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1135, in _run
			feed_dict_tensor, options, run_metadata)
		  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1316, in _do_run
			run_metadata)
		  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1335, in _do_call
			raise type(e)(node_def, op, message)
	tensorflow.python.framework.errors_impl.InternalError: GPU sync failed

2018年11月9日 程式碼測試:

加上控制視訊記憶體的程式碼: 單純測試tf,gpu可以用,cpu可以用
1. [email protected]:~/restful$ sudo python3 test_tf_gpuoff.py

	[sudo] password for nvidia: 
	2018-11-09 01:48:28.274129: E tensorflow/stream_executor/cuda/cuda_driver.cc:397] failed call to cuInit: CUDA_ERROR_NO_DEVICE
	2018-11-09 01:48:28.274207: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:145] kernel driver does not appear to be running on this host (tegra-ubuntu): /proc/driver/nvidia/version does not exist
	7
2. [email protected]:~/restful$ sudo python3 test_tf_gpuon.py

	2018-11-09 01:49:21.879343: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:864] ARM64 does not support NUMA - returning NUMA node zero
	2018-11-09 01:49:21.879559: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1392] Found device 0 with properties: 
	name: NVIDIA Tegra X2 major: 6 minor: 2 memoryClockRate(GHz): 1.3005
	pciBusID: 0000:00:00.0
	totalMemory: 7.67GiB freeMemory: 6.06GiB
	2018-11-09 01:49:21.879637: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1471] Adding visible gpu devices: 0
	2018-11-09 01:49:23.226974: I tensorflow/core/common_runtime/gpu/gpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix:
	2018-11-09 01:49:23.227051: I tensorflow/core/common_runtime/gpu/gpu_device.cc:958]      0 
	2018-11-09 01:49:23.227078: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0:   N 
	2018-11-09 01:49:23.227220: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1084] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 5554 MB memory) -> physical GPU (device: 0, name: NVIDIA Tegra X2, pci bus id: 0000:00:00.0, compute capability: 6.2)
	7
	
3. YOLO.py開頭 加上控制視訊記憶體程式碼,單純測試yolo模型程式碼, no gpu no flask
global config 
config = tf.ConfigProto()
config.gpu_options.allow_growth = True
[email protected]:~/restful$ sudo python3 test_nogpu_noflask.py
	[sudo] password for nvidia: 
	Using TensorFlow backend.
	2018-11-09 02:29:06.727529: E tensorflow/stream_executor/cuda/cuda_driver.cc:397] failed call to cuInit: CUDA_ERROR_NO_DEVICE
	2018-11-09 02:29:06.727608: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:145] kernel driver does not appear to be running on this host (tegra-ubuntu): /proc/driver/nvidia/version does not exist
	model_data/yolov3_20181031_best.h5 model, anchors, and classes loaded.
	Found 1 boxes for img
	arrow2fen 1.00 (314, 80) (671, 712)
	Cost time:7.397829957999875
	-1
	Found 1 boxes for img
	arrow2I 1.00 (486, 428) (563, 504)
	Cost time:3.500870160999966
	1
	Found 1 boxes for img
	ball2I 0.92 (71, 285) (282, 467)
	Cost time:3.4744570509997175
	1
	Found 1 boxes for img
	light2he 0.99 (120, 101) (301, 367)
	Cost time:3.46852697300028
	1
	Found 6 boxes for img
	jiediV2fen 0.99 (304, 761) (330, 788)
	jiediV2fen 1.00 (511, 193) (565, 259)
	jiediV2fen 1.00 (233, 159) (286, 231)
	square2he 0.88 (281, 560) (333, 606)
	square2he 0.97 (234, 748) (272, 783)
	square2he 0.99 (362, 168) (435, 235)
	Cost time:3.4980721929996434
	-1
	true
	false
4. flask框架可以跑
[email protected]:~/restful$ sudo python3 flask_only.py
	 * Serving Flask app "flask_only" (lazy loading)
	 * Environment: production
	   WARNING: Do not use the development server in a production environment.
	   Use a production WSGI server instead.
	 * Debug mode: on
	 * Running on http://0.0.0.0:8383/ (Press CTRL+C to quit)
	 * Restarting with stat
	 * Debugger is active!
	 * Debugger PIN: 174-283-214
	{'SwitchName': '903開關', 'ImageName': '/opt/py/restful/image_test/2.jpg', 'SwitchStatus': '-1'}
	192.168.1.84 - - [09/Nov/2018 03:04:11] "POST /todos HTTP/1.1" 201 -
	{'SwitchName': '903開關', 'ImageName': '/opt/py/restful/image_test/2.jpg', 'SwitchStatus': '-1'}
	192.168.1.84 - - [09/Nov/2018 03:04:15] "POST /todos HTTP/1.1" 201 -
	{'SwitchName': '903開關', 'ImageName': '/opt/py/restful/image_test/5.jpg', 'SwitchStatus': '-1'}
	192.168.1.84 - - [09/Nov/2018 03:04:19] "POST /todos HTTP/1.1" 201 -


5. YOLO.py開頭 加上控制視訊記憶體程式碼,單純測試yolo模型程式碼, have gpu no flask
test_havegpu_noflask288.py
	[email protected]:~/restful$ sudo python3 test_havegpu_noflask288.py
	Using TensorFlow backend.
	2018-11-09 02:58:01.860612: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:864] ARM64 does not support NUMA - returning NUMA node zero
	2018-11-09 02:58:01.860744: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1392] Found device 0 with properties: 
	name: NVIDIA Tegra X2 major: 6 minor: 2 memoryClockRate(GHz): 1.3005
	pciBusID: 0000:00:00.0
	totalMemory: 7.67GiB freeMemory: 4.79GiB
	2018-11-09 02:58:01.860827: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1471] Adding visible gpu devices: 0
	2018-11-09 02:58:02.576956: I tensorflow/core/common_runtime/gpu/gpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix:
	2018-11-09 02:58:02.577031: I tensorflow/core/common_runtime/gpu/gpu_device.cc:958]      0 
	2018-11-09 02:58:02.577056: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0:   N 
	2018-11-09 02:58:02.577194: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1084] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4407 MB memory) -> physical GPU (device: 0, name: NVIDIA Tegra X2, pci bus id: 0000:00:00.0, compute capability: 6.2)
	
	2018-11-09 02:58:02.815539: E tensorflow/stream_executor/cuda/cuda_driver.cc:1108] could not synchronize on CUDA context: CUDA_ERROR_UNKNOWN :: *** Begin stack trace ***
		stream_executor::cuda::CUDADriver::SynchronizeContext(stream_executor::cuda::CudaContext*)
		stream_executor::StreamExecutor::SynchronizeAllActivity()
		tensorflow::GPUUtil::SyncAll(tensorflow::Device*)
	*** End stack trace ***

	Traceback (most recent call last):
	  File "/home/nvidia/restful/YOLO.py", line 113, in generate
		self.yolo_model = load_model(model_path, compile=False)
	  File "/usr/local/lib/python3.5/dist-packages/keras/engine/saving.py", line 419, in load_model
		model = _deserialize_model(f, custom_objects, compile)
	  File "/usr/local/lib/python3.5/dist-packages/keras/engine/saving.py", line 221, in _deserialize_model
		model_config = f['model_config']
	  File "/usr/local/lib/python3.5/dist-packages/keras/utils/io_utils.py", line 302, in __getitem__
		raise ValueError('Cannot create group in read only mode.')
	ValueError: Cannot create group in read only mode.

	During handling of the above exception, another exception occurred:

	Traceback (most recent call last):
	  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1322, in _do_call
		return fn(*args)
	  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1307, in _run_fn
		options, feed_dict, fetch_list, target_list, run_metadata)
	  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun
		run_metadata)
	tensorflow.python.framework.errors_impl.InternalError: GPU sync failed

	During handling of the above exception, another exception occurred:

	Traceback (most recent call last):
	  File "test_havegpu_noflask288.py", line 19, in <module>
		anchors_path=anchors_path,Use_Soft_NMS=False)
	  File "/home/nvidia/restful/YOLO.py", line 66, in __init__
		self.boxes, self.scores, self.classes = self.generate()
	  File "/home/nvidia/restful/YOLO.py", line 116, in generate
		if is_tiny_version else yolo_body(Input(shape=(None,None,3)), num_anchors//3, num_classes)
	  File "/home/nvidia/restful/yolo3/model.py", line 74, in yolo_body
		darknet = Model(inputs, darknet_body(inputs))
	  File "/home/nvidia/restful/yolo3/model.py", line 49, in darknet_body
		x = DarknetConv2D_BN_Leaky(32, (3,3))(x)
	  File "/home/nvidia/restful/yolo3/utils.py", line 17, in <lambda>
		return reduce(lambda f, g: lambda *a, **kw: g(f(*a, **kw)), funcs)
	  File "/home/nvidia/restful/yolo3/utils.py", line 17, in <lambda>
		return reduce(lambda f, g: lambda *a, **kw: g(f(*a, **kw)), funcs)
	  File "/usr/local/lib/python3.5/dist-packages/keras/engine/base_layer.py", line 457, in __call__
		output = self.call(inputs, **kwargs)
	  File "/usr/local/lib/python3.5/dist-packages/keras/layers/normalization.py", line 185, in call
		epsilon=self.epsilon)
	  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 1858, in normalize_batch_in_training
		if not _has_nchw_support() and list(reduction_axes) == [0, 2, 3]:
	  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 292, in _has_nchw_support
		gpus_available = len(_get_available_gpus()) > 0
	  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 278, in _get_available_gpus
		_LOCAL_DEVICES = get_session().list_devices()
	  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 199, in get_session
		[tf.is_variable_initialized(v) for v in candidate_vars])
	  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 900, in run
		run_metadata_ptr)
	  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1135, in _run
		feed_dict_tensor, options, run_metadata)
	  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1316, in _do_run
		run_metadata)
	  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1335, in _do_call
		raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InternalError: GPU sync failed
could not synchronize on CUDA context: CUDA_ERROR_UNKNOWN 

2018年11月9日 程式碼重新測試, 離線安裝TF
cd /home/nvidia/restful
sudo python3 test_havegpu_haveflask416.py

[email protected]:~/restful$ sudo python3 flask_only.py
* Serving Flask app “flask_only” (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:8383/ (Press CTRL+C to quit)
* Restarting with stat
* Debugger is active!
* Debugger PIN: 174-283-214
^[email protected]:~/restful$
[email protected]:~/restful$
[email protected]:~/restful$ sudo python3 test_tf_gpuoff.py
2018-11-09 04:09:18.048548: E tensorflow/stream_executor/cuda/cuda_driver.cc:397] failed call to cuInit: CUDA_ERROR_NO_DEVICE
2018-11-09 04:09:18.048620: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:145] kernel driver does not appear to be running on this host (tegra-ubuntu): /proc/driver/nvidia/version does not exist
7
[email protected]:~/restful$ sudo python3 test_tf_gpuon.py
2018-11-09 04:09:34.915217: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:864] ARM64 does not support NUMA - returning NUMA node zero
2018-11-09 04:09:34.915351: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1392] Found device 0 with properties:
name: NVIDIA Tegra X2 major: 6 minor: 2 memoryClockRate(GHz): 1.3005
pciBusID: 0000:00:00.0
totalMemory: 7.67GiB freeMemory: 4.30GiB
2018-11-09 04:09:34.915400: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1471] Adding visible gpu devices: 0
2018-11-09 04:09:35.628112: I tensorflow/core/common_runtime/gpu/gpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-11-09 04:09:35.628180: I tensorflow/core/common_runtime/gpu/gpu_device.cc:958] 0
2018-11-09 04:09:35.628205: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0: N
2018-11-09 04:09:35.628339: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1084] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3904 MB memory) -> physical GPU (device: 0, name: NVIDIA Tegra X2, pci bus id: 0000:00:00.0, compute capability: 6.2)
7
[email protected]:~/restful$ sudo python3 test_nogpu_noflask.py
Using TensorFlow backend.
2018-11-09 04:09:57.547152: E tensorflow/stream_executor/cuda/cuda_driver.cc:397] failed call to cuInit: CUDA_ERROR_NO_DEVICE
2018-11-09 04:09:57.547228: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:145] kernel driver does not appear to be running on this host (tegra-ubuntu): /proc/driver/nvidia/version does not exist
model_data/yolov3_20181031_best.h5 model, anchors, and classes loaded.
Found 1 boxes for img
arrow2fen 1.00 (314, 80) (671, 712)
Cost time:7.3449035230000845
-1
Found 1 boxes for img
arrow2I 1.00 (486, 428) (563, 504)
Cost time:3.4960819299999457
1
Found 1 boxes for img
ball2I 0.92 (71, 285) (282, 467)
Cost time:3.446750769999653
1
Found 1 boxes for img
light2he 0.99 (120, 101) (301, 367)
Cost time:3.4814000480000686
1
Found 6 boxes for img
jiediV2fen 0.99 (304, 761) (330, 788)
jiediV2fen 1.00 (511, 193) (565, 259)
jiediV2fen 1.00 (233, 159) (286, 231)
square2he 0.88 (281, 560) (333, 606)
square2he 0.97 (234, 748) (272, 783)
square2he 0.99 (362, 168) (435, 235)
Cost time:3.483333424000193
-1
true
false
[email protected]:~/restful$ sudo python3 test_gpu_noflask.py
Using TensorFlow backend.
2018-11-09 04:13:41.930703: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:864] ARM64 does not support NUMA - returning NUMA node zero
2018-11-09 04:13:41.930835: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1392] Found device 0 with properties:
name: NVIDIA Tegra X2 major: 6 minor: 2 memoryClockRate(GHz): 1.3005
pciBusID: 0000:00:00.0
totalMemory: 7.67GiB freeMemory: 4.07GiB
2018-11-09 04:13:41.930892: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1471] Adding visible gpu devices: 0
2018-11-09 04:13:42.627598: I tensorflow/core/common_runtime/gpu/gpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-11-09 04:13:42.627667: I tensorflow/core/common_runtime/gpu/gpu_device.cc:958] 0
2018-11-09 04:13:42.627693: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0: N
2018-11-09 04:13:42.627832: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1084] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 3661 MB memory) -> physical GPU (device: 0, name: NVIDIA Tegra X2, pci bus id: 0000:00:00.0, compute capability: 6.2)
model_data/yolov3_20181031_best.h5 model, anchors, and classes loaded.
Found 1 boxes for img
arrow2I 1.00 (486, 428) (563, 504)
Cost time:9.81604150899966
1
Found 1 boxes for img
ball2I 0.92 (71, 285) (282, 467)
Cost time:0.5447981950001122
1
Found 1 boxes for img
light2he 0.99 (120, 101) (301, 367)
Cost time:0.5261266229999819
1
Found 6 boxes for img
jiediV2fen 0.99 (304, 761) (330, 788)
jiediV2fen 1.00 (511, 193) (565, 259)
jiediV2fen 1.00 (233, 159) (286, 231)
square2he 0.88 (281, 560) (333, 606)
square2he 0.97 (234, 748) (272, 783)
square2he 0.99 (362, 168) (435, 235)
Cost time:0.5771966570000586
-1
true
false
[email protected]:~/restful$
[email protected]:~/restful$ sudo python3 test_nogpu_haveflask.py
[sudo] password for nvidia:
Using TensorFlow backend.
* Serving Flask app “test_nogpu_haveflask” (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:8383/ (Press CTRL+C to quit)
* Restarting with stat
Using TensorFlow backend.
2018-11-09 04:44:23.036144: E tensorflow/stream_executor/cuda/cuda_driver.cc:397] failed call to cuInit: CUDA_ERROR_NO_DEVICE
2018-11-09 04:44:23.036223: I tensorflow/stream_executor/cuda/cuda_diagnostics.cc:145] kernel driver does not appear to be running on this host (tegra-ubuntu): /proc/driver/nvidia/version does not exist
model_data/yolov3_20181031_best.h5 model, anchors, and classes loaded.
Found 1 boxes for img
arrow2fen 1.00 (314, 80) (671, 712)
Cost time:7.384201387999383
-1
* Debugger is active!
* Debugger PIN: 174-283-214
{‘SwitchStatus’: ‘-1’, ‘ImageName’: ‘/opt/py/restful/image_test/5.jpg’, ‘SwitchName’: ‘903開關’}
/opt/py/restful/image_test/5.jpg
no image
192.168.1.84 - - [09/Nov/2018 04:46:22] “POST /todos HTTP/1.1” 201 -
{‘SwitchStatus’: ‘-1’, ‘ImageName’: ‘/opt/py/restful/image_test/1.jpg’, ‘SwitchName’: ‘903開關’}
/opt/py/restful/image_test/1.jpg
no image
192.168.1.84 - - [09/Nov/2018 04:46:27] “POST /todos HTTP/1.1” 201 -
{‘SwitchStatus’: ‘-1’, ‘ImageName’: ‘/home/nvidia/restful/image_test/1.jpg’, ‘SwitchName’: ‘903開關’}
/home/nvidia/restful/image_test/1.jpg
Found 1 boxes for img
arrow2fen 1.00 (314, 80) (671, 712)
Cost time:3.5199496660006844
image_test\1.png
-1
192.168.1.84 - - [09/Nov/2018 04:46:56] “POST /todos HTTP/1.1” 201 -
{‘SwitchStatus’: ‘-1’, ‘ImageName’: ‘/home/nvidia/restful/image_test/5.jpg’, ‘SwitchName’: ‘903開關’}
/home/nvidia/restful/image_test/5.jpg
Found 6 boxes for img
jiediV2fen 0.99 (304, 761) (330, 788)
jiediV2fen 1.00 (511, 193) (565, 259)
jiediV2fen 1.00 (233, 159) (286, 231)
square2he 0.88 (281, 560) (333, 606)
square2he 0.97 (234, 748) (272, 783)
square2he 0.99 (362, 168) (435, 235)
Cost time:3.549997598000118
image_test\5.png
-1
192.168.1.84 - - [09/Nov/2018 04:47:05] “POST /todos HTTP/1.1” 201 -
[email protected]:~/restful$ sudo python3 test_havegpu_haveflask.py
Using TensorFlow backend.
* Serving Flask app “test_havegpu_haveflask” (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:8383/ (Press CTRL+C to quit)
* Restarting with stat
Using TensorFlow backend.
2018-11-09 04:53:08.902617: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:864] ARM64 does not support NUMA - returning NUMA node zero
2018-11-09 04:53:08.902759: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1392] Found device 0 with properties:
name: NVIDIA Tegra X2 major: 6 minor: 2 memoryClockRate(GHz): 1.3005
pciBusID: 0000:00:00.0
totalMemory: 7.67GiB freeMemory: 4.43GiB
2018-11-09 04:53:08.902813: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1471] Adding visible gpu devices: 0
2018-11-09 04:53:09.613204: I tensorflow/core/common_runtime/gpu/gpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-11-09 04:53:09.613273: I tensorflow/core/common_runtime/gpu/gpu_device.cc:958] 0
2018-11-09 04:53:09.613301: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0: N
2018-11-09 04:53:09.613474: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1084] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4035 MB memory) -> physical GPU (device: 0, name: NVIDIA Tegra X2, pci bus id: 0000:00:00.0, compute capability: 6.2)
model_data/yolov3_20181031_best.h5 model, anchors, and classes loaded.
Found 1 boxes for img
arrow2fen 1.00 (314, 80) (671, 712)
Cost time:9.477419259999806
-1
* Debugger is active!
* Debugger PIN: 174-283-214
{‘SwitchName’: ‘903開關’, ‘SwitchStatus’: ‘-1’, ‘ImageName’: ‘/home/nvidia/restful/image_test/5.jpg’}
/home/nvidia/restful/image_test/5.jpg
Found 6 boxes for img
jiediV2fen 0.99 (304, 761) (330, 788)
jiediV2fen 1.00 (511, 193) (565, 259)
jiediV2fen 1.00 (233, 159) (286, 231)
square2he 0.88 (281, 560) (333, 606)
square2he 0.97 (234, 748) (272, 783)
square2he 0.99 (362, 168) (435, 235)
Cost time:0.6662494860001971
image_test\5.png
-1
192.168.1.84 - - [09/Nov/2018 04:54:36] “POST /todos HTTP/1.1” 201 -
{‘SwitchName’: ‘903開關’, ‘SwitchStatus’: ‘-1’, ‘ImageName’: ‘/home/nvidia/restful/image_test/2.jpg’}
/home/nvidia/restful/image_test/2.jpg
Found 1 boxes for img
arrow2I 1.00 (486, 428) (563, 504)
Cost time:0.7566004760001306
image_test\2.png
1
192.168.1.84 - - [09/Nov/2018 04:54:44] “POST /todos HTTP/1.1” 201 -
{‘SwitchName’: ‘903開關’, ‘SwitchStatus’: ‘-1’, ‘ImageName’: ‘/home/nvidia/restful/image_test/1.jpg’}
/home/nvidia/restful/image_test/1.jpg
Found 1 boxes for img
arrow2fen 1.00 (314, 80) (671, 712)
Cost time:0.6276727509994089
image_test\1.png
-1
192.168.1.84 - - [09/Nov/2018 04:55:04] “POST /todos HTTP/1.1” 201 -

再次測試
[email protected]:~/restful$ sudo python3 test_havegpu_haveflask.py
Using TensorFlow backend.
* Serving Flask app “test_havegpu_haveflask” (lazy loading)
* Environment: production
WARNING: Do not use the development server in a production environment.
Use a production WSGI server instead.
* Debug mode: on
* Running on http://0.0.0.0:8383/ (Press CTRL+C to quit)
* Restarting with stat
Using TensorFlow backend.
2018-11-09 05:28:49.778722: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:864] ARM64 does not support NUMA - returning NUMA node zero
2018-11-09 05:28:49.778863: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1392] Found device 0 with properties:
name: NVIDIA Tegra X2 major: 6 minor: 2 memoryClockRate(GHz): 1.3005
pciBusID: 0000:00:00.0
totalMemory: 7.67GiB freeMemory: 4.68GiB
2018-11-09 05:28:49.778921: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1471] Adding visible gpu devices: 0
2018-11-09 05:28:50.489701: I tensorflow/core/common_runtime/gpu/gpu_device.cc:952] Device interconnect StreamExecutor with strength 1 edge matrix:
2018-11-09 05:28:50.489767: I tensorflow/core/common_runtime/gpu/gpu_device.cc:958] 0
2018-11-09 05:28:50.489792: I tensorflow/core/common_runtime/gpu/gpu_device.cc:971] 0: N
2018-11-09 05:28:50.489948: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1084] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4291 MB memory) -> physical GPU (device: 0, name: NVIDIA Tegra X2, pci bus id: 0000:00:00.0, compute capability: 6.2)
2018-11-09 05:28:50.724268: E tensorflow/stream_executor/cuda/cuda_driver.cc:1108] could not synchronize on CUDA context: CUDA_ERROR_UNKNOWN :: *** Begin stack trace ***
stream_executor::cuda::CUDADriver::SynchronizeContext(stream_executor::cuda::CudaContext*)
stream_executor::StreamExecutor::SynchronizeAllActivity()
tensorflow::GPUUtil::SyncAll(tensorflow::Device*)
*** End stack trace ***

Traceback (most recent call last):
  File "/home/nvidia/restful/YOLO.py", line 114, in generate
	self.yolo_model = load_model(model_path, compile=False)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/saving.py", line 419, in load_model
	model = _deserialize_model(f, custom_objects, compile)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/saving.py", line 221, in _deserialize_model
	model_config = f['model_config']
  File "/usr/local/lib/python3.5/dist-packages/keras/utils/io_utils.py", line 302, in __getitem__
	raise ValueError('Cannot create group in read only mode.')
ValueError: Cannot create group in read only mode.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1322, in _do_call
	return fn(*args)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1307, in _run_fn
	options, feed_dict, fetch_list, target_list, run_metadata)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1409, in _call_tf_sessionrun
	run_metadata)
tensorflow.python.framework.errors_impl.InternalError: GPU sync failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "test_havegpu_haveflask.py", line 75, in <module>
	anchors_path=anchors_path,Use_Soft_NMS=False)
  File "/home/nvidia/restful/YOLO.py", line 67, in __init__
	self.boxes, self.scores, self.classes = self.generate()
  File "/home/nvidia/restful/YOLO.py", line 117, in generate
	if is_tiny_version else yolo_body(Input(shape=(None,None,3)), num_anchors//3, num_classes)
  File "/home/nvidia/restful/yolo3/model.py", line 74, in yolo_body
	darknet = Model(inputs, darknet_body(inputs))
  File "/home/nvidia/restful/yolo3/model.py", line 49, in darknet_body
	x = DarknetConv2D_BN_Leaky(32, (3,3))(x)
  File "/home/nvidia/restful/yolo3/utils.py", line 17, in <lambda>
	return reduce(lambda f, g: lambda *a, **kw: g(f(*a, **kw)), funcs)
  File "/home/nvidia/restful/yolo3/utils.py", line 17, in <lambda>
	return reduce(lambda f, g: lambda *a, **kw: g(f(*a, **kw)), funcs)
  File "/usr/local/lib/python3.5/dist-packages/keras/engine/base_layer.py", line 457, in __call__
	output = self.call(inputs, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/keras/layers/normalization.py", line 185, in call
	epsilon=self.epsilon)
  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 1858, in normalize_batch_in_training
	if not _has_nchw_support() and list(reduction_axes) == [0, 2, 3]:
  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 292, in _has_nchw_support
	gpus_available = len(_get_available_gpus()) > 0
  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 278, in _get_available_gpus
	_LOCAL_DEVICES = get_session().list_devices()
  File "/usr/local/lib/python3.5/dist-packages/keras/backend/tensorflow_backend.py", line 199, in get_session
	[tf.is_variable_initialized(v) for v in candidate_vars])
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 900, in run
	run_metadata_ptr)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1135, in _run
	feed_dict_tensor, options, run_metadata)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1316, in _do_run
	run_metadata)
  File "/usr/local/lib/python3.5/dist-packages/tensorflow/python/client/session.py", line 1335, in _do_call
	raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_i