'TensorFlow - Tflearning error feed_dict
I am working on a classification problem in python. Fact is, I'm not good yet in TensorFlow. So I have the same problem since a long time now and I don't know how to fix it. I hope you could help me :)
This is my data :
X : 8000 pictures : 32*32px and 3 colors (rgb), so I load a matrix X.shape = (8000,32,32,3)
Y : 4 classes (1,2,3 and 4): Y. shape = (8000,1)
This is my code :
network = input_data(shape=[None, 32, 32, 3], name='iput')
# Step 1: Convolution
network = conv_2d(network, 32, 3, activation='relu')
# Step 2: Max pooling
network = max_pool_2d(network, 2)
# Step 3: Convolution again
network = conv_2d(network, 64, 3, activation='relu')
# Step 4: Convolution yet again
network = conv_2d(network, 64, 3, activation='relu')
# Step 5: Max pooling again
network = max_pool_2d(network, 2)
# Step 6: Fully-connected 512 node neural network
network = fully_connected(network, 512, activation='relu')
# Step 7: Dropout - throw away some data randomly during training to prevent over-fitting
network = dropout(network, 0.5)
# Step 8: Fully-connected neural network with 4 outputs
network = fully_connected(network, 4, activation='softmax')
# Tell tflearn how we want to train the network
network = regression(network, optimizer='adam',
loss='categorical_crossentropy',
learning_rate=0.001)
model = tflearn.DNN(network)
model.fit(X, Y)
This is my erros
Traceback (most recent call last):
File "", line 3, in
model.fit(X, Y)
File "/home/side/anaconda3/lib/python3.5/site-packages/tflearn/models/dnn.py",
line 157, in fit
self.targets)
File "/home/side/anaconda3/lib/python3.5/site-packages/tflearn/utils.py", line 267, in feed_dict_builder feed_dict[net_inputs[i]] = x IndexError: list index out of range
I have also tried to pass X as (8000,3072) Matrix And Y as (8000,4) Matrix, for exemple :
[0 0 1 0 <-- Y[0] = 3
0 1 0 0 <-- Y[1] = 2
...]
I reuse this code : https://github.com/tflearn/tflearn/blob/master/examples/images/convnet_cifar10.py , used to class cifar10 data.
Thank you for your help,
Celia
Solution 1:[1]
Another option is to add:
tf.reset_default_graph()
As the first line of your code
Solution 2:[2]
Paraphrased from the source code :
The number of inputs don't match the expected ones.
If you are using ipython notebook, make sure you didn't run the graph construction cell multiple times. Or enclose the graph construction in the with tf.Graph().as_default() block.
Solution 3:[3]
As motjuste says when you use a notebooks with TFLearn, you should restart your kernel everytime you run your code.
See this issue in github:
Solution 4:[4]
as Luis Leal says, its a good way to solve this problem, but after adding this code, it's wrong as follow
AttributeError: module 'tensorflow' has no attribute 'reset_default_graph'
so, if you have same problem too, you can use the code
from tensorflow.python.framework import ops
ops.reset_default_graph()
replacetf.reset_default_graph()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Luis Leal |
| Solution 2 | motjuste |
| Solution 3 | Julian |
| Solution 4 | ZERONE |
