I'm trying to implement a simple logistic regression model trained with my own set of images, but I am getting this error when I try to train the model:
Traceback (most recent call last):
File "main.py", line 26, in <module>
model.entrenar_modelo(sess, training_images, training_labels)
File "/home/jr/Desktop/Dropbox/Machine_Learning/TF/Míos/Hip/model_log_reg.py", line 24, in entrenar_modelo
train_step.run({x: batch_xs, y_: batch_ys})
File "/home/jr/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 1267, in run
_run_using_default_session(self, feed_dict, self.graph, session)
File "/home/jr/.local/lib/python2.7/site-packages/tensorflow/python/framework/ops.py", line 2763, in _run_using_default_session
session.run(operation, feed_dict)
File "/home/jr/.local/lib/python2.7/site-packages/tensorflow/python/client/session.py", line 334, in run
np_val = np.array(subfeed_val, dtype=subfeed_t.dtype.as_numpy_dtype)
ValueError: setting an array element with a sequence.
The data I'm feeding to train_step.run({x: batch_xs, y_: batch_ys})
is like this:
What am I doing wrong?
It seems the problem was that I had to evaluate the tensors in batch_xs
before passing them to train_step.run(...)
. I thought the run method would take care of that, but I guess I was wrong?
Anyway, so once I did this before calling the function:
for i, x in enumerate(batch_xs):
batch_xs[i] = x.eval()
#print batch_xs[i].shape
#assert all(x.shape == (100, 100, 3) for x in batch_xs)
# Now I can call the function
I had several issues even after doing what is suggested in the answers below. I finally fixed everything by ditching tensors and using numpy arrays.
This particular error is coming out of numpy
. Calling np.array
on a sequence with a inconsistant dimensions can throw it.
>>> np.array([1,2,3,[4,5,6]])
ValueError: setting an array element with a sequence.
It looks like it's failing at the point where tf
ensures that all the elements of the feed_dict
are numpy.array
s.
Check your feed_dict
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With