import tensorflow as tf
a=3
#create a variable
w=tf.Variable([[0.5,1.0]])
x=tf.Variable([[2.0],[1.0]])
y=tf.matmul(w,x)
print(y)
#variables have to be expicitly initialized before you can run ops
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
print(y)
運行時報錯,沒有全域變數引數,這是因為tensorflow2.0的版本將1.x版本的東西都打包到compat.v1里面去了,
將import tensorflow as tf 改為 import tensorflow.compat.v1 as tf ,問題解決。
uj5u.com熱心網友回復:
是的。tf2和tf1完全不一樣,做好版本管理。轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/169934.html
