【前言】
【米尔-瑞芯微RK3576核心板及开发板】具有6TpsNPU以及GPU,因此是学习机器学习的好环境,为此结合《深度学习的数学——使用Python语言》
1、使用vscode 连接远程开发板
2、使用conda新建虚拟环境:
- root@myd-lr3576x-debian:/home/myir/pro_learn# conda create --name myenv python=3.9
- root@myd-lr3576x-debian:/home/myir/pro_learn# conda create --name myenv python=3.9
- Channels:
- - defaults
- Platform: linux-aarch64
- Collecting package metadata (repodata.json): done
- Solving environment: done
- ## Package Plan ##
- environment location: /root/miniconda3/envs/myenv
- added / updated specs:
- - python=3.9
- The following packages will be downloaded:
- package | build
- ---------------------------|-----------------
- _libgcc_mutex-0.1 | main 2 KB defaults
- _openmp_mutex-5.1 | 51_gnu 1.4 MB defaults
- ca-certificates-2024.11.26 | hd43f75c_0 131 KB defaults
- ld_impl_linux-aarch64-2.40 | h48e3ba3_0 848 KB defaults
- libffi-3.4.4 | h419075a_1 140 KB defaults
- libgcc-ng-11.2.0 | h1234567_1 1.3 MB defaults
- libgomp-11.2.0 | h1234567_1 466 KB defaults
- libstdcxx-ng-11.2.0 | h1234567_1 779 KB defaults
- ncurses-6.4 | h419075a_0 1.1 MB defaults
- openssl-3.0.15 | h998d150_0 5.2 MB defaults
- pip-24.2 | py39hd43f75c_0 2.2 MB defaults
- python-3.9.20 | h4bb2201_1 24.7 MB defaults
- readline-8.2 | h998d150_0 381 KB defaults
- setuptools-75.1.0 | py39hd43f75c_0 1.6 MB defaults
- sqlite-3.45.3 | h998d150_0 1.5 MB defaults
- tk-8.6.14 | h987d8db_0 3.5 MB defaults
- tzdata-2024b | h04d1e81_0 115 KB defaults
- wheel-0.44.0 | py39hd43f75c_0 111 KB defaults
- xz-5.4.6 | h998d150_1 662 KB defaults
- zlib-1.2.13 | h998d150_1 113 KB defaults
- ------------------------------------------------------------
- Total: 46.2 MB
- The following NEW packages will be INSTALLED:
- _libgcc_mutex anaconda/pkgs/main/linux-aarch64::_libgcc_mutex-0.1-main
- _openmp_mutex anaconda/pkgs/main/linux-aarch64::_openmp_mutex-5.1-51_gnu
- ca-certificates anaconda/pkgs/main/linux-aarch64::ca-certificates-2024.11.26-hd43f75c_0
- ld_impl_linux-aar~ anaconda/pkgs/main/linux-aarch64::ld_impl_linux-aarch64-2.40-h48e3ba3_0
- libffi anaconda/pkgs/main/linux-aarch64::libffi-3.4.4-h419075a_1
- libgcc-ng anaconda/pkgs/main/linux-aarch64::libgcc-ng-11.2.0-h1234567_1
- libgomp anaconda/pkgs/main/linux-aarch64::libgomp-11.2.0-h1234567_1
- libstdcxx-ng anaconda/pkgs/main/linux-aarch64::libstdcxx-ng-11.2.0-h1234567_1
- ncurses anaconda/pkgs/main/linux-aarch64::ncurses-6.4-h419075a_0
- openssl anaconda/pkgs/main/linux-aarch64::openssl-3.0.15-h998d150_0
- pip anaconda/pkgs/main/linux-aarch64::pip-24.2-py39hd43f75c_0
- python anaconda/pkgs/main/linux-aarch64::python-3.9.20-h4bb2201_1
- readline anaconda/pkgs/main/linux-aarch64::readline-8.2-h998d150_0
- setuptools anaconda/pkgs/main/linux-aarch64::setuptools-75.1.0-py39hd43f75c_0
- sqlite anaconda/pkgs/main/linux-aarch64::sqlite-3.45.3-h998d150_0
- tk anaconda/pkgs/main/linux-aarch64::tk-8.6.14-h987d8db_0
- tzdata anaconda/pkgs/main/noarch::tzdata-2024b-h04d1e81_0
- wheel anaconda/pkgs/main/linux-aarch64::wheel-0.44.0-py39hd43f75c_0
- xz anaconda/pkgs/main/linux-aarch64::xz-5.4.6-h998d150_1
- zlib anaconda/pkgs/main/linux-aarch64::zlib-1.2.13-h998d150_1
- Proceed ([y]/n)? y
- Downloading and Extracting Packages:
-
- Preparing transaction: done
- Verifying transaction: done
- Executing transaction: done
- #
- # To activate this environment, use
- #
- # $ conda activate myenv
- #
- # To deactivate an active environment, use
- #
- # $ conda deactivate
-
- root@myd-lr3576x-debian:/home/myir/pro_learn#
- root@myd-lr3576x-debian:/home/myir/pro_learn# conda activate myenv
- (myenv) root@myd-lr3576x-debian:/home/myir/pro_learn#
2、查看python版本号:
- (myenv) root@myd-lr3576x-debian:/home/myir/pro_learn# python --version
- Python 3.9.20
编写测试代码:
- import numpy as np
- from sklearn.datasets import load_digits
- from sklearn.neural_network import MLPClassifier
- d = load_digits()
- digits = d["data"]
- labels = d["target"]
- N = 200
- idx = np.argsort(np.random.random(len(labels)))
- xtest, ytest = digits[idx[:N]], labels[idx[:N]]
- xtrain, ytrain = digits[idx[N:]], labels[idx[N:]]
- clf = MLPClassifier(hidden_layer_sizes=(128, ))
- clf.fit(xtrain, ytrain)
- score = clf.score(xtest, ytest)
- pred = clf.predict(xtest)
- err = np.where(pred != ytest)[0]
- print("score:", score)
- print("err:", err)
- print("actual:", ytest[err])
- print("predicted:", pred[err])
【总结】
米尔的这款开发板,搭载3576这颗强大的芯片,搭建了深度学习的环境,进行了基础的数据集训练,效果非常好!在书中记录训练要几分钟,但是这在这款开发板上测试,只要几秒钟就训练完毕,书中说总体准确率为0.97,但是我在这款开发板上有0.99的良好效果!