《深度学习的数学——使用Python语言》1、搭建舞台
[复制链接]
手上有:【米尔-瑞芯微RK3576核心板及开发板】具有6TpsNPU以及GPU,因此是学习机器学习的好环境,为此结合《深度学习的数学——使用Python语言》进行环境搭建
1、使用vscode 远程连接开发板:
2、使用conda新建虚拟环境:
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
虽然书上说要对应3.9.2,希望不会有问题。
3、使用conda install numpy等来安装组件,安装好后用pip list查看:
4、编写测试程序
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])
【训练测试】
训练4次后就可以达到0.99,速度非常快:
【总结】
拿到书后,在RK3576上进行环境搭建,并成功的训练后数据集。
|