Conclusions about Deep Learning with Python

 Conclusions about Deep Learning with Python html

 

Last night, I start to learn the python for deep learning research. It really confused me at the beginning. So, here is some conclusions about the hard beginning progress. If you have some more excellent solutions, please let us know (you can leave a message in the bottom of this poster). Thank you. node

 

0. Install the specific version of Tensorflow (for example, tf 1.2.0):  python

$: pip install tensorflow==1.2.0linux

 

1. The first problem I met is how to load images using python and change the image format to some specific requirements ? git

 here is what I searched from online: python 讀取並顯示圖片的兩種方法 . I think its a goog tutorial about this problem. github

 1 1、matplotlib  2 1. 顯示圖片  3 複製代碼  4 import matplotlib.pyplot as plt # plt 用於顯示圖片
 5 import matplotlib.image as mpimg # mpimg 用於讀取圖片
 6 import numpy as np  7 
 8 lena = mpimg.imread('lena.png') # 讀取和代碼處於同一目錄下的 lena.png
 9 # 此時 lena 就已是一個 np.array 了,能夠對它進行任意處理
 10 lena.shape #(512, 512, 3)
 11 
 12 plt.imshow(lena) # 顯示圖片
 13 plt.axis('off') # 不顯示座標軸
 14 plt.show()  15 複製代碼  16 2. 顯示某個通道  17 複製代碼  18 # 顯示圖片的第一個通道
 19 lena_1 = lena[:,:,0]  20 plt.imshow('lena_1')  21 plt.show()  22 # 此時會發現顯示的是熱量圖,不是咱們預想的灰度圖,能夠添加 cmap 參數,有以下幾種添加方法:
 23 plt.imshow('lena_1', cmap='Greys_r')  24 plt.show()  25 
 26 img = plt.imshow('lena_1')  27 img.set_cmap('gray') # 'hot' 是熱量圖
 28 plt.show()  29 
 30 複製代碼  31 3. 將 RGB 轉爲灰度圖  32 matplotlib 中沒有合適的函數能夠將 RGB 圖轉換爲灰度圖,能夠根據公式自定義一個:  33 
 34 複製代碼  35 def rgb2gray(rgb):  36     return np.dot(rgb[...,:3], [0.299, 0.587, 0.114])  37 
 38 gray = rgb2gray(lena)  39 # 也能夠用 plt.imshow(gray, cmap = plt.get_cmap('gray'))
 40 plt.imshow(gray, cmap='Greys_r')  41 plt.axis('off')  42 plt.show()  43 複製代碼  44 4. 對圖像進行放縮  45 這裏要用到 scipy  46 
 47 複製代碼  48 from scipy import misc  49 lena_new_sz = misc.imresize(lena, 0.5) # 第二個參數若是是整數,則爲百分比,若是是tuple,則爲輸出圖像的尺寸
 50 plt.imshow(lena_new_sz)  51 plt.axis('off')  52 plt.show()  53 複製代碼  54 5. 保存圖像  55 5.1 保存 matplotlib 畫出的圖像  56 
 57 該方法適用於保存任何 matplotlib 畫出的圖像,至關於一個 screencapture。  58 
 59 plt.imshow(lena_new_sz)  60 plt.axis('off')  61 plt.savefig('lena_new_sz.png')  62 5.2 將 array 保存爲圖像  63 
 64 from scipy import misc  65 misc.imsave('lena_new_sz.png', lena_new_sz)  66 5.3 直接保存 array  67 
 68 讀取以後仍是能夠按照前面顯示數組的方法對圖像進行顯示,這種方法徹底不會對圖像質量形成損失  69 
 70 np.save('lena_new_sz', lena_new_sz) # 會在保存的名字後面自動加上.npy
 71 img = np.load('lena_new_sz.npy') # 讀取前面保存的數組
 72  
 73 
 74  
 75 
 76 2、PIL  77 1. 顯示圖片  78 from PIL import Image  79 im = Image.open('lena.png')  80 im.show()  81 2. 將 PIL Image 圖片轉換爲 numpy 數組  82 im_array = np.array(im)  83 # 也能夠用 np.asarray(im) 區別是 np.array() 是深拷貝,np.asarray() 是淺拷貝
 84 3. 保存 PIL 圖片  85 直接調用 Image 類的 save 方法  86 
 87 from PIL import Image  88 I = Image.open('lena.png')  89 I.save('new_lena.png')  90 4. 將 numpy 數組轉換爲 PIL 圖片  91 這裏採用 matplotlib.image 讀入圖片數組,注意這裏讀入的數組是 float32 型的,範圍是 0-1,而 PIL.Image 數據是 uinit8 型的,範圍是0-255,因此要進行轉換:  92 
 93 import matplotlib.image as mpimg  94 from PIL import Image  95 lena = mpimg.imread('lena.png') # 這裏讀入的數據是 float32 型的,範圍是0-1
 96 im = Image.fromarray(np.uinit8(lena*255))  97 im.show()  98  5. RGB 轉換爲灰度圖  99 from PIL import Image 100 I = Image.open('lena.png') 101 I.show() 102 L = I.convert('L') 103 L.show()
View Code

 

2. TypeError: mat is not a numpy array, neither a scalarweb

Today I use cv2 to load one image, but it shown me the error like this : 編程

==>> Loading Image Names
==>> Epoch ID is 0
======>> deal with video ID 0 ==>> Basketball
Traceback (most recent call last):
File "./xxx.py", line 160, in <module>
cv2.imshow("candidateRegion", image)
TypeError: mat is not a numpy array, neither a scalar json

-------------------------------------------------------------------------------------------------------------------bootstrap

So, how to solve this issue ? 

I found it all depends on which methods you use to load the image. 

for example, you may use cv2, PIL, matplotlib or something else. 

But, you can only use cv2 for some specific operation later. Here is an example: 

 

 

Then, this problem can be avoided. Just try to transform the type of the loaded image, i.e. im_array = np.array(im) or directly

utilize the cv2 approach to load the image. 

Finally, I want to say that: I love cv2. 

 

3. When you copy a part of python code from other files, you may find this error:

wangxiao@AHU:~/Documents/files$ python ./run_train_Visual_Tracking_v2.py
File "./run_train_Visual_Tracking_v2.py", line 149
history_vector = np.zeros([20])
^
IndentationError: unindent does not match any outer indentation level 

 

But you sure that: this code do not have any problem ! but it still shown you this fucking error ! 

This is caused by the alignment issue in python: the mixture usage of "space" and "Tab" ! 

Just select those code and align it using Tab, first move to most left to reduce the "space" and move it to the right location.  

It will be OK, trust me. 

 

4. Compute IOU of two BBox using python: 

 

5. Shut down the warning of python code. 

==>> add these two lines at the beginning of your code. 

import warnings
warnings.filterwarnings("ignore")

 

6. 打開 txt 文檔,而且讀取對應行的 txt 內容記錄:

  path = '/path to your txt files /xxx.txt'  

  txtfiles = [ ]

  for line in open(path): 

    txtfiles.append(line) 

  ## 此時,咱們已經將 txt 文件中的內容轉移到了 list txtfiles 當中。咱們能夠經過 txtfiles[i] 的方式來訪問某一行的記錄。

  for example:  print(txtfiles[0])  ## 返回第一行的文件記錄。

 

7. Python __future__ 模塊 :爲何有時候須要 from __future__ import division?

參考博文:http://blog.csdn.net/langb2014/article/details/53305246

有以下的解釋:

 

  1. 避免和現有分析import工具混淆,並獲得你指望的模塊
  2. 確保2.1以前的版本導入__future__產生運行時異常,由於2.1以前沒有這個模塊
  3. 文檔化不兼容的改變,一般這些改變會在新版中強制執行。這類文檔以可執行的形式組織,經過導入__future__進行可編程式的檢查 。

 

8. How to understand the defaultdict in python ?

  As discussed in http://www.jb51.net/article/115578.htm 

  we can see a example like following:  

  

 

9. the use of iter() in python ?

  ==>>  Python 中的迭代器用起來很是靈巧,不只能夠迭代序列,也能夠迭表明現出序列行爲的對象,例如字典的鍵、一個文件的行,等等。迭代器就是有一個next()方法的對象,而不是經過索引來計數。當使用一個循環機制須要下一個項時,調用迭代器的next()方法,迭代完後引起一個StopIteration異常。 可是迭代器只能向後移動、不能回到開始、再次迭代只能建立另外一個新的迭代對象。

  

 

10.  we often see "@property" in python files , what does it used for ? 

  here are some reference: 

    1. http://python.jobbole.com/80955/

    2. https://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb493182103fac9270762a000/001386820062641f3bcc60a4b164f8d91df476445697b9e000 

    3. http://www.jb51.net/article/65052.htm 

    4. http://python.jobbole.com/81967/?utm_source=blog.jobbole.com&utm_medium=relatedPosts 

  Generally speaking, this function can be used as the followings: 

  1. 將它做爲一個方法的裝飾器來使用。

######################################################################## class Person(object): """""" #---------------------------------------------------------------------- def __init__(self, first_name, last_name): """Constructor""" self.first_name = first_name self.last_name = last_name #----------------------------------------------------------------------  @property def full_name(self): """ Return the full name """ return "%s %s" % (self.first_name, self.last_name)

  

>>> person = Person("Mike", "Driscoll") >>> person.full_name 'Mike Driscoll' >>> person.first_name 'Mike' >>> person.full_name = "Jackalope" Traceback (most recent call last): File "<string>", line 1, in <fragment> AttributeError: can't set attribute

  由於咱們將方法變成了屬性,咱們可使用正常的點符號訪問它。可是,若是咱們試圖將該屬性設爲其餘值,咱們會引起一個AttributeError錯誤. 

  @property普遍應用在類的定義中,可讓調用者寫出簡短的代碼,同時保證對參數進行必要的檢查,這樣,程序運行時就減小了出錯的可能性。

  

11. ipython notebook error: Unsupported nbformat version 4 

 ==>> error: 2017-08-16 10:28:29.718 [NotebookApp] WARNING | Unreadable Notebook: ~~/refer-master/pyEvalDemo.ipynb Unsupported nbformat version 4

 sudo apt-get install ipython notebook sudo pip install notebook --upgrade

 

12. python2 與python3 版本之間的切換

設置優先級

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2 100 

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 150 

 

13. install python 3.6 and pip3 on Ubuntu system. 

  reference blog: https://www.rosehosting.com/blog/how-to-install-python-3-6-on-ubuntu-16-04/

Python 2.7 and Python 3.5 are installed on Ubuntu 16.04 by default. In this tutorial, we will guide you through steps of installing the latest Python 3.6 on Ubuntu 16.04. 1. Login via SSH and update all installed packages First of all, login to your Ubuntu 16.04 VPS via SSH as user root ssh root@IP_Address -p Port_number and update all installed packages 2. Check the currently installed version of Python To check the currently installed version of Python, execute the following command # python -V
Python 2.7.12 To check the Python 3 version, use the following command # python3 -V
Python 3.5.2 There are two methods of installing Python 3.6 on an Ubuntu 16.04 VPS, from source, and from PPA. 3. Install Python 3.6 on Ubuntu 16.04, from source In order to install the latest Python 3.6 release for Linux/UNIX, go to their official website and download its source code to your server. At the moment of writing this article, it is version 3.6.3 cd /opt wget https://www.python.org/ftp/python/3.6.3/Python-3.6.3.tgz and unpack the downloaded archive tar -xvf Python-3.6.3.tgz 4. Method 1: Run the 「configure」 script Change the current working directory and run the ‘configure’ script cd Python-3.6.3 ./configure If there are no errors, run the following commands to complete the installation process of Python 3.6 make make install If you get the following error message zipimport.ZipImportError: can't decompress data; zlib not available
install the ‘zlib1g-dev’ package apt-get install zlib1g-dev are run ‘make’ and ‘make install’ again. That’s all. Python 3.6 should be successfully installed at this point. You can check this with the following command # python3.6 -V
Python 3.6.3
5. Method 2: Install Python 3.6 from PPA You can also install Python 3.6 from J Fernyhough’s Personal Package Archive (PPA). Install the following requirements apt-get install software-properties-common python-software-properties Run the following command to add the PPA # add-apt-repository ppa:jonathonf/python-3.6
Press [ENTER] to continue or ctrl-c to cancel adding it and press enter to continue. 6. Update the repositories update the repositories apt-get update 7. Install Python version 3.6 on Ubuntu 16.04

and finally, install Python version 3.6 apt-get install python3.6
7. Verify Python 3.6.3 installation Once it is installed, you can verify the installed version by executing the following command # python3.6 -V
Python 3.6.3 To learn more about Python version 3.6 check their official release notes.
View Code

  install pip3: 

wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c4188f8dbad6a1e6f6d44d117eeb  tar -zxvf pip-8.0.2.tar.gz cd pip-8.0.2 python3 setup.py build python3 setup.py install

  Then you can found the pip3 operation in the /usr/local/bin/ : 

  

14. nvcc -c -o crop_and_resize_kernel.cu.o crop_and_resize_kernel.cu -x cu -Xcompiler -fPIC -arch=[arch]

The program 'nvcc' is currently not installed. You can install it by typing:
sudo apt-get install nvidia-cuda-toolkit 

However, I have installed the cuda tools successfully. This issue can be solved by export path to the terminal according to: https://devtalk.nvidia.com/default/topic/995277/cuda-8-0-toolkit-install-nvcc-not-found-ubuntu-16-04/?offset=19 

export PATH=/usr/local/cuda-8.0/bin:$PATH export LD_LIBRARY_PATH=/usr/local/cuda-8.0/lib64:$LD_LIBRARY_PATH

 

15. cffi.error.VerificationError: CompileError: command 'gcc' failed with exit status 1

 1 creating media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src
 2 gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DWITH_CUDA -I/usr/local/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/usr/local/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/usr/local/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/usr/local/include/python3.6m -c _crop_and_resize.c -o ./_crop_and_resize.o -std=c99 -fopenmp -std=c99
 3 gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -fPIC -DWITH_CUDA -I/usr/local/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include -I/usr/local/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/TH -I/usr/local/lib/python3.6/site-packages/torch/utils/ffi/../../lib/include/THC -I/usr/local/cuda/include -I/usr/local/include/python3.6m -c /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c -o ./media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.o -std=c99 -fopenmp -std=c99
 4 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c: In function ‘crop_and_resize_forward’:
 5 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:124:33: error: dereferencing pointer to incomplete type
 6 const int batch_size = image->size[0];
 7 ^
 8 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:125:28: error: dereferencing pointer to incomplete type
 9 const int depth = image->size[1];
10 ^
11 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:126:35: error: dereferencing pointer to incomplete type
12 const int image_height = image->size[2];
13 ^
14 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:127:34: error: dereferencing pointer to incomplete type
15 const int image_width = image->size[3];
16 ^
17 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:129:32: error: dereferencing pointer to incomplete type
18 const int num_boxes = boxes->size[0];
19 ^
20 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c: In function ‘crop_and_resize_backward’:
21 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:165:39: error: dereferencing pointer to incomplete type
22 const int batch_size = grads_image->size[0];
23 ^
24 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:166:34: error: dereferencing pointer to incomplete type
25 const int depth = grads_image->size[1];
26 ^
27 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:167:41: error: dereferencing pointer to incomplete type
28 const int image_height = grads_image->size[2];
29 ^
30 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:168:40: error: dereferencing pointer to incomplete type
31 const int image_width = grads_image->size[3];
32 ^
33 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:170:32: error: dereferencing pointer to incomplete type
34 const int num_boxes = grads->size[0];
35 ^
36 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:171:34: error: dereferencing pointer to incomplete type
37 const int crop_height = grads->size[2];
38 ^
39 /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/py-MDNet-master-RoIAlign-V2/roialign/roi_align/src/crop_and_resize.c:172:33: error: dereferencing pointer to incomplete type
40 const int crop_width = grads->size[3];
41 ^
42 Traceback (most recent call last):
43 File "/usr/local/lib/python3.6/distutils/unixccompiler.py", line 118, in _compile
44 extra_postargs)
45 File "/usr/local/lib/python3.6/distutils/ccompiler.py", line 909, in spawn
46 spawn(cmd, dry_run=self.dry_run)
47 File "/usr/local/lib/python3.6/distutils/spawn.py", line 36, in spawn
48 _spawn_posix(cmd, search_path, dry_run=dry_run)
49 File "/usr/local/lib/python3.6/distutils/spawn.py", line 159, in _spawn_posix
50 % (cmd, exit_status))
51 distutils.errors.DistutilsExecError: command 'gcc' failed with exit status 1
52 
53 During handling of the above exception, another exception occurred:
54 
55 Traceback (most recent call last):
56 File "/usr/local/lib/python3.6/site-packages/cffi/ffiplatform.py", line 51, in _build
57 dist.run_command('build_ext')
58 File "/usr/local/lib/python3.6/distutils/dist.py", line 974, in run_command
59 cmd_obj.run()
60 File "/usr/local/lib/python3.6/distutils/command/build_ext.py", line 339, in run
61 self.build_extensions()
62 File "/usr/local/lib/python3.6/distutils/command/build_ext.py", line 448, in build_extensions
63 self._build_extensions_serial()
64 File "/usr/local/lib/python3.6/distutils/command/build_ext.py", line 473, in _build_extensions_serial
65 self.build_extension(ext)
66 File "/usr/local/lib/python3.6/distutils/command/build_ext.py", line 533, in build_extension
67 depends=ext.depends)
68 File "/usr/local/lib/python3.6/distutils/ccompiler.py", line 574, in compile
69 self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
70 File "/usr/local/lib/python3.6/distutils/unixccompiler.py", line 120, in _compile
71 raise CompileError(msg)
72 distutils.errors.CompileError: command 'gcc' failed with exit status 1
73 
74 During handling of the above exception, another exception occurred:
75 
76 Traceback (most recent call last):
77 File "build.py", line 40, in <module>
78 ffi.build()
79 File "/usr/local/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 189, in build
80 _build_extension(ffi, cffi_wrapper_name, target_dir, verbose)
81 File "/usr/local/lib/python3.6/site-packages/torch/utils/ffi/__init__.py", line 111, in _build_extension
82 outfile = ffi.compile(tmpdir=tmpdir, verbose=verbose, target=libname)
83 File "/usr/local/lib/python3.6/site-packages/cffi/api.py", line 697, in compile
84 compiler_verbose=verbose, debug=debug, **kwds)
85 File "/usr/local/lib/python3.6/site-packages/cffi/recompiler.py", line 1520, in recompile
86 compiler_verbose, debug)
87 File "/usr/local/lib/python3.6/site-packages/cffi/ffiplatform.py", line 22, in compile
88 outputfilename = _build(tmpdir, ext, compiler_verbose, debug)
89 File "/usr/local/lib/python3.6/site-packages/cffi/ffiplatform.py", line 58, in _build
90 raise VerificationError('%s: %s' % (e.__class__.__name__, e))
91 cffi.error.VerificationError: CompileError: command 'gcc' failed with exit status 1
View Code

According to the blog: https://github.com/jwyang/faster-rcnn.pytorch/issues/235 

we need to install pytorch 0.4.0 not 0.4.1. However, my current version is pytorch 0.4.1. 

 

16. ImportError: /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/reference_code/pytorch-mask-rcnn/pycocotools/_mask.so: undefined symbol: _Py_ZeroStruct

wangxiao@AHU:/media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/reference_code/pytorch-mask-rcnn$ python3 demo.py
Traceback (most recent call last):
File "demo.py", line 10, in <module>
import coco
File "/media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/reference_code/pytorch-mask-rcnn/coco.py", line 40, in <module>
from pycocotools.coco import COCO
File "/media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/reference_code/pytorch-mask-rcnn/pycocotools/coco.py", line 55, in <module>
from . import mask as maskUtils
File "/media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/reference_code/pytorch-mask-rcnn/pycocotools/mask.py", line 3, in <module>
import pycocotools._mask as _mask
ImportError: /media/wangxiao/b8efbc67-7ea5-476d-9631-70da75f84e2d/reference_code/pytorch-mask-rcnn/pycocotools/_mask.so: undefined symbol: _Py_ZeroStruct 

==>> According to the blog: https://blog.csdn.net/u011636567/article/details/78201106, we need to install the Cython under the Python3 envionment, because I installed this software before under Python 2.7. 

==>> However, this is maybe one of the reason caused this issue, but not mine. Actually, i need to modify the Makefile: 

all: # install pycocotools locally
python3 setup.py build_ext --inplace rm -rf build install: # install pycocotools to the Python site-packages
python3 setup.py build_ext install rm -rf build

 

 

17. It shown me the following error, but when I re-running my code, it can jump it, but it still occur sometimes: 

Exception RuntimeError: RuntimeError('main thread is not in main loop',) in <bound method PhotoImage.__del__ of <Tkinter.PhotoImage instance at 0x7f0edf4e5758>> ignored

Tcl_AsyncDelete: async handler deleted by the wrong thread
Aborted (core dumped)

 

18. Could not fetch URL https://pypi.python.org/simple/numpy/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping 

A18: https://blog.csdn.net/zr1076311296/article/details/75136612 

1.安裝ssl
sudo apt-get install openssl
sudo apt-get install libssl-dev
2. 修改Moudles/Setup (該目錄在python的解壓目錄下) 直接將這一段拷貝到該文件的最後便可!親測可行!!!
vim Modules/Setup
#修改結果以下:
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
3.從新安裝一次
./configure --prefix=/usr/local/python
make
sudo -H make install
4.python3
>>>import ssl #檢測成功!
>>>

19. 安裝並指定 Ubuntu 默認的 Python 版本

Referencehttps://blog.csdn.net/shenlongshi/article/details/79630940 

1. 安裝 Python3.6 sudo add-apt-repository ppa:deadsnakes/ppa sudo apt-get update sudo apt-get install python3.6
2. 列出系統當前存在的python版本及python默認的版本 ls -l /usr/bin | grep python 3. 刪除原有的 python 或者 python3 的連接: sudo rm /usr/bin/python 4. 創建python到python3.6.4新的軟連接 sudo ln -s /usr/bin/python3.6 /usr/bin/python 5. 測試系統默認python命令已經指向python3.6.4 python -V 

 

20. ModuleNotFoundError: No module named '_tkinter'

Traceback (most recent call last):
File "run_tracker_OTB100_p1.py", line 8, in <module>
import matplotlib.pyplot as plt
File "/usr/local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 2374, in <module>
switch_backend(rcParams["backend"])
File "/usr/local/lib/python3.6/site-packages/matplotlib/pyplot.py", line 207, in switch_backend
backend_mod = importlib.import_module(backend_name)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/usr/local/lib/python3.6/site-packages/matplotlib/backends/backend_tkagg.py", line 1, in <module>
from . import _backend_tk
File "/usr/local/lib/python3.6/site-packages/matplotlib/backends/_backend_tk.py", line 5, in <module>
import tkinter as Tk
File "/usr/local/lib/python3.6/tkinter/__init__.py", line 36, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ModuleNotFoundError: No module named '_tkinter' 

A20:

1. 對於 Python3.6 來說,執行這個命令來安裝這個軟件:
sudo apt-get install python3.6-tk 
2. 從新安裝 Python3.6
3. 檢查是否成功

 

Q21. Scripts to run the MDNet on benchmarks ans save the results into txt files: 

 1 if __name__ == "__main__":
 2 
 3     videos = ['Basketball', 'Biker', 'Bird1','Matrix','Diving','Girl2','Bird2','BlurBody','BlurCar1','BlurCar2','MotorRolling','Jump','CarScale',
 4               'BlurCar4','BlurFace','BlurOwl','Board','Bolt','Bolt2','Twinnings','Vase', 'Walking','Walking2','Woman', 'BlurCar3','David2','Freeman3',
 5               'Box','Boy','Car1','Car2','Car24','Car4','CarDark','ClifBar','Coke','Couple','Coupon','Crossing','Crowds','Dancer','Dancer2','David',
 6               'David3','Deer','Dog','Dog1','Doll','DragonBaby','Dudek','FaceOcc1','FaceOcc2','Fish','FleetFace','Football','Football1','Freeman1',
 7               'Freeman4','Girl','Gym','Human2','Human3','Human4','Human5','Human6','Human7','Human8','Human9','Ironman','Jogging-1','Jogging-2','Jumping',
 8               'KiteSurf','Lemming','Liquor','Man','Mhyang','MountainBike','Panda','RedTeam','Rubik','Shaking','Singer1','Singer2','Skater','Skater2',
 9               'Skating1','Skating2-1','Skating2-2','Skiing','Soccer','Subway','Surfer','Suv','Sylvester','Tiger1','Tiger2','Toy','Trans','Trellis']
10  
11     # videos = ['ball','bicycle','bolt','david','diving','drunk','fernando','fish1','fish2','gymnastics','hand1','hand2','jogging','motocross','polarbear',
12     #             'skating','sphere','sunshade','surfing','torus','trellis','tunnel', 'woman','skating','car','basketball']
13 
14     # videos = ['bag','ball1','ball2','basketball','birds1','birds2','blanket','bmx','bolt1','bolt2','book','butterfly','car1','car2',
15     #           'crossing','dinosaur','fernando','fish1','fish2','fish3','fish4','girl','glove','godfather','graduate','gymnastics1','gymnastics2',
16     #           'gymnastics3','gymnastics4','hand','handball1','handball2','helicopter','iceskater1','iceskater2','leaves','marching','matrix',
17     #           'motocross1','motocross2','nature','octopus','pedestrian1','pedestrian2','rabbit','racing','road','shaking','sheep','singer1',
18     #           'singer2','singer3','soccer1','soccer2','soldier','sphere','tiger','traffic','tunnel','wiper']
19 
20 
21     for vid in range(len(videos)) : 
22         videoname = videos[vid]
23         seq_home = '/home/wangxiao/data/OTB100'
24         save_home = '../result_fig'
25         result_home = './pyMDNetOTB100_v1'
26 
27         resultFiles = os.listdir(result_home)
28 
29         if videoname in resultFiles: 
30             vid = vid + 1 
31         else:
32             seq_name = videoname
33             img_dir = os.path.join(seq_home, seq_name, 'img')
34             gt_path = os.path.join(seq_home, seq_name, 'groundtruth_rect_new.txt')
35 
36             print("==>> deal with video: ", seq_name)
37 
38             img_list = os.listdir(img_dir)
39             img_list.sort()
40             img_list = [os.path.join(img_dir,x) for x in img_list]
41 
42             gt = np.loadtxt(gt_path, delimiter=',') 
43 
44             init_bbox = gt[0]
45             
46             savefig_dir = os.path.join(save_home,seq_name)
47             result_dir = os.path.join(result_home,seq_name)
48             if not os.path.exists(result_dir):
49                 os.makedirs(result_dir)
50             result_path = os.path.join(result_dir,'result.json')
51 
52             # Run tracker
53             result, result_bb, fps = run_mdnet(img_list, init_bbox, videoname, gt=gt)
54             
55             # Save result
56             res = {}
57             res['res'] = result_bb.round().tolist()
58             res['type'] = 'rect'
59             res['fps'] = fps
60             json.dump(res, open(result_path, 'w'), indent=2)
View Code

#####################################
#### save into txt
#####################################
txtName = seq + '_baseline.txt'
fid = open(result_home+txtName, 'w')
for iidex in range(len(result_bb)):
line = result_bb[iidex]
# pdb.set_trace()

fid.write(str(line[0]))
fid.write(',')
fid.write(str(line[1]))
fid.write(',')
fid.write(str(line[2]))
fid.write(',')
fid.write(str(line[3]))
fid.write('\n')
fid.close()

 

Q22. AttributeError: 'NoneType' object has no attribute '_inbound_nodes' 

Traceback (most recent call last):
File "tip_language_guided_VAE_train_64_64.py", line 163, in <module>
vae = Model(x, x_decoded_mean)
File "/usr/local/lib/python2.7/dist-packages/keras/legacy/interfaces.py", line 91, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/network.py", line 93, in __init__
self._init_graph_network(*args, **kwargs)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/network.py", line 237, in _init_graph_network
self.inputs, self.outputs)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/network.py", line 1353, in _map_graph_network
tensor_index=tensor_index)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/network.py", line 1340, in build_map
node_index, tensor_index)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/network.py", line 1340, in build_map
node_index, tensor_index)
File "/usr/local/lib/python2.7/dist-packages/keras/engine/network.py", line 1312, in build_map
node = layer._inbound_nodes[node_index]
AttributeError: 'NoneType' object has no attribute '_inbound_nodes'

==>> Solutionhttps://stackoverflow.com/questions/51963377/keras-nonetype-object-has-no-attribute-inbound-nodes 

https://blog.csdn.net/u011897301/article/details/83620126 

 

Q23. OSError: libcudart.so.10.0: cannot open shared object file: No such file or directory  

Traceback (most recent call last):
 File "train_toy.py", line 1, in <module>
   import mxnet as mx
 File "/root/miniconda3/lib/python3.6/site-packages/mxnet/__init__.py", line 24, in <module>
   from .context import Context, current_context, cpu, gpu, cpu_pinned
 File "/root/miniconda3/lib/python3.6/site-packages/mxnet/context.py", line 24, in <module>
   from .base import classproperty, with_metaclass, _MXClassPropertyMetaClass
 File "/root/miniconda3/lib/python3.6/site-packages/mxnet/base.py", line 213, in <module>
   _LIB = _load_lib()
 File "/root/miniconda3/lib/python3.6/site-packages/mxnet/base.py", line 204, in _load_lib
   lib = ctypes.CDLL(lib_path[0], ctypes.RTLD_LOCAL)
 File "/root/miniconda3/lib/python3.6/ctypes/__init__.py", line 348, in __init__
   self._handle = _dlopen(self._name, mode)
OSError: libcudart.so.10.0: cannot open shared object file: No such file or directory

A23. I meet this bug when I run the code of adaptis, and I search one solution as follows, it indeed worked. 
root@o:/home/wangxiao/data/adaptis# pip install --user mxnet

Collecting mxnet
 Downloading https://files.pythonhosted.org/packages/92/6c/c6e5562f8face683cec73f5d4d74a58f8572c0595d54f1fed9d923020bbd/mxnet-1.5.1.post0-py2.py3-none-manylinux1_x86_64.whl (25.4MB)
    |████████████████████████████████| 25.4MB 693kB/s  
Requirement already satisfied: numpy<2.0.0,>1.16.0 in /root/miniconda3/lib/python3.6/site-packages (from mxnet) (1.16.4)
Requirement already satisfied: requests<3,>=2.20.0 in /root/miniconda3/lib/python3.6/site-packages (from mxnet) (2.22.0)
Collecting graphviz<0.9.0,>=0.8.1 (from mxnet)
 Downloading https://files.pythonhosted.org/packages/53/39/4ab213673844e0c004bed8a0781a0721a3f6bb23eb8854ee75c236428892/graphviz-0.8.4-py2.py3-none-any.whl
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /root/miniconda3/lib/python3.6/site-packages (from requests<3,>=2.20.0->mxnet) (1.24.2)
Requirement already satisfied: idna<2.9,>=2.5 in /root/miniconda3/lib/python3.6/site-packages (from requests<3,>=2.20.0->mxnet) (2.8)
Requirement already satisfied: certifi>=2017.4.17 in /root/miniconda3/lib/python3.6/site-packages (from requests<3,>=2.20.0->mxnet) (2019.6.16)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /root/miniconda3/lib/python3.6/site-packages (from requests<3,>=2.20.0->mxnet) (3.0.4)
Installing collected packages: graphviz, mxnet
Successfully installed graphviz-0.8.4 mxnet-1.5.1.post0
 

Q24.  mxnet.base.MXNetError: value 0 for Parameter num_args should be greater equal to 1, in operator add_n(name="", num_args="0")

  File "/DATA/wangxiao/adaptis/adaptis/utils/misc.py", line 22, in save_checkpoint
   net.save_parameters(str(checkpoint_path))
 File "/root/.local/lib/python3.6/site-packages/mxnet/gluon/block.py", line 334, in save_parameters
   arg_dict = {key : val._reduce() for key, val in params.items()}
 File "/root/.local/lib/python3.6/site-packages/mxnet/gluon/block.py", line 334, in <dictcomp>
   arg_dict = {key : val._reduce() for key, val in params.items()}
 File "/root/.local/lib/python3.6/site-packages/mxnet/gluon/parameter.py", line 366, in _reduce
   data = ndarray.add_n(*(w.copyto(ctx) for w in block)) / len(block)
 File "<string>", line 44, in add_n
 File "/root/.local/lib/python3.6/site-packages/mxnet/_ctypes/ndarray.py", line 92, in _imperative_invoke
   ctypes.byref(out_stypes)))
 File "/root/.local/lib/python3.6/site-packages/mxnet/base.py", line 253, in check_call
   raise MXNetError(py_str(_LIB.MXGetLastError()))
mxnet.base.MXNetError: value 0 for Parameter num_args should be greater equal to 1, in operator add_n(name="", num_args="0") 

A24. Some parameters I need to initialize, but I am not. 

 

Q25. 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

==

相關文章
相關標籤/搜索