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

【讨论】使用自制数字图像测试模型精度 #7

Open
leewishyuanfang opened this issue May 18, 2019 · 6 comments
Open

【讨论】使用自制数字图像测试模型精度 #7

leewishyuanfang opened this issue May 18, 2019 · 6 comments

Comments

@leewishyuanfang
Copy link
Contributor

在本次试验中,一共收集了19个人的手写数字笔迹,共190副图片。
为批量对这些图片进行处理,对图片处理的make_your_mnist.py代码进行了一定修改,具体修改如下:
# -- coding: utf-8 --

"""
Make mnist data set.
Ensure that the PIL module is installed before using the code below.
"""
from PIL import Image
cache = '../data/mnist_data/image/'
# 从image文件夹中依次读取数字图片并进行转换
# 本次一共收集到了19个人的0-9的数字笔迹,所以转换图片共10*19=190张
for i in range(0,9):
for j in range(1,19):
# 源图像
sr = (cache+'source/%d-%d.jpg' % (i,j))
# 目标图像
tg = (cache+'target/%d-%d.jpg' % (i,j))
I = Image.open(sr)
# 转换大小 为 28 * 28
I = I.resize((28, 28))
# 图像黑白化
L = I.convert('L')
# 保存转换后的图像
L.save(tg)

最后,得到190张处理后的,黑白化的28*28大小的数字图像

@leewishyuanfang
Copy link
Contributor Author

leewishyuanfang commented May 18, 2019

接下来,需要通过这些自制数字图像来检测模型的精度。
这次测试,我是通过modelarts的批量服务来进行的,具体操作如下:

  1. 通过OBS工具批量上传自制数字图像文件
    初次使用OBS工具,需要输入华为云的账号以及access key,如下所示:

1
登陆成功后,就可以对自己账户的桶和文件夹进行管理。
在mnist桶中,我们新建一个文件夹test_image,并将自制数字图像文件批量上传到该文件夹下
2

  1. 部署并运行新的批量服务
    我们登录华为云,进入到ModelArts管理控制台中,在左侧的部署上线中选择批量服务,如下图所示:
    3
    然后,点击“部署”,开始创建新的批量服务
    4
    之后,点击“立即创建”按钮,就可以等待批量服务运行完毕了(部署后,批量服务会自动运行)
    5
    这里需要提醒一点的是,批量服务的运行无需开启在线服务,只需要模型已经训练好就可以了
    批量服务运行结束后,就可以通过输出数据来检测模型的精度了
  2. 下载输出数据
    在OBS工具中打开输出数据目录,可以看到对于每张数字图像,均生成了一个识别结果文件。
    6
    将这些结果文件下载回本地,打开,就可以看到最后的识别结果
    7
    通过统计分析,190张图像中,成功识别的图像只有18张,正确率不到1成。
    这也就证明了训练时只使用一层神经网络,达不到很好的训练效果。接下来,可以尝试使用卷积神经网络来训练模型并再次测试训练效果。
    最后,附上本次实验使用到的自制手写数字图像文件。
    手写数字(个人收集).zip
    转换后的数字图片.zip

@chenliang613
Copy link
Collaborator

@leewishyuanfang great sharing!

@leewishyuanfang
Copy link
Contributor Author

在上一步骤中出现了一个错误,就是测试时错误地使用了没有经过转换的手写数字图片,经改正后,实际190张图像中,成功识别的图像有53张,正确率0.327。

@wonleing
Copy link
Contributor

会不会是因为训练模型里的数字书写与你上传的书写差距过大。之前的训练应该还是比较狭窄吧

@wonleing
Copy link
Contributor

image
我手写了几个数字,基本没有预测对了(我已经写的很认真了)。能给个链接下载几张训练时用的数字图片吗,看看差距到底有多大。

@leewishyuanfang
Copy link
Contributor Author

leewishyuanfang commented May 18, 2019

我提取了训练文件中的20张数字图像,成功率要高不少,感觉主要的区别在于训练图像的数字字体要粗一些
训练图像提取.zip
测试用图像提取.zip

@chenliang613 chenliang613 changed the title 实践2:使用自制数字图像测试模型精度 【讨论】实践2:使用自制数字图像测试模型精度 Jun 4, 2019
@chenliang613 chenliang613 changed the title 【讨论】实践2:使用自制数字图像测试模型精度 【讨论】使用自制数字图像测试模型精度 Jun 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants