TensorFlow例外:AttributeError:モジュール「tensorflow」に属性「mul」がありません



Tensorflow Exception



AttributeError:モジュール 'tensorflow'には属性 'mul'がありません

実行コード:



import tensorflow as tf sess = tf.Session() a = tf.placeholder('float') b = tf.placeholder('float') c = tf.constant(6.0) d = tf.mul(a, b) y = tf.mul(d, c) print(sess.run(y, feed_dict={a: 3, b: 3})) A = [[1.1,2.3],[3.4,4.1]] Y = tf.matrix_inverse(A) print(sess.run(Y)) sess.close()

例外情報:

File 'F:/demo/learning_tensorflow/1.py', line 8, in d = tf.mul(a, b) AttributeError: module 'tensorflow' has no attribute 'mul'

理由:TensorFlowの「mul」関数は 'になりますかける'機能。 TensorFlowのバージョンが異なれば、使用する関数も異なります。



変更後:

import tensorflow as tf sess = tf.Session() a = tf.placeholder('float') b = tf.placeholder('float') c = tf.constant(6.0) d = tf.multiply(a, b) y = tf.multiply(d, c) print(sess.run(y, feed_dict={a: 3, b: 3})) A = [[1.1,2.3],[3.4,4.1]] Y = tf.matrix_inverse(A) print(sess.run(Y)) sess.close()

演算結果:

54.0 [[-1.2386707 0.69486403] [ 1.0271904 -0.33232632]] Process finished with exit code 0 tf.mul関数はtf.multiplyに置き換えられました正常に動作した後。わかりました、例外は解決されました。