我正在尝试实现VGG,但遇到上述奇怪的错误。我在 Ubuntu 上运行 TFv2。这可能是因为我没有运行CUDA吗?代码来自此处。from __future__ import absolute_importfrom __future__ import divisionfrom __future__ import print_function# Importsimport timeimport numpy as npimport tensorflow as tfimport matplotlib.pyplot as plt# tf.logging.set_verbosity(tf.logging.INFO)from tensorflow.keras.layers import Conv2D, Dense, Flattennp.random.seed(1)mnist = tf.keras.datasets.mnist(train_data, train_labels), (eval_data, eval_labels) = mnist.load_data()train_data, train_labels = train_data / 255.0, train_labels / 255.0# Add a channels dimensiontrain_data = train_data[..., tf.newaxis]train_labels = train_labels[..., tf.newaxis]index = 7plt.imshow(train_data[index].reshape(28, 28))plt.show()time.sleep(5);print("y = " + str(np.squeeze(train_labels[index])))print ("number of training examples = " + str(train_data.shape[0]))print ("number of evaluation examples = " + str(eval_data.shape[0]))print ("X_train shape: " + str(train_data.shape))print ("Y_train shape: " + str(train_labels.shape))print ("X_test shape: " + str(eval_data.shape))print ("Y_test shape: " + str(eval_labels.shape))print("done")
3 回答
紫衣仙女
TA贡献1839条经验 获得超15个赞
您可以使用 postfix compat.v1 使为 tensorflow 1.x 编写的代码与较新版本一起使用。
在你的情况下,这可以通过改变来实现:
tf.layers.conv2d
自
tf.compat.v1.layers.conv2d
您可以在此处阅读有关将张量流 v1.x 迁移到张量流 v2.x 的更多信息:
https://www.tensorflow.org/guide/migrate
喵喔喔
TA贡献1735条经验 获得超5个赞
使用 tensorflow 1.x 而不是 tensorflow 2.x 版本。但请记住,Python 3.8上没有2.x版本。使用具有tensorflow 1.x的Python的较低版本。
python3.6 -m pip install tensorflow==1.8.0
添加回答
举报
0/150
提交
取消