matthewearl / deep-anpr

Using neural networks to build an automatic number plate recognition system
MIT License
1.85k stars 697 forks source link

ValueError: Only call `softmax_cross_entropy_with_logits` with named arguments (labels=..., logits=..., ...) #19

Open ChadTaljaardt opened 7 years ago

ChadTaljaardt commented 7 years ago

I have this error running ./train.py. Does anyone know why?

2017-01-30 07:33:03: I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcublas.so.8.0 locally
2017-01-30 07:33:03: I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcudnn.so.5 locally
2017-01-30 07:33:03: I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcufft.so.8.0 locally
2017-01-30 07:33:03: I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcuda.so.1 locally
2017-01-30 07:33:03: I tensorflow/stream_executor/dso_loader.cc:135] successfully opened CUDA library libcurand.so.8.0 locally
Traceback (most recent call last):
  File "./train.py", line 266, in <module>
    initial_weights=initial_weights)
  File "./train.py", line 174, in train
    digits_loss, presence_loss, loss = get_loss(y, y_)
  File "./train.py", line 132, in get_loss
    [-1, len(common.CHARS)]))
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_ops.py", line 1578, in softmax_cross_entropy_with_logits
    labels, logits)
  File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/nn_ops.py", line 1533, in _ensure_xent_args
    "named arguments (labels=..., logits=..., ...)" % name)
ValueError: Only call `softmax_cross_entropy_with_logits` with named arguments (labels=..., logits=..., ...)
balcilar commented 7 years ago

I took the exact same error. I do not know why but train.py file seems to be wrong or at least wrong for my configuration. I changed some lines in getloss(y,y) function as..

.... digits_loss = tf.nn.softmax_cross_entropy_withlogits(logits= tf.reshape(y[:, 1:],[-1,len(common.CHARS)]), labels=tf.reshape(y[:, 1:], [-1, len(common.CHARS)]))

.... presence_loss = tf.nn.sigmoid_cross_entropy_withlogits(labels=y[:, :1], logits= y[:, :1])

.....

that it run.

hungpt297 commented 7 years ago

From tensorflow v1, only call softmax_cross_entropy_with_logits with named arguments (labels=..., logits=..., ...). Tensorflow 0.x, don't need named arguments

mazcallu commented 5 years ago

shouldn´t it be this instead? Labels are contained in y_ and logits are the output from the neural net

presence_loss = tf.nn.sigmoid_cross_entropy_with_logits(labels=y_[:, :1], logits= y[:, :1])
SJTUPanda commented 4 years ago

I think @mazcallu is right, thanks