这个项目有好几年了,项目中使用的是 tensorflow1,现在主要 2 比较流行,但是 1 和 2 里面有很多方法都是不同的。
另外 M 芯片的 mac 很难跑起来,最好还是 win。
适用于无深度学习基础的朋友,只需要编写getimg.py相关路径即可
有问题可以提issue
有关于验证码生成可以看我这两篇文章:
用CNN识别验证码| python识别验证码| 训练验证码模型
License: Apache License 2.0
这个项目有好几年了,项目中使用的是 tensorflow1,现在主要 2 比较流行,但是 1 和 2 里面有很多方法都是不同的。
另外 M 芯片的 mac 很难跑起来,最好还是 win。
适用于无深度学习基础的朋友,只需要编写getimg.py相关路径即可
有问题可以提issue
有关于验证码生成可以看我这两篇文章:
验证的时候, 第二次请求就出现Original stack trace for 'save_1/RestoreV2' 这样的错误提示, 每次请求save_*就会+1, 如果是重新运行python文件, 就正常
尝试过在with tf.Session() as sess:下面增加sess.run(tf.compat.v1.global_variables_initializer()), 虽然这样是不报错了...但是只有第一次返回的是正确的验证码, 接下来都是错误的验证码...
初学者...希望能指点指点
import base64
import json
import os
import tensorflow.compat.v1 as tf
tf.disable_v2_behavior()
from cPython import cPython as cp
from train import cnn_graph
from PIL import Image
from process import vec2text,convert2gray,wrap_gen_captcha_text_and_image_test
from getimg import CAPTCHA_HEIGHT, CAPTCHA_WIDTH, CAPTCHA_LEN, CAPTCHA_LIST
import numpy as np
import random
# 验证码图片转化为文本
def captcha2text(image_list, height=CAPTCHA_HEIGHT, width=CAPTCHA_WIDTH):
x = tf.placeholder(tf.float32, [None, height * width])
keep_prob = tf.placeholder(tf.float32)
y_conv = cnn_graph(x, keep_prob, (height, width))
saver = tf.train.Saver()
with tf.Session() as sess:
saver.restore(sess, tf.train.latest_checkpoint('.'))
predict = tf.argmax(tf.reshape(y_conv, [-1, CAPTCHA_LEN, len(CAPTCHA_LIST)]), 2)
vector_list = sess.run(predict, feed_dict={x: image_list, keep_prob: 1})
vector_list = vector_list.tolist()
text_list = [vec2text(vector) for vector in vector_list]
return text_list
if __name__ == '__main__':
data = json.loads(cp.get_html('http://whois.chinaz.com/ajaxsync.aspx?at=vc&%s' % random.random()))
image = base64.b64decode(data['Img'].replace('data:image/jpeg;base64,', ''))
with open('temp.jpg', 'wb') as w:
w.write(image)
image_a = Image.open('temp.jpg')
img_array = np.array(image_a)
image = convert2gray(img_array)
image = image.flatten() / 255
pre_text = captcha2text([image])
print(pre_text)
data = json.loads(cp.get_html('http://whois.chinaz.com/ajaxsync.aspx?at=vc&%s' % random.random()))
image = base64.b64decode(data['Img'].replace('data:image/jpeg;base64,', ''))
with open('temp2.jpg', 'wb') as w:
w.write(image)
image_a = Image.open('temp2.jpg')
img_array = np.array(image_a)
image = convert2gray(img_array)
image = image.flatten() / 255
pre_text = captcha2text([image])
print(pre_text)
Traceback (most recent call last):
File "train.py", line 190, in
train()
File "train.py", line 171, in train
batch_x, batch_y = next_batch(64)
File "C:\Users\11967\desktop\cnnyzm\process.py", line 61, in next_batch
image_a = image[text.index(text_a)]
IndexError: list index out of range
?
问下如何才能支持不定长度
这种运算的能训练出来吗
我使用gui跑的1万数据集,很慢,而且acc一直都是0.1,这个是因为什么啊
Traceback (most recent call last):
File "/Users/vm/Documents/workspace/First/_20200927/cnnyzm/process.py", line 80, in <module>
x,y = next_batch(batch_count=1)
File "/Users/vm/Documents/workspace/First/_20200927/cnnyzm/process.py", line 69, in next_batch
image_a = image[text.index(text_a)]
IndexError: list index out of range
64
9965
XkOt.jp
8250
Traceback (most recent call last):
File "/Users/rember_i/学习/chinaunicom/train.py", line 214, in
train()
File "/Users/rember_i/学习/chinaunicom/train.py", line 182, in train
batch_x, batch_y = next_batch(64)
File "/Users/rember_i/学习/chinaunicom/process.py", line 70, in next_batch
batch_y[i, :] = text2vec(text_a)
File "/Users/rember_i/学习/chinaunicom/process.py", line 21, in text2vec
raise ValueError("验证码超过4位啦!")
ValueError: 验证码超过4位啦!
Traceback (most recent call last):
File "D:\Python\cnnyzm-master\train.py", line 185, in
train()
File "D:\Python\cnnyzm-master\train.py", line 166, in train
batch_x, batch_y = next_batch(7)
File "D:\Python\cnnyzm-master\process.py", line 58, in next_batch
image_a = image[text.index(text_a)]
IndexError: list index out of range
Process finished with exit code 1
demo1是什么啊
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.