AttributeError:模块"tensorflow_core.compat.v1"没有属性"contrib" [英] AttributeError: module 'tensorflow_core.compat.v1' has no attribute 'contrib'

查看:223
本文介绍了AttributeError:模块"tensorflow_core.compat.v1"没有属性"contrib"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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并得到了标题中提到的错误.如果有人可以帮助我使用一个代码示例来解决问题,我将非常感激.

2.This is my code in Jupyter Notebook. I just started with python and get the error I mentioned in the headline. I would be very thankful if someone could help me wizh a code example to solve the problem.

推荐答案

tf.contrib 在TensorFlow 2.0 alpha版本中已从TensorFlow中删除.

tf.contrib was removed from TensorFlow once with TensorFlow 2.0 alpha version.

很可能您已经在使用TensorFlow 2.0.

Most likely, you are already using TensorFlow 2.0.

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

You can find more details here: https://github.com/tensorflow/tensorflow/releases/tag/v2.0.0-alpha0

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

For using specific versions of tensorflow, use

pip install tensorflow==1.14

pip install tensorflow-gpu==1.14

这篇关于AttributeError:模块"tensorflow_core.compat.v1"没有属性"contrib"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆