【问题标题】:TFLearn CovNet example resulting in an error w/ CIFAR-10TFLearn CovNet 示例导致带有 CIFAR-10 的错误
【发布时间】:2016-10-23 06:44:36
【问题描述】:

我正在尝试通过为cifar 数据集构建分类器来了解神经网络。我决定从tflearn repo 中获取一个示例,但是我遇到了麻烦。

有几点需要注意:

我正在使用Jupyter Notebook 来测试我的模型。

我正在使用https://www.cs.toronto.edu/~kriz/cifar.html 上的Cifar 数据集。每个图像都是一个形状数组[3072](它被展平成一个数组)

版本:Python 3.5、Tensorflow 0.10、TFLearn 0.2.1

import tflearn
from tflearn.data_utils import shuffle, to_categorical
from tflearn.layers.core import input_data, dropout, fully_connected
from tflearn.layers.conv import conv_2d, max_pool_2d
from tflearn.layers.estimator import regression

(X, Y), (X_test, Y_test) = (raw_train_data, raw_train_labels), \
                       (raw_test_data, raw_test_labels)
X, Y = shuffle(X, Y)
Y = to_categorical(Y, 10)
Y_test = to_categorical(Y_test, 10)

# X, X_test = tf.reshape(X, [-1, 32, 32, 3]), tf.reshape(X_test, [-1, 32, 32, 3])
# Convolutional network building
network = input_data(shape=[None, 32, 32, 3],
                 data_preprocessing=img_prep,
                 data_augmentation=img_aug)
network = conv_2d(network, 32, 3, activation='relu')
network = max_pool_2d(network, 2)
network = conv_2d(network, 64, 3, activation='relu')
network = conv_2d(network, 64, 3, activation='relu')
network = max_pool_2d(network, 2)
network = fully_connected(network, 512, activation='relu')
network = dropout(network, 0.5)
network = fully_connected(network, 10, activation='softmax')
network = regression(network, optimizer='adam',
                 loss='categorical_crossentropy',
                 learning_rate=0.01)

model = tflearn.DNN(network, tensorboard_verbose=0)
model.fit(X, Y, n_epoch=2, shuffle=False, validation_set=(X_test, Y_test),
      show_metric=False, batch_size=50, run_id='cifar10_cnn')

我在第一次运行时遇到以下异常: 线程 Thread-17 中的异常:

ValueError: Input must be >= 2-d.

当我在不重置内核的情况下重新运行笔记本时,我的错误消息变为:

IndexError: list index out of range

最后,当我尝试使用 Tensorflow 重塑数据时:

TypeError: 'Tensor' object is not iterable.

【问题讨论】:

    标签: python neural-network tensorflow conv-neural-network


    【解决方案1】:

    我觉得这是您的 tf 和 tf-learn 安装的问题。 我强烈建议您重新安装 tensorflow 和 tflearn(不确定 Jupyter 使用的是什么) 因为我刚刚使用 virtualenv 进行了全新安装。一切都像带有 .py 文件的终端的魅力一样。 您能否指出 Jupyter 笔记本,以便我查看 tf 和 tf-learn 的版本?

    这是代码的修改版本(带有您的参数): 我使用了 convnet 示例 here 作为基础。

    https://gist.github.com/hakanu/1cc91000548978e0245a901e565040d1

    【讨论】:

      猜你喜欢
      • 2016-04-16
      • 1970-01-01
      • 1970-01-01
      • 2018-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      相关资源
      最近更新 更多