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

关于单张图片inference的问题 #17

Open
yourlovedu opened this issue Apr 25, 2018 · 6 comments
Open

关于单张图片inference的问题 #17

yourlovedu opened this issue Apr 25, 2018 · 6 comments

Comments

@yourlovedu
Copy link

你好,我发现在使用infer.py时,输入图片的数量必须和BATCH_SIZE一样。
1)当BATCH_SIZE为40,我用如下代码预测时:
for img_pd in val_img:
val_predict = sess.run(pred_decode_result,feed_dict={image: np.array([img_pd])})
predit = cfg.int2label(np.argmax(val_predict, axis=2))
print(predit)
会出现这样的错误:ConcatOp : Dimensions of inputs should match: shape[0] = [40,326] vs. shape[1] = [1,256]
也就是输入图片的数量得和BATCH_SIZE一样。

2)当我把BATCH_SIZE改为2,我用如下代码预测时:
for img_pd in val_img:
val_predict = sess.run(pred_decode_result,feed_dict={image: np.array([img_pd,img_pd])})
predit = cfg.int2label(np.argmax(val_predict, axis=2))
print(predit)
虽然能输出结果,但是结果却是没那么准确的。

3)我把BATCH_SIZE改为1之后,在build_network时会报错:0 is not an invariant for the loop.
定位是tf.contrib.seq2seq.dynamic_decode这个函数里面出错了。
所以没办法通过更改BATCH_SIZE为1来实现单张图片预测。

那么,请问一下,如何进行单张图片的预测呢?
期待你的回复,谢谢!

@MatrixPlayer
Copy link

没看到解决方案,为什么closed掉了? issues#15也没有解决这问题啊

@MatrixPlayer
Copy link

@yourlovedu @wushilian

@wushilian
Copy link
Owner

@MatrixPlayer 暂时没有解决,单张图片预测由于bn的影响,准确度会下降

@zuokai
Copy link

zuokai commented Aug 8, 2018

@wushilian 我用你ctc的代码发现你没有保存bn的参数。。保存了就正常了

@yourlovedu
Copy link
Author

@zuokai 那该怎么保存呢

@zuokai
Copy link

zuokai commented Aug 10, 2018

@yourlovedu
update_ops = tf.get_collection(tf.GraphKeys.UPDATE_OPS)
with tf.control_dependencies(update_ops):
self.optimizer = tf.train.MomentumOptimizer(learning_rate=self.learning_rate, momentum=FLAGS.momentum, use_nesterov=True).minimize(self.cost,
global_step=self.global_step)

加前面两句话。或者你可以用tensorpack,框架自动帮你保存bn参数,比较方便。

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

4 participants