gpt4 book ai didi

python - 属性错误 : module 'tensorflow_core.compat.v1' has no attribute 'contrib'

转载 作者:行者123 更新时间:2023-12-03 23:27:54 28 4
gpt4 key购买 nike

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 并得到我在标题中提到的错误。如果有人可以帮助我提供代码示例来解决问题,我将不胜感激。

最佳答案

tf.contrib曾经在 TensorFlow 2.0 alpha 版本中从 TensorFlow 中删除。

很可能,您已经在使用 TensorFlow 2.0。

您可以在此处找到更多详细信息:https://github.com/tensorflow/tensorflow/releases/tag/v2.0.0-alpha0

要使用特定版本的 tensorflow,请使用

pip install tensorflow==1.14

或者
pip install tensorflow-gpu==1.14

关于python - 属性错误 : module 'tensorflow_core.compat.v1' has no attribute 'contrib' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59644859/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com