x = tf.placeholder(dtype = tf.float32, shape = [None, 28, 28])
y = tf.placeholder(dtype = tf.int32, shape = [None])
images_flat = tf.contrib.layers.flatten(x)
logits = tf.contrib.layers.fully_connected(images_flat, 62, tf.nn.relu)
loss =
tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(
labels = y, logits = logits))
train_op =
tf.train.AdamOptimizer(learning_rate=0.001).minimize(loss)
correct_pred = tf.argmax(logits, 1)
accuracy = tf.reduce_mean(tf.cast(correct_pred,
tf.float32))
print("images_flat: ", images_flat)
print("logits: ", logits)
print("loss: ", loss)
print("predicted_labels: ", correct_pred)
AttributeError Traceback (most recent call last)
<ipython-input-17-183722ce66a3> in <module>
1 x = tf.placeholder(dtype = tf.float32, shape = [None, 28, 28])
2 y = tf.placeholder(dtype = tf.int32, shape = [None])
----> 3 images_flat = tf.contrib.layers.flatten(x)
4 logits = tf.contrib.layers.fully_connected(images_flat, 62, tf.nn.relu)
5 loss = tf.reduce_mean(tf.nn.sparse_softmax_cross_entropy_with_logits(labels = y, logits = logits))
AttributeError: module 'tensorflow_core.compat.v1' has no attribute 'contrib'
2.これはJupyter Notebookの私のコードです。 python=で始めたところ、見出しで述べたエラーが発生しました。問題を解決するためのコード例を誰かに教えてもらえれば、とてもありがたいです。
実行しようとしているpythonファイルに次の行を追加する必要があると思います。
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()