zoukankan      html  css  js  c++  java
  • centos 7 配置pytorch运行环境

    华为云服务器,4核心8G内存,没有显卡,性能算凑合,赶上双11才不到1000,性价比还可以,打算配置一套训练densenet的环境。

    首先自带的python版本是2.7,由于明年开始就不再维护了,所以安装了个conda。

    wget https://repo.continuum.io/archive/Anaconda3-5.3.0-Linux-x86_64.sh

    https://repo.anaconda.com/archive/Anaconda3-2020.02-Linux-x86_64.sh 2020-4-9 updated

    发现实在太慢,找了个清华的源,快了很多。

    wget  https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-4.3.0-Linux-x86_64.sh

    Anaconda3-5.3.1-MacOSX-x86_64.sh

    https://mirrors.tuna.tsinghua.edu.cn/anaconda/archive/Anaconda3-2020.02-Linux-x86_64.sh

    (这里4.3.0可以换成5.3.0,4.3.0的python版本好像是3.6 ,后面再安装pytorch和torchvision的时候可能还需要升级python版本)

    chmod 777 anaconda3.4.3.0-Linux-x86_64.sh

    ./anaconda3.4.3.0-Linux-x86_64.sh

    一直yes,安装好后,会提示是否加入系统变量中,点击yes,再执行命令 :source ~/.bachrc

    输入python --version 检查是否版本从2.7升级到3.6

    输入conda list,检查conda是否安装好

    然后安装pytorch和torchvision

    conda config --add channels https://repo.continuum.io/pkgs/free/ 
    conda config --add channels https://repo.continuum.io/pkgs/main/ 
    conda config --set show_channel_urls yes
    conda config --add channels https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/pytorch/

    conda install pytorch torchvision

    也可以conda install pytorch torchvision cudatoolkit=10.0.130,因为没有cuda显卡,所以不用带也没关系。

    也可以这样:conda install pytorch -c pytorch  

    conda install torchvision -c pytorch

    安装好以后,使用测试程序

    import torch
    train_on_gpu = torch.cuda.is_available()
    if not train_on_gpu:
    print('Training on CPU ...')
    else:
    print('Training on GPU ...')

    将数据集上传到服务器,开始训练。

    1:报了个lr_scheduler的错,升级一下pytorch和torchvision

    conda install pytorch==0.4.0

    conda upgrade torchvision

    2:报了个错,pytorch:ValueError: optimizing a parameter that doesn't require gradients

    但是这个错,同样在windows环境和centos7 + python 2.7两种环境下没有出现过。

    有两种解决办法,一个是将param.requires_grad = False ➡param.requires_grad = True,但是内存可能扛不住。

    还有一个办法是将optimizer = optim.Adadelta(model.parameters()) ➡ optimizer = optim.Adadelta(filter(lambda p: p.requires_grad,model.parameters()))

    推荐第二种方法,第一种方法由于求导数还慢占内存。

    3:报了个错:json.decoder.JSONDecodeError: Expecting property name enclosed in double quo

    好像是json文件最后多了个“,”号,排除这种错看log就搞定了。

  • 相关阅读:
    springboot 项目部署到服务器
    Thymeleaf的注意项
    springboot定时器
    springboot
    随笔
    mysql数据库连接超过8小时失效的解决方案(springboot)
    Druid连接池与spring配置
    IDEA快捷键
    jsonp解决跨域,用div,css,js,jq实现textarea自适应高度
    mysql的查询、子查询及连接查询(商城查询常用)
  • 原文地址:https://www.cnblogs.com/marszhw/p/11918815.html
Copyright © 2011-2022 走看看