网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
01月16日漏签0天
tensorflow吧 关注:4,242贴子:12,915
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 6回复贴,共1页
<<返回tensorflow吧
>0< 加载中...

tensorflow加载训练模型时出错

  • 只看楼主
  • 收藏

  • 回复
  • 蒙奇丶D丶杰
  • 中级粉丝
    2
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
求吧里大佬帮帮忙,看下


  • 蒙奇丶D丶杰
  • 中级粉丝
    2
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
E:\Python\Python36\python.exe E:/finalExam/recognize.py
2018-10-11 16:46:09.996829: W tensorflow/core/framework/op_kernel.cc:1273] OP_REQUIRES failed at save_restore_v2_ops.cc:184 : Out of range: Read fewer bytes than requested
Traceback (most recent call last):
File "E:\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1292, in _do_call
return fn(*args)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1277, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1367, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.OutOfRangeError: Read fewer bytes than requested
[[{{node save/RestoreV2}} = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "E:/finalExam/recognize.py", line 277, in <module>
predict_text = crack_captcha(image)
File "E:/finalExam/recognize.py", line 210, in crack_captcha
saver.restore(sess, "./crack_capcha.model-8710")
File "E:\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1538, in restore
{self.saver_def.filename_tensor_name: save_path})
File "E:\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 887, in run
run_metadata_ptr)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1110, in _run
feed_dict_tensor, options, run_metadata)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1286, in _do_run
run_metadata)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\client\session.py", line 1308, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.OutOfRangeError: Read fewer bytes than requested
[[{{node save/RestoreV2}} = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]
Caused by op 'save/RestoreV2', defined at:
File "E:/finalExam/recognize.py", line 277, in <module>
predict_text = crack_captcha(image)
File "E:/finalExam/recognize.py", line 208, in crack_captcha
saver = tf.train.Saver()
File "E:\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1094, in __init__
self.build()
File "E:\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1106, in build
self._build(self._filename, build_save=True, build_restore=True)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 1143, in _build
build_save=build_save, build_restore=build_restore)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 787, in _build_internal
restore_sequentially, reshape)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 406, in _AddRestoreOps
restore_sequentially)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\training\saver.py", line 854, in bulk_restore
return io_ops.restore_v2(filename_tensor, names, slices, dtypes)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\ops\gen_io_ops.py", line 1549, in restore_v2
shape_and_slices=shape_and_slices, dtypes=dtypes, name=name)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\framework\op_def_library.py", line 787, in _apply_op_helper
op_def=op_def)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\util\deprecation.py", line 488, in new_func
return func(*args, **kwargs)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 3272, in create_op
op_def=op_def)
File "E:\Python\Python36\lib\site-packages\tensorflow\python\framework\ops.py", line 1768, in __init__
self._traceback = tf_stack.extract_stack()
OutOfRangeError (see above for traceback): Read fewer bytes than requested
[[{{node save/RestoreV2}} = RestoreV2[dtypes=[DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT, DT_FLOAT], _device="/job:localhost/replica:0/task:0/device:CPU:0"](_arg_save/Const_0_0, save/RestoreV2/tensor_names, save/RestoreV2/shape_and_slices)]]
Process finished with exit code 1


2026-01-16 15:36:47
广告
不感兴趣
开通SVIP免广告
  • 蒙奇丶D丶杰
  • 中级粉丝
    2
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
代码在码云里
https://gitee.com/dali1997/finalExam.git


  • 蒙奇丶D丶杰
  • 中级粉丝
    2
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
顶一顶


  • 蒙奇丶D丶杰
  • 中级粉丝
    2
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
# 训练
def train_crack_captcha_cnn():
output = crack_captcha_cnn()
loss = tf.reduce_mean(tf.nn.sigmoid_cross_entropy_with_logits(logits=output, labels=Y))
optimizer = tf.train.AdamOptimizer(learning_rate=0.001).minimize(loss)
predict = tf.reshape(output, [-1, MAX_CAPTCHA, CHAR_SET_LEN])
max_idx_p = tf.argmax(predict, 2)
max_idx_l = tf.argmax(tf.reshape(Y, [-1, MAX_CAPTCHA, CHAR_SET_LEN]), 2)
correct_pred = tf.equal(max_idx_p, max_idx_l)
accuracy = tf.reduce_mean(tf.cast(correct_pred, tf.float32))
saver = tf.train.Saver()
with tf.Session() as sess:
sess.run(tf.global_variables_initializer())
step = 0
while True:
batch_x, batch_y = get_next_batch(64)
_, loss_ = sess.run([optimizer, loss], feed_dict={X: batch_x, Y: batch_y, keep_prob: 0.75})
print("训练次数:", step, "丢失率:", loss_)
# 每10 step计算一次准确率
if step % 10 == 0:
batch_x_test, batch_y_test = get_next_batch(100)
acc = sess.run(accuracy, feed_dict={X: batch_x_test, Y: batch_y_test, keep_prob: 1.})
print("训练次数:", step, "准确率:", acc)
# 如果准确率大于85%,保存模型,完成训练
if acc > 0.90:
saver.save(sess, "./model/crack_capcha.model", global_step=step)
# saver.save(sess, "./crack_capcha.model", global_step=step)
break
step += 1
# 测试
def crack_captcha(captcha_image):
output = crack_captcha_cnn()
saver = tf.train.Saver()
with tf.Session() as sess:
saver.restore(sess, "./crack_capcha.model-8710")
# saver.restore(sess, tf.train.latest_checkpoint('.'))
predict = tf.argmax(tf.reshape(output, [-1, MAX_CAPTCHA, CHAR_SET_LEN]), 2)
text_list = sess.run(predict, feed_dict={X: [captcha_image], keep_prob: 1})
text = text_list[0].tolist()
return text
if __name__ == '__main__':
train = 1
if train == 0:
number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z']
ALPHABET = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z']
text, image = gen_captcha_text_and_image()
print("验证码图像channel:", image.shape) # (60, 160, 3)
# 图像大小
IMAGE_HEIGHT = 60
IMAGE_WIDTH = 160
MAX_CAPTCHA = len(text)
print("验证码文本最长字符数", MAX_CAPTCHA)
# 文本转向量
char_set = number + alphabet + ALPHABET + ['_'] # 如果验证码长度小于4, '_'用来补齐
# char_set = number
CHAR_SET_LEN = len(char_set)
X = tf.placeholder(tf.float32, [None, IMAGE_HEIGHT * IMAGE_WIDTH])
Y = tf.placeholder(tf.float32, [None, MAX_CAPTCHA * CHAR_SET_LEN])
keep_prob = tf.placeholder(tf.float32) # dropout
train_crack_captcha_cnn()
if train == 1:
number = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
alphabet = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
'u', 'v', 'w', 'x', 'y', 'z']
ALPHABET = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z']
IMAGE_HEIGHT = 60
IMAGE_WIDTH = 160
char_set = number + alphabet + ALPHABET + ['_'] # 如果验证码长度小于4, '_'用来补齐
CHAR_SET_LEN = len(char_set)
text, image = gen_captcha_text_and_image()
f = plt.figure()
ax = f.add_subplot(111)
ax.text(0.1, 0.9, text, ha='center', va='center', transform=ax.transAxes)
plt.imshow(image)
plt.show()
MAX_CAPTCHA = len(text)
image = convert2gray(image)
image = image.flatten() / 255
X = tf.placeholder(tf.float32, [None, IMAGE_HEIGHT * IMAGE_WIDTH])
Y = tf.placeholder(tf.float32, [None, MAX_CAPTCHA * CHAR_SET_LEN])
keep_prob = tf.placeholder(tf.float32) # dropout
predict_text = crack_captcha(image)
print("正确: {} 预测: {}".format(text, predict_text))


  • 海沚风兰
  • 初级粉丝
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
解决了么?


  • 明20152014
  • 高级粉丝
    3
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
会不会是数组访问下标越界?


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 6回复贴,共1页
<<返回tensorflow吧
分享到:
©2026 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示