Skip to main content

HyperAI Identify handwritten digits below

If you understand machine learning. Especially the popular deep learning methods in recent years. So you've probably heard of it MNIST This dataset. This dataset is from the National Institute of Standards and Technology in the United States (National Institute of Standards and Technology, abbreviation NIST). Training set (training set)From 250 Composed of handwritten numbers by different individuals. Test set (test set)It is also handwritten digit data with the same proportion.

We will use this dataset here to introduce HyperAI Medium adoption PyTorch / TensorFlow Classify images. Among them, it will be used HyperAI Binding of datasets. Training and use of models.

PyTorch

Get code

from GitHub Download sample code:

git clone https://github.com/signcl/hyperai-mnist-example.git
cd HyperAI-mnist-example/pytorch

Switch to the downloaded code directory and see the following code structure:

.
├── HyperAI.yaml
└── train.py

among,

  1. .py Contains code for training machine learning models and using models for inference
  2. HyperAI.yaml Including the execution of one "Submit task" The configuration. For more information, please refer to HyperAI cli configuration file

Create the first task

be careful

This introduces the process of uploading code compression files through the page, howeverThis is no longer the creation we recommended "Submit task" The Best Practice, A better way is to refer to bayes Introduction to Command Line Tools.

After the dataset is ready, click on the left navigation bar on the page "Create a new computing power container" Create a task, use train.py Train one Pytorch The handwriting recognition model.

stay "Create a new container" Select the access method on the page Python Script execution. And put it in the directory train.py upload. Enter the command at the command execution location:

python train.py

train.py The analysis of the middle parameters adopts Python Built in libraries argparse Process it. For more content, please refer to argparse — Parser for command-line options, arguments and sub-commands.

Computing power selection CPU (If there are any other GPU type. Recommended choices GPU type. The speed will be much faster), Then select the image "pytorch-1.8" ,

Wait after submitting the task 15 The task will start executing in about seconds. On the container page, you can see the execution status displayed in the log.

TensorFlow

Get code

from GitHub Download sample code:

git clone https://github.com/signcl/hyperai-mnist-example.git
cd HyperAI-mnist-example/tensorflow

Switch to the downloaded code directory and see the following code structure:

.
├── inference.py
├── HyperAI.yaml
└── train.py

among,

  1. .py Contains code for training machine learning models and using models for inference
  2. HyperAI.yaml Including the execution of one "Python script" The configuration. For more information, please refer to HyperAI cli configuration file

Create the first task

be careful

This article introduces the process of uploading code compression files through a webpage.however. This is no longer the creation we recommended "Python script" The Best Practices. For a better method, please refer to bayes Introduction to Command Line Tools.

After the dataset is ready. Click on the left navigation bar on the page "Create a new computing power container" Create a Python Script execution tasks, use train.py Train one TensorFlow The handwriting recognition model.

stay "Create a new container" Select under the page "Submit task" Enter the command at the command execution location:

python train.py -o /hyperai/home -e 50 -m model.h5 -l ./tf_dir

among:

  1. train.py For model training purposes py file
  2. -o /hyperai/home to specify Gear The directory of the file to be saved is /hyperai/home, stay Python In script execution mode. Gear Will be /hyperai/home Save and upload the results in the directory. Therefore, all working directory results should be saved in that directory, Under other directories. Even including default settings . Updates to files in the directory will not be saved
  3. -e 50 Designated model training epoch value
  4. -m model.h5 The name of the saved model indicated. Of course, combined -o /hyperai/home parameter. The final training model will be stored in /hyperai/home/model.h5 lower
  5. -l ./tf_dir default ./tf_dir point HyperAI take TensorBoard The directory

train.py The analysis of the middle parameters adopts Python Built in libraries argparse Process it. For more content, please refer to argparse — Parser for command-line options, arguments and sub-commands.

Next step in computing power selection CPU. Mirror selection "tensorflow-2.8", Selection of access method "Submit task" , And put it in the directory train.py File upload.

Wait after submitting the task 15 The task will start executing in about seconds. The start time of the task is usually related to the size of the bound dataset. The larger the required dataset. The longer the preparation time for container execution. On the container page, you can see the execution status displayed in the log.

click "TensorBoard visualization" Can be done through TensorBoard View model information during execution.

View the directory of execution and output results

After completion of execution. Click on the container page "working directory" The tab shows that the model we specified has been created.

Classify using a trained model

After obtaining the training model. We can use it to classify and estimate the data. Click on the top right corner of the completed execution page "Continue to execute" , Enter a new execution build page.

Here is the previous one "working directory" The binding points to /hyperai/home. More about "Continue to execute" See details for details [Continuation of Container Execution](/docs/gear/#Continue to execute).

Modify the specified execution command:

python inference.py -m /hyperai/home/model.h5

among -m /hyperai/home/model.h5 Specify the directory of the model to be loaded. After submission and execution. It can be seen from the log that the 10000 The test results have been obtained 98% Accuracy rate.