1 Star 1 Fork 17

yangyin2020/pytorch-captcha-recognition

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
captcha_predict.py 1.29 KB
一键复制 编辑 原始数据 按行查看 历史
coolcooldee 提交于 2018-10-19 16:30 . not use visdom
# -*- coding: UTF-8 -*-
import numpy as np
import torch
from torch.autograd import Variable
#from visdom import Visdom # pip install Visdom
import captcha_setting
import my_dataset
from captcha_cnn_model import CNN
def main():
cnn = CNN()
cnn.eval()
cnn.load_state_dict(torch.load('model.pkl'))
print("load cnn net.")
predict_dataloader = my_dataset.get_predict_data_loader()
#vis = Visdom()
for i, (images, labels) in enumerate(predict_dataloader):
image = images
vimage = Variable(image)
predict_label = cnn(vimage)
c0 = captcha_setting.ALL_CHAR_SET[np.argmax(predict_label[0, 0:captcha_setting.ALL_CHAR_SET_LEN].data.numpy())]
c1 = captcha_setting.ALL_CHAR_SET[np.argmax(predict_label[0, captcha_setting.ALL_CHAR_SET_LEN:2 * captcha_setting.ALL_CHAR_SET_LEN].data.numpy())]
c2 = captcha_setting.ALL_CHAR_SET[np.argmax(predict_label[0, 2 * captcha_setting.ALL_CHAR_SET_LEN:3 * captcha_setting.ALL_CHAR_SET_LEN].data.numpy())]
c3 = captcha_setting.ALL_CHAR_SET[np.argmax(predict_label[0, 3 * captcha_setting.ALL_CHAR_SET_LEN:4 * captcha_setting.ALL_CHAR_SET_LEN].data.numpy())]
c = '%s%s%s%s' % (c0, c1, c2, c3)
print(c)
#vis.images(image, opts=dict(caption=c))
if __name__ == '__main__':
main()
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/yangyin2020/pytorch-captcha-recognition.git
[email protected]:yangyin2020/pytorch-captcha-recognition.git
yangyin2020
pytorch-captcha-recognition
pytorch-captcha-recognition
master

搜索帮助