1. 程式人生 > >Tensorflow+python3 常見執行問題及其解決方法

Tensorflow+python3 常見執行問題及其解決方法

1 SyntaxError: Missing parentheses in call to ‘print’

解決:python2支援 print “xxxx” ,python3需要使用print(“xxx”)

2 SyntaxError: multiple statements found while compiling a single statement

解決:多行程式碼直接在IDLE中編譯,是每行都要回車的,或者新建一個py檔案來執行。

3 ImportError: Could not find ‘cudart64_90.dll’.

ImportError: Could not find ‘cudart64_90.dll’. TensorFlow requires that this DLL be installed in a directory that is named in your %PATH% environment variable. Download and install CUDA 9.0 from this URL:

https://developer.nvidia.com/cuda-toolkit
解決:tensorflow只支援cuda9.0,下載9.0並安裝。

4 ImportError: No module named ‘utils’

解決:pip install utils

5 NameError: name ‘xrange’ is not defined

解決:Python3中xrange改為range

6 ImportError: No module named ‘input_data’

解決:解決:下載input_data或者使用tensorflow自帶的input_data
from tensorflow.examples.tutorials.mnist import input_data

7 ValueError: Cannot evaluate tensor using eval()

ValueError: Cannot evaluate tensor using eval(): No default session is registered
解決:根據提示新增引數sess(sess為自己定義的Session名稱):

train_accuracy = accuracy.eval(feed_dict={x:batch[0], y_: batch[1], keep_prob: 1.0})  

修改為:

train_accuracy = accuracy.eval(session=sess,feed_dict={x:batch[0], y_: batch[1], keep_prob: 1.0})  

8 ValueError: Cannot execute operation using run()

ValueError: Cannot execute operation using run(): No default session is registered. Use with sess.as_default(): or pass an explicit session to run(session=sess)
解決:根據提示新增引數sess(sess為自己定義的Session名稱)

train_step.run(feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5}) 

修改為:

train_step.run(session=sess, feed_dict={x: batch[0], y_: batch[1], keep_prob: 0.5})  

9 Import cv2 ImportError:DLL load failed

10