luyishisi / Anti-Anti-Spider

越来越多的网站具有反爬虫特性,有的用图片隐藏关键数据,有的使用反人类的验证码,建立反反爬虫的代码仓库,通过与不同特性的网站做斗争(无恶意)提高技术。(欢迎提交难以采集的网站)(因工作原因,项目暂停)
https://www.urlteam.cn
7.28k stars 2.17k forks source link

实际项目中的验证码图片如何放入接口识别呢? #17

Open mengguiyouziyi opened 6 years ago

mengguiyouziyi commented 6 years ago

![Uploading image.png…]() if name == 'main':

text, image = gen_captcha_text_and_image()

text = '1dxz'
captcha = 'y.jpg'
image = Image.open(captcha)
# image.show()
image = np.array(image)
image = convert2gray(image)
image = image.flatten() / 255
predict_text = crack_captcha(image)
print("正确: {}  预测: {}".format(text, predict_text))

# train_crack_captcha_cnn()
# text, image = gen_captcha_text_and_image()
# image = convert2gray(image)  # 生成一张新图
# image = image.flatten() / 255  # 将图片一维化
# predict_text = crack_captcha(image)  # 导入模型识别
# print("正确: {}  预测: {}".format(text, predict_text))

报错: 验证码图像channel: (36, 70, 3) 验证码文本最长字符数 4 2017-11-28 22:35:53.116468: I tensorflow/core/platform/cpu_feature_guard.cc:137] Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA Traceback (most recent call last): File "/Users/menggui/Desktop/project/zhuanli_spider/cnipr/other_operate/test_2/tensorflow_cnn.py", line 229, in predict_text = crack_captcha(image) File "/Users/menggui/Desktop/project/zhuanli_spider/cnipr/other_operate/test_2/tensorflow_cnn.py", line 209, in crack_captcha text_list = sess.run(predict, feed_dict={X: [captcha_image], keep_prob: 1}) File "/Users/menggui/.pyenv/versions/env_comm_Ana3-4.3.0/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 889, in run run_metadata_ptr) File "/Users/menggui/.pyenv/versions/env_comm_Ana3-4.3.0/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1096, in _run % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape()))) ValueError: Cannot feed value of shape (1, 36, 70) for Tensor 'Placeholder:0', which has shape '(?, 9600)'

luyishisi commented 6 years ago

这是说明你给的验证码图片和训练的以及模型本身定义的图片大小不符合,建议是1:可以resize你要投入的图片,2:用你当前的图片重新打码训练模型

limbo-envoy commented 6 years ago

InvalidArgumentError (see above for traceback): Incompatible shapes: [38,378] vs. [64,378] [[Node: logistic_loss/mul = Mul[T=DT_FLOAT, _device="/job:localhost/replica:0/task:0/device:CPU:0"](Add_1, _arg_Placeholder_1_0_1)]] 我想用我当前图片进行验证码训练, 但是出现了这个错误无法训练,您能看看这个属于什么问题吗?我在网上搜了下,但是看得没有头绪

limbo-envoy commented 6 years ago

哦, 重新更改图片尺寸没有报错。