William Gottschalk
William Gottschalk

Reputation: 261

TFLearn CovNet example resulting in an error w/ CIFAR-10

I'm trying to get my feet wet with Neural Nets by building a classifier for the cifar dataset. I decided to grab an example from the tflearn repo, however I'm running into trouble.

There are some things to note:

I'm using Jupyter Notebook to test my model.

I'm using the Cifar dataset that is on https://www.cs.toronto.edu/~kriz/cifar.html. Each image is an array of shape [3072] (its flattened into a single array)

Versions: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')

I get the following exception on the first run: Exception in thread Thread-17:

ValueError: Input must be >= 2-d.

When I rerun the notebook without resetting the kernel, my error message changes to:

IndexError: list index out of range

And then finally when I try to reshape my data using Tensorflow:

TypeError: 'Tensor' object is not iterable.

Upvotes: 1

Views: 1894

Answers (1)

Hakan
Hakan

Reputation: 618

I feel like this is an issue with your tf and tf-learn install. I strongly recommend you to reinstall tensorflow and tflearn (not sure what Jupyter is using) Because I've just had a clean install using virtualenv. Everything works like a charm from terminal with .py file. Could you point out the Jupyter notebook so I can take a look at the versions of tf and tf-learn?

Here is the modified version of the code (with your parameters): I used the convnet example here as base.

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

Upvotes: 2

Related Questions