pytorch 小例子 demo 使用demo
阿新 • • 發佈:2018-11-05
我使用anaconda3,建議大家也用這個,好用!!!
假設你安裝完了anaconda3.
一、建立一個測試Demo的實驗環境
conda create -n PyTorch-demo python=3.6
The following NEW packages will be INSTALLED: ca-certificates: 2018.03.07-0 certifi: 2018.4.16-py36_0 libcxx: 4.0.1-h579ed51_0 libcxxabi: 4.0.1-hebd6815_0 libedit: 3.1.20170329-hb402a30_2 libffi: 3.2.1-h475c297_4 ncurses: 6.1-h0a44026_0 openssl: 1.0.2o-h1de35cc_1 pip: 10.0.1-py36_0 python: 3.6.6-hc167b69_0 readline: 7.0-hc1231fa_4 setuptools: 39.2.0-py36_0 sqlite: 3.24.0-ha441bb4_0 tk: 8.6.7-h35a86e2_3 wheel: 0.31.1-py36_0 xz: 5.2.4-h1de35cc_4 zlib: 1.2.11-hf3cbc9b_2 Proceed ([y]/n)? y
二、安裝需要的一些環境,包括pytorch
啟用環境,並進入
source activate PyTorch-demo
給conda新增清華映象
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/
conda config --set show_channel_urls yes
安裝環境依賴
conda install numpy pyyaml mkl mkl-include setuptools cmake cffi typing pip install opencv-python matplotlib scikit-image tqdm tensorboardX
conda install pytorch-cpu torchvision-cpu -c pytorch
#for GPU
conda install pytorch torchvision cuda80 -c pytorch
三、測試pytorch
>>> import torch >>> x=torch.ones(1,1,6,6) >>> print(x) tensor([[[[1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.], [1., 1., 1., 1., 1., 1.]]]])