用digists处理mnist步骤

本文介绍如何使用Digits平台训练CNN模型识别手写数字。文章详细记录了从下载MNIST数据集、创建数据集、训练LeNet-5模型到最终测试的全过程,并附带操作截图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

网上找了好多教程,发现还是原汁原味的好。我的digits是6.1.1版本的

文地址:https://github.com/NVIDIA/DIGITS/blob/v6.1.1/docs/GettingStarted.mdGetting Started

Now that you have successfully installed DIGITS, this guide will teach you the basics of how to use it.By the end, you will have trained a Caffe model to recognize hand-written digits.We will be using the MNIST handwritten digit database as our dataset and LeNet-5 for our network.Both are generously made available by Yann LeCun on his website.

Download the data

Use the following command to download the MNIST dataset onto your server:

$ python -m digits.download_data mnist ~/mnist
Downloading url=http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz ...
Downloading url=http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz ...
Downloading url=http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz ...
Downloading url=http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz ...
Uncompressing file=train-images-idx3-ubyte.gz ...
Uncompressing file=train-labels-idx1-ubyte.gz ...
Uncompressing file=t10k-images-idx3-ubyte.gz ...
Uncompressing file=t10k-labels-idx1-ubyte.gz ...
Reading labels from /home/username/mnist/train-labels.bin ...
Reading images from /home/username/mnist/train-images.bin ...
Reading labels from /home/username/mnist/test-labels.bin ...
Reading images from /home/username/mnist/test-images.bin ...
Dataset directory is created successfully at '/home/username/mnist'
Done after 16.722807169 seconds.

See Standard Datasets for details about this script.

Using the Webapp

Open up a web browser and navigate to the home screen of DIGITS.The server should be at either http://localhost/ (if installed from Deb packages), or http://localhost:5000/ (if using digits-devserver).

Home page

Logging in

Click on Datasets > New Dataset > Images > Classification.This will lead you to the login page:

NOTE: there is no authentication - you don't even need a password.This is a utility feature, not a security feature.

Login

Creating a Dataset

After logging in, you will be brought to the "New Image Classification Dataset" page.

  • Type in the path to the MNIST training images
    • You can also add the folder of MNIST test images as a "Separate validation images folder", if you like. Don't use the "test images" fields - test images are not used for anything in DIGITS yet.
  • Change the Image Type to Grayscale
  • Change the Image size to 28 x 28
  • Give the dataset a name
  • Click on the Create button

New dataset

在这个页面的左边,可以设置图片是彩色图片还是灰度图片,如果提供的原始图片大小不一致,还可用Resize Transformation功能转换成一致大小 。从页面中间可以看出,系统默认将训练图片中的25%取出来作为验证集(for validation)。

如果想把用来测试的图片,也生成lmdb, 则把“ separate test image folder" 这个选项选上。

全部设置好后,点击"create" 按钮,开始生成lmdb数据。


While the job is running, you should see the expected completion time on the right side:

注意左上角的Job Directory(工作目录),生成的lmdb文件就放在这个目录下面,大家最好打开这个目录去看看,看一下生成了些什么文件,了解一下运行原理。

在这个界面,我们还可以可视化查看训练和测试的图片,如下图:


Creating dataset

train.txt里面存放的是所有训练图片的列表清单,柱状图清晰地显示了10类样本各自的数量。点击" Explorer the db” 即可查看图片。

最后,点击最左上角“ DIGITS" 链接回到网站根目录。


When the job is finished, go back to the home page by clicking DIGITS in the top left hand part of the page.You should now see your dataset listed under the "Datasets" tab.

Home page with dataset

Training a Model

经过前面的操作,我们就把数据准备好了。

一、训练一个model

右击右边Models模块的” Images" 按钮 ,选择“classification"

在打开页面右下角可以看到,系统提供了一个caffe model,分别为LeNet, AlexNet, GoogLeNet, 如果使用这三个模型,则所有参数都已经设置好了,就不用再设置了。

Click on Models > New Model > Images > Classification.This will lead you to the "New Image Classification Model" page.

For this example, do the following:

  • Choose the "MNIST" dataset in the Select Dataset field
  • Choose the LeNet network in the Standard Networks tab
  • Give the model a name
  • Click on the Create button

New model

While training the model, you should see the expected completion time on the right side:

在训练过程页面,左上角显示了生成的配置文件名称 (放在job目录文件下,默认路径为:/usr/share/digits/digits/jobs/),运行过程中保存的caffemodel快照也保存在这个目录下面。

页面中间显示了训练和测试的数据信息,右面显示了训练所用的时间和gpu使用情况,下面就是一些实时化图表,可以看到训练阶段的loss, 测试阶段的loss和accuracy,相当方便,甚至还可以看到学习率的变化情况,吃惊吧!


Training model

模型训练好后,直接就可以在下面进行测试了。

二、测试新来的图片

将页面拖到最下面,选择Upload imager按钮,加载一幅测试图片。在 /home/username/mnist/test/ 下面有大量的测试图片,随便选一张就可以了。

也可以通过在Image URL方框里,输入一张网上的图片地址来进行测试。

加载好测试图片,在 Show visualizations and statistics 选择模式框上点上勾。

点击”Classify One" 按钮就可以开始测试了。

如果你不是对一张图片进行测试,而是一个测试集,则是在" Upload Image List"这个地方,选择测试图片的列表清单文件(如 val.txt)


To test the model, scroll to the bottom of the page.

  • Click on the Upload image button and choose a file
    • There are plenty to choose from in /home/username/mnist/test/
  • Or, find an image on the web and paste the URL into the Image URL field
  • Check the Show visualizations and statistics box
  • Click on Classify One

At the top of the page, DIGITS displays the top five classifications and corresponding confidence values.DIGITS also provides visualizations and statistics about the weights and activations of each layer in your network.

系统会弹出一个新的页面,显示top-5的分类情况 ,同时digits还提供了测试数据与权值的可视化和统计信息。


Classified one image


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值