ubuntu18.04 cpu版本 pytorch
1.配置环境选择python3.6版本进行配置,利用anaconda创建python=3.6的环境fcn,参考:https://github.com/wkentaro/pytorch-fcnhttps://github.com/wkentaro/pytorch-fcn
pytorch >= 0.2.0torchvision >= 0.1.8fcn >= 6.1.5Pillowscipytqdm 1.1 安装fcn包:
pip install fcn #pip install --default-timeout=100 -i https://pypi.tuna.tsinghua.edu.cn/simple fcn1.2 安装PyTorch:
进入PyTorch官网,下载cpu版本:
Start Locally | PyTorchhttps://pytorch.org/get-started/locally/
复制网页的命令,我的如下:
conda install pytorch torchvision torchaudio cpuonly -c pytorch #或者pip pip3 install torch==1.10.2+cpu torchvision==0.11.3+cpu torchaudio==0.10.2+cpu -f https://download.pytorch.org/whl/cpu/torch_stable.html
验证安装:
clash$ conda activate py36 (py36) clash$ python Python 3.6.13 |Anaconda, Inc.| (default, Jun 4 2021, 14:25:59) [GCC 7.5.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import torch >>> torch.cuda.is_available() False >>>1.3 安装pillow、scipy、tqdm
pip install pillow pip install scipy pip install tqdm1.4 验证环境配置
下载 https://github.com/wkentaro/pytorch-fcnhttps://github.com/wkentaro/pytorch-fcn 的代码并解压,pip install .后出现下面一堆successfully。
(py36) paper1$ cd pytorch-fcn-main/ (py36) pytorch-fcn-main$ pip install . ######安装torchfcn Processing /home/elfoot/paper1/pytorch-fcn-main Preparing metadata (setup.py) ... done -------------------------------- Requirement already satisfied: idna<4,>=2.5 in /home/elfoot/anaconda3/envs/py36/lib/python3.6/site-packages (from requests[socks]->gdown->fcn>=6.1.5->torchfcn==1.9.7) (3.3) Requirement already satisfied: PySocks!=1.5.7,>=1.5.6 in /home/elfoot/anaconda3/envs/py36/lib/python3.6/site-packages (from requests[socks]->gdown->fcn>=6.1.5->torchfcn==1.9.7) (1.7.1) Building wheels for collected packages: torchfcn Building wheel for torchfcn (setup.py) ... done Created wheel for torchfcn: filename=torchfcn-1.9.7-py3-none-any.whl size=137110 sha256=0e0a02e7459ab0c07e029ccefb4d80959a61ee28a9d4a052ea8574855f7c488f Stored in directory: /home/elfoot/.cache/pip/wheels/c9/60/99/c1bd09fc67e214cb878410d34a27c1a3ac13a0e4f22bddbadf Successfully built torchfcn Installing collected packages: torchfcn Successfully installed torchfcn-1.9.72.利用VOC数据集训练example
正在下载数据集-----很慢----不知有没有快的方法
运行xxx/paper1/pytorch-fcn-main/examples/voc/download_dataset.sh脚本下载数据集,脚本内容如下,主要下载两个内容,并把他们放到DIR目录处:
#!/bin/bash DIR=~/data/datasets/VOC mkdir -p $DIR cd $DIR if [ ! -e benchmark_RELEASE ]; then wget http://www.eecs.berkeley.edu/Research/Projects/CS/vision/grouping/semantic_contours/benchmark.tgz -O benchmark.tar tar -xvf benchmark.tar fi if [ ! -e VOCdevkit/VOC2012 ]; then wget http://host.robots.ox.ac.uk/pascal/VOC/voc2012/VOCtrainval_11-May-2012.tar tar -xvf VOCtrainval_11-May-2012.tar fi
关于直接在终端下载很慢,由于使用了科学上网,我直接把链接放到网页下载----贼快:
创建文件夹~/data/datasets/VOC,并把下载的文件分别解压到文件夹内:
接着如下图,分别将benchmark文件夹内的benchmark_RELEASE、VOCtrainval_11-May-2012内的VOCdevkit提到VOC目录中来。
2.2 配置git因为xxx/pytorch-fcn-main/examples/voc/train_fcn32s.py中提到了git log以及结合报错,如下,故先配置一下git
//xxx/pytorch-fcn-main/examples/voc/train_fcn32s.py截取
def git_hash():
cmd = 'git log -n 1 --pretty="%h"'
ret = subprocess.check_output(shlex.split(cmd)).strip()
if isinstance(ret, bytes):
ret = ret.decode()
return ret
先在自己的github创建一个repository,其链接为:https://github.com/menghxz/fcn-pytorch-cpu.git
在~/.bashrc配置科学上网(可能需要,现在还没弄清需不需要),格式参考如下
export HTTP_PROXY="http://127.0.0.1:7890" export HTTPS_PROXY="http://127.0.0.1:7890"
终端配置git:
cd /home/elfoot/paper1/pytorch-fcn-main/examples/voc git init git add README.md git commit -m "first commit" git branch -M main git remote add origin https://github.com/menghxz/fcn-pytorch-cpu.git #你的链接 git push -u origin main2.3 训练
终端进入voc目录,训练如下:
cd /home/elfoot/paper1/pytorch-fcn-main/examples/voc ./train_fcn32s.py参考链接:
Ubuntu18.04安装cpu版pytorch环境 - 简书https://www.jianshu.com/p/43f66c69baa7https://github.com/pytorch/pytorch#installationhttps://github.com/pytorch/pytorch#installation



