Francis'Blog

加油!奋斗!奥里给!


  • Home

  • Categories

  • About

  • Archives

  • Search

基于TensorFlow的验证码识别

Posted on 2018-11-11 | In TensorFlow

这篇博客我们来用TensorFlow来实现一个验证码识别的深度学习模型,我们的。我们会先用标注好的数据来训练第一个模型,然后再用模型来实现验证码识别

验证码

我们先看下验证码是怎么样的, 我们使用Python的captcha库来生成验证码,再用pip安装好captcha之后,就可以用代码来生成一个简单的图形验证码了。

1
2
3
4
5
6
7
8
9
10
11
from captcha.image import ImageCaptcha
from PIL import Image
from matplotlib import pyplot as plt

text = '1234'
image = ImageCaptcha()
captcha = image.generate(text)
captcha_image = Image.open(captcha)

plt.figure()
plt.imshow(captcha_image)

运行代码,就可以看到这样的图片了:

Read more »

leetcode_3

Posted on 2018-11-10 | In LeetCode

[LeetCode: No.3]

Given a string, find the length of the longest substring without repeating characters.

题目大意:给出一个字符串,找到最长的没有重复字符的子字符串,并返回该子字符串的长度。

Examples:

Given "abcabcbb", the answer is "abc", which the length is 3.
Given "bbbbb", the answer is "b", with the length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.
解法一

粗暴的想法是利用循环嵌套对所有情况进行遍历。大体的思路是:第一层循环从字符串的最左侧到左右侧第二个,然后第二层循环从第一层紧跟着的一个到最后的字符串,之后比较长度得到最大长度的子字符串

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
def lengthOfLongestSubstring(self, s):
"""
:type s: str
:rtype: int
"""
max_len = 0 #用这个值记录我们要返回的最长子字符串长度
#当原字符串长度为0或1的特殊情况
if (len(s) == 1 or len(s) == 0):
max_len = len(s)
#开始遍历每一个子字符串,并进行长度比较,得到最长的那个
for i in range(0,len(s)-1):
for j in range(i+1, len(s)):
if s[j] in s[i:j]:
if j-i > max_len:
max_len = j - i
break
elif j == len(s) - 1:
#当j是最后一个字符时,需要加上一个单位
if max_len < j - i + 1:
max_len = j - i + 1
return max_len

这种解法虽然可以通过,但是效率很低,时间会很长

Read more »
1…1112
Francis Cheng

Francis Cheng

很惭愧,就做了一点微小的工作。

35 posts
14 categories
16 tags
© 2019 Francis Cheng
Powered by Hexo
Theme - NexT.Gemini