import numpy as np
import sys
import tensorflow as tf
import cv2
import os
import random
import time
# 验证码中的字符
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']
class Model(object):
def __init__(self,MAX_CAPTCHA,Is_alphabet,IMAGE_HEIGHT,IMAGE_WIDTH,model_path, train_image_path=None,valid_image_path=None):
self.model_path = model_path
self.train_path = train_image_path
self.valid_path = valid_image_path
self.MAX_CAPTCHA=MAX_CAPTCHA
self.char_set=self.get_char_set(Is_alphabet)
self.IMAGE_WIDTH=IMAGE_WIDTH
self.IMAGE_HEIGHT=IMAGE_HEIGHT
self.CHAR_SET_LEN=len(self.char_set)
self.X = tf.placeholder(tf.float32, [None, self.IMAGE_HEIGHT * self.IMAGE_WIDTH])
self.Y = tf.placeholder(tf.float32, [None, self.CHAR_SET_LEN])
self.keep_prob = tf.placeholder(tf.float32) # dropout
self.image_filename_list, self.total = self.get_image_file_name(self.train_path)
self.image_filename_list_valid, self.valid_total = self.get_image_file_name(self.valid_path)
self.output = self.crack_captcha_cnn()
#根据是否包含英文字母获取字符集.
def get_char_set(self,Is_alphabet):
char_set=[]
if(Is_alphabet==0):
char_set=number
else:
char_set=number+alphabet+ALPHABET
return char_set
def get_image_file_name(self,imgFilePath):
fileName = []
total = 0
for filePath in os.listdir(imgFilePath):
captcha_name = filePath.split('/')[-1]
fileName.append(captcha_name)
total += 1
random.seed(time.time())
random.shuffle(fileName)
return fileName, total
# 构建网络,定义cnn网络
def crack_captcha_cnn(self,w_alpha=0.01, b_alpha=0.1):
x = tf.reshape(self.X, shape=[-1, self.IMAGE_HEIGHT, self.IMAGE_WIDTH, 1])
w_c1 = tf.Variable(w_alpha * tf.random_normal([3, 3, 1, 32]))
w_c1 = tf.Variable(w_alpha * tf.random_normal([3, 3, 1, 32]))
b_c1 = tf.Variable(b_alpha * tf.random_normal([32]))
conv1 = tf.nn.relu(tf.nn.bias_add(tf.nn.conv2d(x, w_c1, strides=[1, 1, 1, 1], padding='SAME'), b_c1))
conv1 = tf.nn.max_pool(conv1, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
conv1 = tf.nn.dropout(conv1, self.keep_prob)
w_c2 = tf.Variable(w_alpha * tf.random_normal([3, 3, 32, 64]))
b_c2 = tf.Variable(b_alpha * tf.random_normal([64]))
conv2 = tf.nn.relu(tf.nn.bias_add(tf.nn.conv2d(conv1, w_c2, strides=[1, 1, 1, 1], padding='SAME'), b_c2))
conv2 = tf.nn.max_pool(conv2, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
conv2 = tf.nn.dropout(conv2, self.keep_prob)
w_c3 = tf.Variable(w_alpha * tf.random_normal([3, 3, 64, 64]))
b_c3 = tf.Variable(b_alpha * tf.random_normal([64]))
conv3 = tf.nn.relu(tf.nn.bias_add(tf.nn.conv2d(conv2, w_c3, strides=[1, 1, 1, 1], padding='SAME'), b_c3))
conv3 = tf.nn.max_pool(conv3, ksize=[1, 2, 2, 1], strides=[1, 2, 2, 1], padding='SAME')
conv3 = tf.nn.dropout(conv3, self.keep_prob)
w_d = tf.Variable(w_alpha * tf.random_normal([5 * 15 * 64, 1024]))
b_d = tf.Variable(b_alpha * tf.random_normal([1024]))
dense = tf.reshape(conv3, [-1, w_d.get_shape().as_list()[0]])
dense = tf.nn.relu(tf.add(tf.matmul(dense, w_d), b_d))
dense = tf.nn.dropout(dense, self.keep_prob)
w_out = tf.Variable(w_alpha * tf.random_normal([1024, self.CHAR_SET_LEN]))
b_out = tf.Variable(b_alpha * tf.random_normal([self.CHAR_SET_LEN]))
out = tf.add(tf.matmul(dense, w_out), b_out)
return out
def predict_builder(self):
self.sess = tf.Session()
saver = tf.train.Saver()
saver.restore(self.sess, tf.train.latest_checkpoint(self.model_path))
predict = tf.reshape(self.output, [-1, 1, self.CHAR_SET_LEN])
self.max_idx_p = tf.argmax(predict, 2)
pass
def predict_image_num(self, predict_image_path):
#print("predict_image_path"+predict_image_path)
result=""
if not os.path.isfile(predict_image_path):
print('file %s is not exist' % predict_image_path)
return
else:
result = self.get_result(self.sess, predict_image_path, self.max_idx_p)
return result
return
def predict_image(self, predict_image_path):
with tf.Session() as sess:
saver = tf.train.Saver()
saver.restore(sess, tf.train.latest_checkpoint(self.model_path))
predict = tf.reshape(self.output, [-1, 1, self.CHAR_SET_LEN])
max_idx_p = tf.argmax(predict, 2)
if not os.path.isdir(predict_image_path):
print("test_path is not dir")
return
while True:
image_name = input("input image name:")
image_path = os.path.join(predict_image_path, image_name)
image_path = image_path.replace('\\', '/')
print("file path: %s" % image_path)
if not os.path.isfile(image_path):
print('file %s is not exist' % image_path)
else:
result = self.get_result(sess, image_path, max_idx_p)
print(result)
def get_result(self, sess, predict_image_path, max_idx_p):
captcha_image = self.get_image(predict_image_path)
result = ""
for i in range(self.MAX_CAPTCHA):
batch_x_predict = captcha_image[i]
text_list = sess.run(max_idx_p, feed_dict={self.X: [batch_x_predict], self.keep_prob: 1})
text = text_list[0].tolist()
vector = np.zeros(self.CHAR_SET_LEN)
j = 0
for n in text:
vector[j * self.CHAR_SET_LEN + n] = 1
j += 1
predict_text = self.vec2text(vector)
result = result + predict_text
return result
def predict_folder(self,predict_image_folder_path):
predict_image_list=[]
true_list=[]
result_list=[]
for filePath in os.listdir(predict_image_folder_path):
true_list.append(filePath.split(".")[0])
predict_image_list.append(os.path.join(predict_image_folder_path,filePath))
saver = tf.train.Saver()
predict = tf.reshape(self.output, [-1, 1, self.CHAR_SET_LEN])
max_idx_p = tf.argmax(predict, 2)
with tf.Session() as sess:
for image_path in predict_image_list:
result=""
captcha_image=self.get_image(image_path)
for i in range(self.MAX_CAPTCHA):
saver.restore(sess, tf.train.latest_checkpoint(self.model_path))
batch_x_predict=captcha_image[i]
text_list = sess.run(max_idx_p, feed_dict={self.X: [batch_x_predict], self.keep_prob: 1})
text = text_list[0].tolist()
vector = np.zeros(self.CHAR_SET_LEN)
j = 0
for n in text:
vector[j * self.CHAR_SET_LEN + n] = 1
j += 1
predict_text= self.vec2text(vector)
result=result+predict_text
result_list.append(result)
return true_list,result_list
def gen_image_for_test(self,image_Path):
img = cv2.imread(image_Path,0)
img = cv2.resize(img, (self.IMAGE_WIDTH*self.MAX_CAPTCHA,self.IMAGE_HEIGHT))
img = np.float32(img)
return img
def get_image(self,im
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
【探索人工智能的宝藏之地】 无论您是计算机相关专业的在校学生、老师,还是企业界的探索者,这个项目都是为您量身打造的。无论您是初入此领域的小白,还是寻求更高层次进阶的资深人士,这里都有您需要的宝藏。不仅如此,它还可以作为毕设项目、课程设计、作业、甚至项目初期的立项演示。 【人工智能的深度探索】 人工智能——模拟人类智能的技术和理论,使其在计算机上展现出类似人类的思考、判断、决策、学习和交流能力。这不仅是一门技术,更是一种前沿的科学探索。 【实战项目与源码分享】 我们深入探讨了深度学习的基本原理、神经网络的应用、自然语言处理、语言模型、文本分类、信息检索等领域。更有深度学习、机器学习、自然语言处理和计算机视觉的实战项目源码,助您从理论走向实践,如果您已有一定基础,您可以基于这些源码进行修改和扩展,实现更多功能。 【期待与您同行】 我们真诚地邀请您下载并使用这些资源,与我们一起在人工智能的海洋中航行。同时,我们也期待与您的沟通交流,共同学习,共同进步。让我们在这个充满挑战和机遇的领域中共同探索未来!
资源推荐
资源详情
资源评论
收起资源包目录
人工智能项目资料-基于机器学习的登录验证码爆破工具.zip (1407个子文件)
all-wcprops 6KB
all-wcprops 3KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 2KB
all-wcprops 1KB
all-wcprops 1KB
all-wcprops 984B
all-wcprops 793B
all-wcprops 770B
all-wcprops 730B
all-wcprops 692B
all-wcprops 678B
all-wcprops 620B
all-wcprops 612B
all-wcprops 594B
all-wcprops 588B
all-wcprops 571B
all-wcprops 552B
all-wcprops 544B
all-wcprops 486B
all-wcprops 480B
all-wcprops 446B
all-wcprops 443B
all-wcprops 434B
all-wcprops 432B
all-wcprops 432B
all-wcprops 346B
all-wcprops 332B
all-wcprops 326B
all-wcprops 315B
all-wcprops 305B
all-wcprops 303B
all-wcprops 303B
all-wcprops 295B
all-wcprops 260B
all-wcprops 224B
all-wcprops 214B
all-wcprops 208B
all-wcprops 208B
all-wcprops 200B
all-wcprops 196B
all-wcprops 94B
all-wcprops 89B
all-wcprops 76B
checkpoint 103B
checkpoint 103B
summernote-bs3.css 143KB
bootstrap.min.css 118KB
bootstrap.min14ed.css 118KB
bootstrap.min.css 114KB
style.min.css 97KB
style.min862f.css 97KB
framework-theme.css 79KB
animate.min.css 46KB
datepicker3.css 33KB
simditor.css 27KB
framework-font.css 27KB
font-awesome.min93e3.css 26KB
ambiance.css 25KB
jquery-ui.min.css 25KB
style.min.css 25KB
jqgrid.css 18KB
sweetalert.css 18KB
simditor.css 17KB
ui.jqgridffe4.css 16KB
dialog.css 15KB
select2.min.css 14KB
jasny-bootstrap.min.css 14KB
chosen.css 12KB
dropzone.css 11KB
layer.css 11KB
layim.css 11KB
fullcalendar.css 11KB
summernote.css 10KB
plyr.css 10KB
framework-ui.css 9KB
codemirror.css 7KB
blueimp-gallery.min.css 7KB
awesome-bootstrap-checkbox.css 7KB
toastr.min.css 7KB
bootstrap-switch.css 6KB
laydate.css 6KB
webuploader-demo.min.css 6KB
wizard.css 6KB
laydate.css 6KB
jquery.steps.css 6KB
bootstrap-switch.min.css 5KB
tree.css 5KB
footable.core.css 5KB
datepicker.css 5KB
jquery.fancybox.css 5KB
datepicker.css 5KB
dataTables.bootstrap.css 5KB
framework-login.css 4KB
bootstrap-table.min.css 4KB
bootstrap-table.min.css 4KB
datepicker-dev.css 4KB
datepicker.css 4KB
共 1407 条
- 1
- 2
- 3
- 4
- 5
- 6
- 15
资源评论
妄北y
- 粉丝: 1w+
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 2023-04-06-项目笔记 - 第一百五十四阶段 - 4.4.2.152全局变量的作用域-152 -2024.06.04
- 松哥解协议松哥解协议松哥解协议松哥解协议松哥解协议
- 618节日618节日618节日
- tensorflow-gpu-2.9.1-cp37-cp37m-win-amd64.whl
- tensorflow-gpu-2.9.0-cp37-cp37m-win-amd64.whl
- tensorflow-gpu-2.9.0-cp39-cp39-win-amd64.whl
- lcd daimalcd daima
- 电影领域-推荐算法-个性化内容-观影决策-电影推荐小程序.zip
- 电气控制PLC考试题库
- 如何使用MATLAB简介
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功