Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

生成的图片宽高改变CNN验证码训练报错 #15

Closed
xiefg opened this issue Oct 26, 2017 · 2 comments
Closed

生成的图片宽高改变CNN验证码训练报错 #15

xiefg opened this issue Oct 26, 2017 · 2 comments

Comments

@xiefg
Copy link

xiefg commented Oct 26, 2017

tensorflow_cnn 改变图片宽高,训练即失败,代码已定义常量IMAGE_HEIGHT、IMAGE_WIDTH,在此改变无法生效会报错,后面训练相关代码不会自适应图片宽高的改变
Traceback (most recent call last):
File "TensorFlow_cnn_train.py", line 197, in
train_crack_captcha_cnn()
File "TensorFlow_cnn_train.py", line 183, in train_crack_captcha_cnn
, loss = sess.run([optimizer, loss], feed_dict={X: batch_x, Y: batch_y, keep_prob: 0.75})
File "/Library/Python/2.7/site-packages/tensorflow/python/client/session.py", line 778, in run
run_metadata_ptr)
File "/Library/Python/2.7/site-packages/tensorflow/python/client/session.py", line 982, in _run
feed_dict_string, options, run_metadata)
File "/Library/Python/2.7/site-packages/tensorflow/python/client/session.py", line 1032, in _do_run
target_list, options, run_metadata)
File "/Library/Python/2.7/site-packages/tensorflow/python/client/session.py", line 1052, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Incompatible shapes: [26,315] vs. [64,315]
[[Node: logistic_loss/mul = Mul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Add_1, _recv_Placeholder_1_0)]]

Caused by op u'logistic_loss/mul', defined at:
File "TensorFlow_cnn_train.py", line 197, in
train_crack_captcha_cnn()
File "TensorFlow_cnn_train.py", line 165, in train_crack_captcha_cnn
loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=output, labels=Y))
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/nn_impl.py", line 171, in sigmoid_cross_entropy_with_logits
return math_ops.add(relu_logits - logits * labels,
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/math_ops.py", line 821, in binary_op_wrapper
return func(x, y, name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/math_ops.py", line 1044, in _mul_dispatch
return gen_math_ops._mul(x, y, name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/ops/gen_math_ops.py", line 1434, in _mul
result = _op_def_lib.apply_op("Mul", x=x, y=y, name=name)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/op_def_library.py", line 768, in apply_op
op_def=op_def)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 2336, in create_op
original_op=self._default_original_op, op_def=op_def)
File "/Library/Python/2.7/site-packages/tensorflow/python/framework/ops.py", line 1228, in init
self._traceback = _extract_stack()

InvalidArgumentError (see above for traceback): Incompatible shapes: [26,315] vs. [64,315]
[[Node: logistic_loss/mul = Mul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/cpu:0"](Add_1, _recv_Placeholder_1_0)]]

@luyishisi
Copy link
Owner

luyishisi commented Oct 27, 2017

图片的大小会影响模型中最终输出的shape 你需要在w_d = tf.Variable(w_alpha*tf.random_normal([8*20*64, 1024]))进行修改,,,这里的8和20 是由图片大小 计算而来 60/2/2/2 和 160/2/2/2所得。你也应该尝试修改

@xiefg
Copy link
Author

xiefg commented Oct 27, 2017

多谢,早上已经修正,确实是这个需要变更

@xiefg xiefg closed this as completed Oct 27, 2017
@xiefg xiefg reopened this Oct 27, 2017
@xiefg xiefg closed this as completed Oct 27, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants