最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

【2023 · CANN訓(xùn)練營(yíng)第一季】——環(huán)境搭建02(在ECS安裝Pytorch和Tensorflow框架)

2023-03-31 11:06 作者:CallMeDaYao-2022  | 我要投稿

前言:

????????在CANN訓(xùn)練營(yíng)提供的華為云鏡像環(huán)境,通過(guò)miniconda 安裝pytorch和Tensorflow框架。在模型遷移前準(zhǔn)備階段,可以用來(lái)在CPU上對(duì)模型訓(xùn)練進(jìn)行驗(yàn)證。

????????本文描述了安裝過(guò)程,更換國(guó)內(nèi)conda源、并分別下載例程,在Pytorch和Tensorflow框架下進(jìn)行了CPU訓(xùn)練。還介紹了在Pytorch、Tensorflow虛擬環(huán)境以及不啟動(dòng)虛擬環(huán)境之間切換的方法。

一、概要

參考文檔:https://www.hiascend.com/document/detail/zh/canncommercial/601/envdeployment/instg/instg_000034.html? ?安裝Tensorflow

https://www.hiascend.com/document/detail/zh/canncommercial/601/envdeployment/instg/instg_000035.html? ? 安裝PyTorch

????????訓(xùn)練營(yíng)鏡像已經(jīng)安裝好了CANN環(huán)境,只需要安裝深度學(xué)習(xí)框架Tensorflow和Pytorch。為了方便安裝和使用兩種框架,采取miniconda的方式進(jìn)行安裝,創(chuàng)建兩個(gè)虛擬環(huán)境,分別安裝這兩個(gè)框架。

? ? ? ? 安裝完成后,系統(tǒng)存在下述四種環(huán)境:無(wú)Conda環(huán)境;Pytorch環(huán)境;Tensorflow環(huán)境;Base環(huán)境。四種環(huán)境切換方式如下表所示:

二、安裝miniconda

1、下載miniconda

????????在官網(wǎng)查找合適的版本,根據(jù)昇騰官方建議的python版本,選擇3.7的版本進(jìn)行安裝。

mkdir downloads && cd downloads? ?#創(chuàng)建下載目錄

wget https://repo.anaconda.com/miniconda/Miniconda3-py37_23.1.0-1-Linux-x86_64.sh #下載miniconda

chmod +x Miniconda3-py37_23.1.0-1-Linux-x86_64.sh? ?#賦執(zhí)行權(quán)限

./Miniconda3-py37_23.1.0-1-Linux-x86_64.sh? #執(zhí)行安裝

按提示操作,默認(rèn)安裝到下述目錄:

安裝的最后,提示

????????此處選擇no,選擇yes,登錄后會(huì)自動(dòng)運(yùn)行conda的base環(huán)境。等需要使用時(shí),通過(guò)

conda activate 進(jìn)行切換。

修改為國(guó)內(nèi)conda源

vim ~/.condarc

#清華源

channels:??

- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/??

- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/??

- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/?

- https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

ssl_verify: true

也可以通過(guò)下述開(kāi)關(guān),進(jìn)行設(shè)置

conda config --set auto_activate_base false

三、安裝Pytorch 1.8

參考文檔:https://www.hiascend.com/document/detail/zh/canncommercial/601/envdeployment/instg/instg_000064.html

1、在miniconda 創(chuàng)建pytorch虛擬環(huán)境

創(chuàng)建pytorch1.8

conda create -n pt_1.8 python=3.7.5

切換到虛擬環(huán)境

conda activate pt_1.8

2、安裝PyTorch環(huán)境依賴

conda install pyyaml

conda?install wheel

3、安裝Pytorch

# CPU Only?

conda install pytorch==1.8.1 torchvision==0.9.1 torchaudio==0.8.1 cpuonly -c pytorch

????????安裝完成后,用conda list查看,有pytorch表示安裝成功。

????????也可以查看pytorch版本:

4、下載pytorch官方例程

地址:https://github.com/pytorch/examples

使用git clone命令下載例程。git clone https://github.com/pytorch/examples.git

5、跑一個(gè)CPU訓(xùn)練

????????選擇mnist例程,進(jìn)行cpu訓(xùn)練。

????(1)修改代碼

????? ? 例程綜合考慮了cpu、gpu、mac gpu下的訓(xùn)練,我們這里使用的是cpu訓(xùn)練,需要將gpu、mac gpu關(guān)閉,避免因?yàn)闄z查gpu、mac gpu而報(bào)錯(cuò)。

????????用Visual Studio Code修改訓(xùn)練腳本如下:

????????修改參數(shù),將訓(xùn)練好的模型落盤存儲(chǔ)

? ? (2)運(yùn)行訓(xùn)練腳本?? python main.py

????????訓(xùn)練完成,模型文件存儲(chǔ)到訓(xùn)練腳本目錄下。

四、安裝Tensorflow1.15

1、切換至base,創(chuàng)建tensorflow虛擬環(huán)境——conda activate base

2、安裝tensorflow 1.15 cpu版本

????????????conda install tensorflow=1.15.0

3、安裝驗(yàn)證

4、下載lenet例程

????????git clone https://gitee.com/qmckw/lenet.git

??????? 原始代碼直接運(yùn)行會(huì)報(bào)錯(cuò):ImportError: cannot import name ‘tutorials’ from ‘tensorflow_core.examples’,需要改一下代碼。

????????執(zhí)行訓(xùn)練 python Train.py


【2023 · CANN訓(xùn)練營(yíng)第一季】——環(huán)境搭建02(在ECS安裝Pytorch和Tensorflow框架)的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
响水县| 徐汇区| 东台市| 龙口市| 互助| 茂名市| 呈贡县| 个旧市| 饶河县| 齐齐哈尔市| 和林格尔县| 东山县| 济阳县| 朝阳区| 云梦县| 容城县| 宣威市| 北流市| 卓资县| 凯里市| 东明县| 龙海市| 邵阳县| 余姚市| 昆明市| 同心县| 苗栗县| 望都县| 湄潭县| 修文县| 故城县| 阿图什市| 金昌市| 湾仔区| 华蓥市| 合川市| 罗田县| 南召县| 博野县| 资阳市| 阿尔山市|