Frank B.
Frank B.

Reputation: 315

TFLearn: Define correct dimension of DNN

I'm building a DNN for a pattern recognition problem using TFLearn in Python 3.5. My input is shaped as a [50, 300], so roughly speaking my training set is a list of arrays each composed of 50 elements which are an array of 300 elements.

All arrays I'm building are NumPy arrays.

Here the code I'm using:

training = np.array(training)

# create train and test lists
train_x = list(training[:,0])
print(train_x[0])
train_y = list(training[:,1])
# reset underlying graph data
tf.reset_default_graph()
mean = int(len(train_x[0])/len(train_y[0]))
net = tflearn.input_data(shape=[None, 50, 300])
net = tflearn.fully_connected(net, mean)
net = tflearn.fully_connected(net, mean)
net = tflearn.fully_connected(net, len(train_y[0]), activation='softmax')
net = tflearn.regression(net)
# Define model and setup tensorboard
model = tflearn.DNN(net, tensorboard_dir='tflearn_logs')
# Start training (apply gradient descent algorithm)
model.fit(train_x, train_y, show_metric=True)

But the error I'm getting is the following:

Traceback (most recent call last):
  File "/Users/Foo/Bar/test.py", line 82, in <module>
model.fit(train_x, train_y, show_metric=True)
  File "/usr/local/lib/python3.5/site-packages/tflearn/models/dnn.py", line 215, in fit
callbacks=callbacks)
  File "/usr/local/lib/python3.5/site-packages/tflearn/helpers/trainer.py", line 336, in fit
show_metric)
  File "/usr/local/lib/python3.5/site-packages/tflearn/helpers/trainer.py", line 777, in _train
feed_batch)
  File "/usr/local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 778, in run
run_metadata_ptr)
  File "/usr/local/lib/python3.5/site-packages/tensorflow/python/client/session.py", line 954, in _run
np_val = np.asarray(subfeed_val, dtype=subfeed_dtype)
  File "/usr/local/lib/python3.5/site-packages/numpy/core/numeric.py", line 531, in asarray
return array(a, dtype, copy=False, order=order)
ValueError: setting an array element with a sequence.

Probably I'm not well defining shapes of the Network. How may I fix it?

Thanks in advice

Upvotes: 0

Views: 98

Answers (1)

ahmet hamza emra
ahmet hamza emra

Reputation: 630

There is nothing wrong with defining the network but the problem is X and Y, first of all they are list but they should be array, it will be better if you fix that first then check the shape of the arrays you fit.

Check this one:

# create train and test lists
train_x = training[:,0].reshape([-1,50,300])
print(train_x.shape)
train_y = training[:,1]

Upvotes: 1

Related Questions