pytorch 小例子 demo 使用demo

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/github_36923418/article/details/81390361

我使用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.]]]])

猜你喜欢

转载自blog.csdn.net/github_36923418/article/details/81390361