Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

楼主,请教 #38

Open
armstrong1972 opened this issue Oct 7, 2019 · 13 comments
Open

楼主,请教 #38

armstrong1972 opened this issue Oct 7, 2019 · 13 comments
Labels
调优 如何提高模型的精度

Comments

@armstrong1972
Copy link

我参考你的pytorch代码,改为读取图片,下载了350张验证码,100张做验证集,5张测试,其它的都训练。
Loss 0.001 : 250 epoch
Loss 0.0001 : 30 epoch

Train Loss =0.0021 , Acc = 0.9687 (比较满意)
但:
Valid Loss = 0.7251 , Acc = 0.4862 (50%不到)

pth保存后,又从train 和 valid 里各复制了几张到 Test 中做测试,共13张,对了7张。请问如何改进,能进一步提高 Acc

@ypwhs
Copy link
Owner

ypwhs commented Oct 7, 2019

增加数据量

@armstrong1972
Copy link
Author

感谢大佬指点。
我想50%的识别率,每2张中就能认出1张,还是可以用的。
我程序加了个小技巧:每次验证码都按时间戳做文件名存盘。凡是通过验证进入下一页面的,我就将文件名改为验证码。这样至少有一半的图片是自动打了标签的(手工打太累了)。
于是乎一上午又多了300多张可用的样板,重新学习后,识别率高达93%。

@ypwhs
Copy link
Owner

ypwhs commented Oct 8, 2019

凡是通过验证进入下一页面的,我就将文件名改为验证码。

这是非常好的思路。

@BerryRB
Copy link

BerryRB commented Oct 10, 2019

@armstrong1972 你好,请问应该如何修改读取自己的图片数据集呢?小白完全不懂该如何下手....

@armstrong1972
Copy link
Author

armstrong1972 commented Oct 10, 2019

@armstrong1972 你好,请问应该如何修改读取自己的图片数据集呢?小白完全不懂该如何下手....

修改 CaptchaDataset 类即可,给你个文件做参考
只要在主程序下,建2个子目录:
img/train 放train的图片
img/valid 放valid的图片

主程序内删除 CaptchaDataset 类所有代码,头部增加 :

from dset_files import CaptchaDataset

dset_files.zip

@BerryRB
Copy link

BerryRB commented Oct 10, 2019 via email

@armstrong1972
Copy link
Author

@Pinndanyi
Copy link

请问您是怎么实现保存验证码的?我目前是用selenium + chrome + pyautogui实现的,但是现在需要将chrome设为headless,那pyautogui的右键保存功能就不能用了。请问您有别的方法吗?

@armstrong1972
Copy link
Author

不要用 pyautogui ,selenium 本身就有存图片的功能

from selenium import webdriver
PATH_ChromeDriver = "chromedriver.exe"
drvChrome = webdriver.Chrome(PATH_ChromeDriver)

drvChrome.get(HOME_PAGE)
imgVC=drvChrome.find_element_by_id("id_of_captcha")
f_vcode = basepath + "/img/__temp.png"
with open(f_vcode,'wb') as fp:
    fp.write(imgVC.screenshot_as_png)

@Pinndanyi
Copy link

Pinndanyi commented Oct 16, 2019

很好用,非常感谢!因为变成120*30像素的png了,用作者的模型就报错了,

RuntimeError: Given groups=1, weight of size 32 3 3 3, expected input[128, 4, 30, 120] to have 3 channels, but got 4 channels instead

我想是因为jpg3个通道,png4个通道的缘故,但是不会改模型参数,劳请您再指教下!谢谢!

@armstrong1972
Copy link
Author

抱歉忘了提醒了,需要你去找个工具批量将他们改为 jpg 3通道文件。

@armstrong1972
Copy link
Author

armstrong1972 commented Oct 16, 2019

或者 :用程序读取4通道png,然后转成3通道

from PIL import Image
im = Image.open(im_path)
if im.shape[2] == 4:
      im =im.convert("RGB")

@ypwhs ypwhs added the 调优 如何提高模型的精度 label Nov 9, 2019
@tangbinchn
Copy link

或者 :用程序读取4通道png,然后转成3通道

from PIL import Image
im = Image.open(im_path)
if im.shape[2] == 4:
      im =im.convert("RGB")

您好,我在修改为读取图片测试时,遇到这样的问题:
RuntimeError: input.size(-1) must be equal to input_size. Expected 512, got 256
应该是输入尺寸的问题,但是我不清楚在哪里修改,劳烦指教一下,谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
调优 如何提高模型的精度
Projects
None yet
Development

No branches or pull requests

5 participants