实例
数据集
笔记本
笔记本
Homework_MMSegmentation
暂无摘要
笔记本内容
# 安装 Pytorch
!pip3 install install torch==1.10.1+cu113 torchvision==0.11.2+cu113 torchaudio==0.10.1+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Looking in links: https://download.pytorch.org/whl/cu113/torch_stable.html Collecting install Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4d/c8/8cbca135f9e167810756ea2bc34b028501936675fcbd7dadccf752fa4622/install-1.3.5-py3-none-any.whl (3.2 kB) Collecting torch==1.10.1+cu113 Downloading https://download.pytorch.org/whl/cu113/torch-1.10.1%2Bcu113-cp37-cp37m-linux_x86_64.whl (1821.5 MB) [K |█████████████████████▌ | 1226.9 MB 93.6 MB/s eta 0:00:07 | | 3.5 MB 33.3 MB/s eta 0:00:55 |██▎ | 128.3 MB 85.3 MB/s eta 0:00:20 |███▌ | 199.6 MB 80.7 MB/s eta 0:00:21 |████▏ | 235.2 MB 80.7 MB/s eta 0:00:20 |████▍ | 248.6 MB 80.7 MB/s eta 0:00:20
IOPub data rate exceeded. The Jupyter server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--ServerApp.iopub_data_rate_limit`. Current values: ServerApp.iopub_data_rate_limit=1000000.0 (bytes/sec) ServerApp.rate_limit_window=3.0 (secs)
[K |██████████████████████████▌ | 1510.4 MB 89.5 MB/s eta 0:00:04
IOPub data rate exceeded. The Jupyter server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--ServerApp.iopub_data_rate_limit`. Current values: ServerApp.iopub_data_rate_limit=1000000.0 (bytes/sec) ServerApp.rate_limit_window=3.0 (secs)
[K |███████████████████████████████▊| 1802.9 MB 88.8 MB/s eta 0:00:01
IOPub data rate exceeded. The Jupyter server will temporarily stop sending output to the client in order to avoid crashing it. To change this limit, set the config variable `--ServerApp.iopub_data_rate_limit`. Current values: ServerApp.iopub_data_rate_limit=1000000.0 (bytes/sec) ServerApp.rate_limit_window=3.0 (secs)
[?25hCollecting torchvision==0.11.2+cu113 Downloading https://download.pytorch.org/whl/cu113/torchvision-0.11.2%2Bcu113-cp37-cp37m-linux_x86_64.whl (24.6 MB) [K |████████████████████████████████| 24.6 MB 62.6 MB/s eta 0:00:01 [?25hCollecting torchaudio==0.10.1+cu113 Downloading https://download.pytorch.org/whl/cu113/torchaudio-0.10.1%2Bcu113-cp37-cp37m-linux_x86_64.whl (2.9 MB) [K |████████████████████████████████| 2.9 MB 60.7 MB/s eta 0:00:01 [?25hRequirement already satisfied: typing-extensions in /environment/miniconda3/lib/python3.7/site-packages (from torch==1.10.1+cu113) (4.0.1) Requirement already satisfied: pillow!=8.3.0,>=5.3.0 in /environment/miniconda3/lib/python3.7/site-packages (from torchvision==0.11.2+cu113) (8.4.0) Requirement already satisfied: numpy in /environment/miniconda3/lib/python3.7/site-packages (from torchvision==0.11.2+cu113) (1.21.4) Installing collected packages: torch, torchvision, torchaudio, install Attempting uninstall: torch Found existing installation: torch 1.10.0+cu113 Uninstalling torch-1.10.0+cu113: Successfully uninstalled torch-1.10.0+cu113 Attempting uninstall: torchvision Found existing installation: torchvision 0.11.1+cu113 Uninstalling torchvision-0.11.1+cu113: Successfully uninstalled torchvision-0.11.1+cu113 Attempting uninstall: torchaudio Found existing installation: torchaudio 0.10.0+cu113 Uninstalling torchaudio-0.10.0+cu113: Successfully uninstalled torchaudio-0.10.0+cu113 Successfully installed install-1.3.5 torch-1.10.1+cu113 torchaudio-0.10.1+cu113 torchvision-0.11.2+cu113
# 安装 MMCV
!pip install -U openmim
!mim install mmengine
!mim install 'mmcv==2.0.0rc4'
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Collecting openmim Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b9/19/f7436e610163f65ff83de5a768180e73765e54bdaee5f5f37983aa3171b9/openmim-0.3.7-py2.py3-none-any.whl (51 kB) [K |████████████████████████████████| 51 kB 4.5 MB/s eta 0:00:01 [?25hRequirement already satisfied: colorama in /environment/miniconda3/lib/python3.7/site-packages (from openmim) (0.4.4) Collecting model-index Downloading https://pypi.tuna.tsinghua.edu.cn/packages/0f/a6/4d4cbbef704f186d143e2859296a610a355992e4eae71582bd598093b36a/model_index-0.1.11-py3-none-any.whl (34 kB) Requirement already satisfied: tabulate in /environment/miniconda3/lib/python3.7/site-packages (from openmim) (0.8.7) Requirement already satisfied: requests in /environment/miniconda3/lib/python3.7/site-packages (from openmim) (2.24.0) Requirement already satisfied: pip>=19.3 in /environment/miniconda3/lib/python3.7/site-packages (from openmim) (21.1.3) Collecting rich Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fc/1e/482e5eec0b89b593e81d78f819a9412849814e22225842b598908e7ac560/rich-13.4.2-py3-none-any.whl (239 kB) [K |████████████████████████████████| 239 kB 73.8 MB/s eta 0:00:01 [?25hRequirement already satisfied: pandas in /environment/miniconda3/lib/python3.7/site-packages (from openmim) (1.3.4) Requirement already satisfied: Click in /environment/miniconda3/lib/python3.7/site-packages (from openmim) (7.1.2) Requirement already satisfied: pyyaml in /environment/miniconda3/lib/python3.7/site-packages (from model-index->openmim) (6.0) Collecting ordered-set Downloading https://pypi.tuna.tsinghua.edu.cn/packages/33/55/af02708f230eb77084a299d7b08175cff006dea4f2721074b92cdb0296c0/ordered_set-4.1.0-py3-none-any.whl (7.6 kB) Requirement already satisfied: markdown in /environment/miniconda3/lib/python3.7/site-packages (from model-index->openmim) (3.3.6) Requirement already satisfied: importlib-metadata>=4.4 in /environment/miniconda3/lib/python3.7/site-packages (from markdown->model-index->openmim) (4.8.2) Requirement already satisfied: zipp>=0.5 in /environment/miniconda3/lib/python3.7/site-packages (from importlib-metadata>=4.4->markdown->model-index->openmim) (3.6.0) Requirement already satisfied: typing-extensions>=3.6.4 in /environment/miniconda3/lib/python3.7/site-packages (from importlib-metadata>=4.4->markdown->model-index->openmim) (4.0.1) Requirement already satisfied: numpy>=1.17.3 in /environment/miniconda3/lib/python3.7/site-packages (from pandas->openmim) (1.21.4) Requirement already satisfied: python-dateutil>=2.7.3 in /environment/miniconda3/lib/python3.7/site-packages (from pandas->openmim) (2.8.2) Requirement already satisfied: pytz>=2017.3 in /environment/miniconda3/lib/python3.7/site-packages (from pandas->openmim) (2021.3) Requirement already satisfied: six>=1.5 in /environment/miniconda3/lib/python3.7/site-packages (from python-dateutil>=2.7.3->pandas->openmim) (1.16.0) Requirement already satisfied: certifi>=2017.4.17 in /environment/miniconda3/lib/python3.7/site-packages (from requests->openmim) (2021.5.30) Requirement already satisfied: chardet<4,>=3.0.2 in /environment/miniconda3/lib/python3.7/site-packages (from requests->openmim) (3.0.4) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /environment/miniconda3/lib/python3.7/site-packages (from requests->openmim) (1.25.11) Requirement already satisfied: idna<3,>=2.5 in /environment/miniconda3/lib/python3.7/site-packages (from requests->openmim) (2.10) Collecting markdown-it-py>=2.2.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bf/25/2d88e8feee8e055d015343f9b86e370a1ccbec546f2865c98397aaef24af/markdown_it_py-2.2.0-py3-none-any.whl (84 kB) [K |████████████████████████████████| 84 kB 50.6 MB/s eta 0:00:01 [?25hCollecting pygments<3.0.0,>=2.13.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/34/a7/37c8d68532ba71549db4212cb036dbd6161b40e463aba336770e80c72f84/Pygments-2.15.1-py3-none-any.whl (1.1 MB) [K |████████████████████████████████| 1.1 MB 72.0 MB/s eta 0:00:01 [?25hCollecting mdurl~=0.1 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl (10.0 kB) Installing collected packages: mdurl, pygments, ordered-set, markdown-it-py, rich, model-index, openmim Attempting uninstall: pygments Found existing installation: Pygments 2.10.0 Uninstalling Pygments-2.10.0: Successfully uninstalled Pygments-2.10.0 Successfully installed markdown-it-py-2.2.0 mdurl-0.1.2 model-index-0.1.11 openmim-0.3.7 ordered-set-4.1.0 pygments-2.15.1 rich-13.4.2 Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Looking in links: https://download.openmmlab.com/mmcv/dist/cu113/torch1.10.0/index.html Collecting mmengine Downloading https://pypi.tuna.tsinghua.edu.cn/packages/11/f4/714c5fa78885c459a4d75957764367c195c937b56f5325898ea514c5a04e/mmengine-0.7.4-py3-none-any.whl (374 kB) [K |████████████████████████████████| 374 kB 50.1 MB/s eta 0:00:01 [?25hRequirement already satisfied: opencv-python>=3 in /environment/miniconda3/lib/python3.7/site-packages (from mmengine) (4.5.4.60) Requirement already satisfied: pyyaml in /environment/miniconda3/lib/python3.7/site-packages (from mmengine) (6.0) Requirement already satisfied: termcolor in /environment/miniconda3/lib/python3.7/site-packages (from mmengine) (1.1.0) Requirement already satisfied: numpy in /environment/miniconda3/lib/python3.7/site-packages (from mmengine) (1.21.4) Requirement already satisfied: matplotlib in /environment/miniconda3/lib/python3.7/site-packages (from mmengine) (3.5.0) Requirement already satisfied: rich in /environment/miniconda3/lib/python3.7/site-packages (from mmengine) (13.4.2) Collecting addict Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6a/00/b08f23b7d7e1e14ce01419a467b583edbb93c6cdb8654e54a9cc579cd61f/addict-2.4.0-py3-none-any.whl (3.8 kB) Requirement already satisfied: yapf in /environment/miniconda3/lib/python3.7/site-packages (from mmengine) (0.31.0) Requirement already satisfied: pyparsing>=2.2.1 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine) (3.0.6) Requirement already satisfied: kiwisolver>=1.0.1 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine) (1.3.2) Requirement already satisfied: pillow>=6.2.0 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine) (8.4.0) Requirement already satisfied: packaging>=20.0 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine) (21.3) Requirement already satisfied: python-dateutil>=2.7 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine) (2.8.2) Requirement already satisfied: fonttools>=4.22.0 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine) (4.28.3) Requirement already satisfied: cycler>=0.10 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine) (0.11.0) Requirement already satisfied: setuptools-scm>=4 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine) (6.3.2) Requirement already satisfied: six>=1.5 in /environment/miniconda3/lib/python3.7/site-packages (from python-dateutil>=2.7->matplotlib->mmengine) (1.16.0) Requirement already satisfied: setuptools in /environment/miniconda3/lib/python3.7/site-packages (from setuptools-scm>=4->matplotlib->mmengine) (52.0.0.post20210125) Requirement already satisfied: tomli>=1.0.0 in /environment/miniconda3/lib/python3.7/site-packages (from setuptools-scm>=4->matplotlib->mmengine) (1.2.2) Requirement already satisfied: typing-extensions<5.0,>=4.0.0 in /environment/miniconda3/lib/python3.7/site-packages (from rich->mmengine) (4.0.1) Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /environment/miniconda3/lib/python3.7/site-packages (from rich->mmengine) (2.15.1) Requirement already satisfied: markdown-it-py>=2.2.0 in /environment/miniconda3/lib/python3.7/site-packages (from rich->mmengine) (2.2.0) Requirement already satisfied: mdurl~=0.1 in /environment/miniconda3/lib/python3.7/site-packages (from markdown-it-py>=2.2.0->rich->mmengine) (0.1.2) Installing collected packages: addict, mmengine Successfully installed addict-2.4.0 mmengine-0.7.4 Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Looking in links: https://download.openmmlab.com/mmcv/dist/cu113/torch1.10.0/index.html Collecting mmcv==2.0.0rc4 Downloading https://download.openmmlab.com/mmcv/dist/cu113/torch1.10.0/mmcv-2.0.0rc4-cp37-cp37m-manylinux1_x86_64.whl (59.4 MB) [K |████████████████████████████████| 59.4 MB 58 kB/s eta 0:00:011 [?25hRequirement already satisfied: pyyaml in /environment/miniconda3/lib/python3.7/site-packages (from mmcv==2.0.0rc4) (6.0) Requirement already satisfied: opencv-python>=3 in /environment/miniconda3/lib/python3.7/site-packages (from mmcv==2.0.0rc4) (4.5.4.60) Requirement already satisfied: numpy in /environment/miniconda3/lib/python3.7/site-packages (from mmcv==2.0.0rc4) (1.21.4) Requirement already satisfied: addict in /environment/miniconda3/lib/python3.7/site-packages (from mmcv==2.0.0rc4) (2.4.0) Requirement already satisfied: packaging in /environment/miniconda3/lib/python3.7/site-packages (from mmcv==2.0.0rc4) (21.3) Requirement already satisfied: yapf in /environment/miniconda3/lib/python3.7/site-packages (from mmcv==2.0.0rc4) (0.31.0) Requirement already satisfied: mmengine>=0.2.0 in /environment/miniconda3/lib/python3.7/site-packages (from mmcv==2.0.0rc4) (0.7.4) Requirement already satisfied: Pillow in /environment/miniconda3/lib/python3.7/site-packages (from mmcv==2.0.0rc4) (8.4.0) Requirement already satisfied: matplotlib in /environment/miniconda3/lib/python3.7/site-packages (from mmengine>=0.2.0->mmcv==2.0.0rc4) (3.5.0) Requirement already satisfied: termcolor in /environment/miniconda3/lib/python3.7/site-packages (from mmengine>=0.2.0->mmcv==2.0.0rc4) (1.1.0) Requirement already satisfied: rich in /environment/miniconda3/lib/python3.7/site-packages (from mmengine>=0.2.0->mmcv==2.0.0rc4) (13.4.2) Requirement already satisfied: cycler>=0.10 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine>=0.2.0->mmcv==2.0.0rc4) (0.11.0) Requirement already satisfied: kiwisolver>=1.0.1 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine>=0.2.0->mmcv==2.0.0rc4) (1.3.2) Requirement already satisfied: python-dateutil>=2.7 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine>=0.2.0->mmcv==2.0.0rc4) (2.8.2) Requirement already satisfied: setuptools-scm>=4 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine>=0.2.0->mmcv==2.0.0rc4) (6.3.2) Requirement already satisfied: fonttools>=4.22.0 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine>=0.2.0->mmcv==2.0.0rc4) (4.28.3) Requirement already satisfied: pyparsing>=2.2.1 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmengine>=0.2.0->mmcv==2.0.0rc4) (3.0.6) Requirement already satisfied: six>=1.5 in /environment/miniconda3/lib/python3.7/site-packages (from python-dateutil>=2.7->matplotlib->mmengine>=0.2.0->mmcv==2.0.0rc4) (1.16.0) Requirement already satisfied: setuptools in /environment/miniconda3/lib/python3.7/site-packages (from setuptools-scm>=4->matplotlib->mmengine>=0.2.0->mmcv==2.0.0rc4) (52.0.0.post20210125) Requirement already satisfied: tomli>=1.0.0 in /environment/miniconda3/lib/python3.7/site-packages (from setuptools-scm>=4->matplotlib->mmengine>=0.2.0->mmcv==2.0.0rc4) (1.2.2) Requirement already satisfied: markdown-it-py>=2.2.0 in /environment/miniconda3/lib/python3.7/site-packages (from rich->mmengine>=0.2.0->mmcv==2.0.0rc4) (2.2.0) Requirement already satisfied: typing-extensions<5.0,>=4.0.0 in /environment/miniconda3/lib/python3.7/site-packages (from rich->mmengine>=0.2.0->mmcv==2.0.0rc4) (4.0.1) Requirement already satisfied: pygments<3.0.0,>=2.13.0 in /environment/miniconda3/lib/python3.7/site-packages (from rich->mmengine>=0.2.0->mmcv==2.0.0rc4) (2.15.1) Requirement already satisfied: mdurl~=0.1 in /environment/miniconda3/lib/python3.7/site-packages (from markdown-it-py>=2.2.0->rich->mmengine>=0.2.0->mmcv==2.0.0rc4) (0.1.2) Installing collected packages: mmcv Successfully installed mmcv-2.0.0rc4
# 安装相关工具
!pip install opencv-python pillow matplotlib seaborn tqdm pytorch-lightning 'mmdet>=3.0.0rc1'
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Requirement already satisfied: opencv-python in /environment/miniconda3/lib/python3.7/site-packages (4.5.4.60) Requirement already satisfied: pillow in /environment/miniconda3/lib/python3.7/site-packages (8.4.0) Requirement already satisfied: matplotlib in /environment/miniconda3/lib/python3.7/site-packages (3.5.0) Collecting seaborn Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8f/2e/17bbb83fbf102687bb2aa3d808add39da820a7698159302a1a69bb82e01c/seaborn-0.12.2-py3-none-any.whl (293 kB) [K |████████████████████████████████| 293 kB 35.8 MB/s eta 0:00:01 [?25hRequirement already satisfied: tqdm in /environment/miniconda3/lib/python3.7/site-packages (4.61.2) Collecting pytorch-lightning Downloading https://pypi.tuna.tsinghua.edu.cn/packages/77/ed/7d91e1958f0d48b439fae0de8ece3de3ce8c3d4e03b04bd3c007ba879a49/pytorch_lightning-1.9.5-py3-none-any.whl (829 kB) [K |████████████████████████████████| 829 kB 38.6 MB/s eta 0:00:01 [?25hCollecting mmdet>=3.0.0rc1 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2d/6a/1f97b0f476f64ed46dedc6b235ba51a5ef4c32db65702bf04d7a7de4ad51/mmdet-3.0.0-py3-none-any.whl (1.7 MB) [K |████████████████████████████████| 1.7 MB 40.6 MB/s eta 0:00:01 [?25hRequirement already satisfied: six in /environment/miniconda3/lib/python3.7/site-packages (from mmdet>=3.0.0rc1) (1.16.0) Collecting terminaltables Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c4/fb/ea621e0a19733e01fe4005d46087d383693c0f4a8f824b47d8d4122c87e0/terminaltables-3.1.10-py2.py3-none-any.whl (15 kB) Collecting pycocotools Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ef/c6/90220be3b39fbc4cbd203775ca47dd8dc97fae06fbd2b500637395621b7c/pycocotools-2.0.6.tar.gz (24 kB) Installing build dependencies ... [?25ldone [?25h Getting requirements to build wheel ... [?25ldone [?25h Preparing wheel metadata ... [?25ldone [?25hRequirement already satisfied: scipy in /environment/miniconda3/lib/python3.7/site-packages (from mmdet>=3.0.0rc1) (1.7.3) Requirement already satisfied: numpy in /environment/miniconda3/lib/python3.7/site-packages (from mmdet>=3.0.0rc1) (1.21.4) Collecting shapely Downloading https://pypi.tuna.tsinghua.edu.cn/packages/1d/a4/931d0780f31f3ea8c4f9ef6464a2825137c5241e6707a5fb03bef760a7eb/shapely-2.0.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.3 MB) [K |████████████████████████████████| 2.3 MB 54.0 MB/s eta 0:00:01 [?25hRequirement already satisfied: cycler>=0.10 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib) (0.11.0) Requirement already satisfied: pyparsing>=2.2.1 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib) (3.0.6) Requirement already satisfied: python-dateutil>=2.7 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib) (2.8.2) Requirement already satisfied: packaging>=20.0 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib) (21.3) Requirement already satisfied: kiwisolver>=1.0.1 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib) (1.3.2) Requirement already satisfied: fonttools>=4.22.0 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib) (4.28.3) Requirement already satisfied: setuptools-scm>=4 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib) (6.3.2) Requirement already satisfied: setuptools in /environment/miniconda3/lib/python3.7/site-packages (from setuptools-scm>=4->matplotlib) (52.0.0.post20210125) Requirement already satisfied: tomli>=1.0.0 in /environment/miniconda3/lib/python3.7/site-packages (from setuptools-scm>=4->matplotlib) (1.2.2) Requirement already satisfied: pandas>=0.25 in /environment/miniconda3/lib/python3.7/site-packages (from seaborn) (1.3.4) Requirement already satisfied: typing_extensions in /environment/miniconda3/lib/python3.7/site-packages (from seaborn) (4.0.1) Requirement already satisfied: pytz>=2017.3 in /environment/miniconda3/lib/python3.7/site-packages (from pandas>=0.25->seaborn) (2021.3) Requirement already satisfied: PyYAML>=5.4 in /environment/miniconda3/lib/python3.7/site-packages (from pytorch-lightning) (6.0) Requirement already satisfied: torch>=1.10.0 in /environment/miniconda3/lib/python3.7/site-packages (from pytorch-lightning) (1.10.1+cu113) Collecting torchmetrics>=0.7.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fb/47/6e9f9b41c48750a45ad07cc6d43a2979bfc09e6989656aece97cc59cbef1/torchmetrics-0.11.4-py3-none-any.whl (519 kB) [K |████████████████████████████████| 519 kB 69.0 MB/s eta 0:00:01 [?25hCollecting lightning-utilities>=0.6.0.post0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5d/ec/a20c5d5f26894913da028110310ba55ee254e1b7ff0ff78441e4eeb7291f/lightning_utilities-0.8.0-py3-none-any.whl (20 kB) Collecting fsspec[http]>2021.06.0 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bd/64/f0d369ede0ca54fdd520bdee5086dbaf0af81dac53a2ce847bd1ec6e0bf1/fsspec-2023.1.0-py3-none-any.whl (143 kB) [K |████████████████████████████████| 143 kB 76.9 MB/s eta 0:00:01 [?25hRequirement already satisfied: requests in /environment/miniconda3/lib/python3.7/site-packages (from fsspec[http]>2021.06.0->pytorch-lightning) (2.24.0) Requirement already satisfied: aiohttp!=4.0.0a0,!=4.0.0a1 in /environment/miniconda3/lib/python3.7/site-packages (from fsspec[http]>2021.06.0->pytorch-lightning) (3.7.4) Requirement already satisfied: async-timeout<4.0,>=3.0 in /environment/miniconda3/lib/python3.7/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning) (3.0.1) Requirement already satisfied: attrs>=17.3.0 in /environment/miniconda3/lib/python3.7/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning) (21.2.0) Requirement already satisfied: multidict<7.0,>=4.5 in /environment/miniconda3/lib/python3.7/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning) (5.2.0) Requirement already satisfied: chardet<4.0,>=2.0 in /environment/miniconda3/lib/python3.7/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning) (3.0.4) Requirement already satisfied: yarl<2.0,>=1.0 in /environment/miniconda3/lib/python3.7/site-packages (from aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning) (1.7.2) Requirement already satisfied: importlib-metadata>=4.0.0 in /environment/miniconda3/lib/python3.7/site-packages (from lightning-utilities>=0.6.0.post0->pytorch-lightning) (4.8.2) Requirement already satisfied: zipp>=0.5 in /environment/miniconda3/lib/python3.7/site-packages (from importlib-metadata>=4.0.0->lightning-utilities>=0.6.0.post0->pytorch-lightning) (3.6.0) Requirement already satisfied: idna>=2.0 in /environment/miniconda3/lib/python3.7/site-packages (from yarl<2.0,>=1.0->aiohttp!=4.0.0a0,!=4.0.0a1->fsspec[http]>2021.06.0->pytorch-lightning) (2.10) Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /environment/miniconda3/lib/python3.7/site-packages (from requests->fsspec[http]>2021.06.0->pytorch-lightning) (1.25.11) Requirement already satisfied: certifi>=2017.4.17 in /environment/miniconda3/lib/python3.7/site-packages (from requests->fsspec[http]>2021.06.0->pytorch-lightning) (2021.5.30) Building wheels for collected packages: pycocotools Building wheel for pycocotools (PEP 517) ... [?25ldone [?25h Created wheel for pycocotools: filename=pycocotools-2.0.6-cp37-cp37m-linux_x86_64.whl size=374102 sha256=0c414257fb21ca14040100c253e65ec7fdb8ae3fbf501cb9bad8fc48b3bae505 Stored in directory: /home/featurize/.cache/pip/wheels/f8/94/70/046149e666bd5812b7de6b87a28dcef238f7162f4108e0b3d8 Successfully built pycocotools Installing collected packages: fsspec, torchmetrics, terminaltables, shapely, pycocotools, lightning-utilities, seaborn, pytorch-lightning, mmdet Successfully installed fsspec-2023.1.0 lightning-utilities-0.8.0 mmdet-3.0.0 pycocotools-2.0.6 pytorch-lightning-1.9.5 seaborn-0.12.2 shapely-2.0.1 terminaltables-3.1.10 torchmetrics-0.11.4
2. 安装 MMSegmentation #
# 克隆最新的 mmsegmentation 源代码(网络问题,直接从 github 页面下载 zip 包)
!git clone https://github.com/open-mmlab/mmsegmentation.git -b dev-1.x
正克隆到 'mmsegmentation'... remote: Enumerating objects: 15132, done.[K remote: Counting objects: 100% (699/699), done.[K remote: Compressing objects: 100% (466/466), done.[K remote: Total 15132 (delta 282), reused 438 (delta 201), pack-reused 14433[K 接收对象中: 100% (15132/15132), 20.28 MiB | 16.07 MiB/s, 完成. 处理 delta 中: 100% (10591/10591), 完成.
# 安装 MMSeg
import os
os.chdir('mmsegmentation')
os.getcwd() # 确保在正确的路径下
'/home/featurize/data/mmsegmentation'
!pip install -v -e .
Using pip 21.1.3 from /environment/miniconda3/lib/python3.7/site-packages/pip (python 3.7) Non-user install because site-packages writeable Created temporary directory: /tmp/pip-ephem-wheel-cache-mryvt3i5 Created temporary directory: /tmp/pip-req-tracker-6uwjlvvx Initialized build tracking at /tmp/pip-req-tracker-6uwjlvvx Created build tracker: /tmp/pip-req-tracker-6uwjlvvx Entered build tracker: /tmp/pip-req-tracker-6uwjlvvx Created temporary directory: /tmp/pip-install-8twg90yz Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple Obtaining file:///home/featurize/data/mmsegmentation Added file:///home/featurize/data/mmsegmentation to build tracker '/tmp/pip-req-tracker-6uwjlvvx' Running setup.py (path:/home/featurize/data/mmsegmentation/setup.py) egg_info for package from file:///home/featurize/data/mmsegmentation Created temporary directory: /tmp/pip-pip-egg-info-ov516xun Running command python setup.py egg_info running egg_info creating /tmp/pip-pip-egg-info-ov516xun/mmsegmentation.egg-info writing /tmp/pip-pip-egg-info-ov516xun/mmsegmentation.egg-info/PKG-INFO writing dependency_links to /tmp/pip-pip-egg-info-ov516xun/mmsegmentation.egg-info/dependency_links.txt writing requirements to /tmp/pip-pip-egg-info-ov516xun/mmsegmentation.egg-info/requires.txt writing top-level names to /tmp/pip-pip-egg-info-ov516xun/mmsegmentation.egg-info/top_level.txt writing manifest file '/tmp/pip-pip-egg-info-ov516xun/mmsegmentation.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' warning: no files found matching 'mmseg/.mim/model-index.yml' warning: no files found matching '*.py' under directory 'mmseg/.mim/configs' warning: no files found matching '*.yaml' under directory 'mmseg/.mim/configs' warning: no files found matching '*.py' under directory 'mmseg/.mim/tools' warning: no files found matching '*.sh' under directory 'mmseg/.mim/tools' writing manifest file '/tmp/pip-pip-egg-info-ov516xun/mmsegmentation.egg-info/SOURCES.txt' Source in /home/featurize/data/mmsegmentation has version 1.0.0, which satisfies requirement mmsegmentation==1.0.0 from file:///home/featurize/data/mmsegmentation Removed mmsegmentation==1.0.0 from file:///home/featurize/data/mmsegmentation from build tracker '/tmp/pip-req-tracker-6uwjlvvx' Requirement already satisfied: matplotlib in /environment/miniconda3/lib/python3.7/site-packages (from mmsegmentation==1.0.0) (3.5.0) Requirement already satisfied: numpy in /environment/miniconda3/lib/python3.7/site-packages (from mmsegmentation==1.0.0) (1.21.4) Requirement already satisfied: packaging in /environment/miniconda3/lib/python3.7/site-packages (from mmsegmentation==1.0.0) (21.3) 1 location(s) to search for versions of prettytable: * https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/ Fetching project page and analyzing links: https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/ Getting page https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/ Found index url https://pypi.tuna.tsinghua.edu.cn/simple Looking up "https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/" in the cache Request header has "max_age" as 0, cache bypassed Starting new HTTPS connection (1): pypi.tuna.tsinghua.edu.cn:443 https://pypi.tuna.tsinghua.edu.cn:443 "GET /simple/prettytable/ HTTP/1.1" 200 None Updating cache with response from "https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/" Caching due to etag Skipping link: unsupported archive format: .egg: https://pypi.tuna.tsinghua.edu.cn/packages/aa/2d/6dda982fc3ff451d06b5840a4722b1ddd6d611c05af26241f660ea1da598/prettytable-0.1-py2.6.egg#sha256=4b78eaacea36bf7321d72bbd6c5ae5b8d9b243b7fabb9c6a5d7bce1e6360b0c5 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) Skipping link: unsupported archive format: .egg: https://pypi.tuna.tsinghua.edu.cn/packages/fc/96/15c68452c4b59791edf3e1f2527cde7199a4d7b6cc673bb94bc60d86dd55/prettytable-0.2-py2.6.egg#sha256=7ace8226edca26af6ddbed83c64c15f8188fe183581e2e59c68826ccbe28e1ce (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) Skipping link: unsupported archive format: .egg: https://pypi.tuna.tsinghua.edu.cn/packages/04/d5/942a2bbaca693ff7942590f51959b8dd12a760598e4c98d95a31c4b2d991/prettytable-0.2.1-py2.6.egg#sha256=15d51ec1aca83a8b6513f3b220619063382d4ff45953f944bf86beca8a647796 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) Skipping link: unsupported archive format: .egg: https://pypi.tuna.tsinghua.edu.cn/packages/cb/2b/89865a1d735309404c092f6ac99dba1c5b1cb2ab832b7825d24d63312943/prettytable-0.3-py2.6.egg#sha256=04fc99a3ab8e9a6e62c5c8741d334a05229378c8c79ea3df8a8c0d09b1b4c66e (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) Found link https://pypi.tuna.tsinghua.edu.cn/packages/56/e4/e21204d3a9757b64a79f3a9800056676f57f9c5f70245ce53b7012e31546/prettytable-0.3.tar.gz#sha256=1523ea10d9c6de00986b3b48144a8aeff734378f2be22570c90e07c207c8207a (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.3 Found link https://pypi.tuna.tsinghua.edu.cn/packages/24/10/c9c6551e075154a7e78108cbb52db44965fe0e6800b271b76beeaffa0d15/prettytable-0.3.zip#sha256=892974c5e8fac7c8d73a5826e17777299ebf89fec03b00a98fefd9b2d2e199c5 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.3 Found link https://pypi.tuna.tsinghua.edu.cn/packages/30/a5/43f03a549f9235e390c9fd6a081082f9c55c38b450969136b40d7122590a/prettytable-0.4.tar.gz#sha256=29cb18d581a13fb276eac068cf3d264b2591a3c2b3499b97a6111358c4fa3ac8 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.4 Found link https://pypi.tuna.tsinghua.edu.cn/packages/24/42/6a030394c00c62b8a51093189fa287dff0aa598d695c36a276aa1b4f7ff8/prettytable-0.4.zip#sha256=e6c7f46b6ba3089d69ab5330ee8b4402eb14e2c54d9d29d6502ce333718b143e (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.4 Found link https://pypi.tuna.tsinghua.edu.cn/packages/06/07/fcfe808e157da9cc442ada347532c6ef5c31c23a594e6b0ddf8f35475f31/prettytable-0.5.tar.gz#sha256=52dbc76b9fdc53f6386ce9380a93653dbff20717296605449b86a73f426b7d8b (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.5 Found link https://pypi.tuna.tsinghua.edu.cn/packages/06/a1/fd7dfad67d52c005776458c97e2800114102e6cb9722526210868a48628c/prettytable-0.5.zip#sha256=a381ba555b8bf10e0b8e59c6c5743b30174ce77340defe880e6e30fe238c3906 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.5 Found link https://pypi.tuna.tsinghua.edu.cn/packages/b8/79/4808e86b6b77b0835cc973dbc737a79cb4575db5f10ea6b5d441f6b92ebd/prettytable-0.6.1.tar.bz2#sha256=7935bd8ae5c15b31703bd10eb4a0815288852dd6584e5e5eff33d1a3af6559b6 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.6.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/91/d4/9dee5e6d9ac63d2c6863caa8a91df650cedcb9119f1f5781b82526556eb5/prettytable-0.6.1.tar.gz#sha256=4085e520da758d6e22e115377ca5d3723f04fb186303879ab98277070444a9cb (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.6.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/6f/84/2ab0fd71dbfd720eae77426b8901d5091d488810ba64c845d43d0faf738f/prettytable-0.6.1.zip#sha256=3f4c48d80af6d40d5a76dd1650dece386349d6df8b7b096fc8ec39fec21ceba7 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.6.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/f0/87/0b8f0498405bfa9ede62d00bcb0357e861afc14117791afbf07c1cd3fa86/prettytable-0.6.tar.bz2#sha256=babe57cb92d4a30185822521cbcfe40c7966db8e7de70c8e99614a9bee61182d (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.6 Found link https://pypi.tuna.tsinghua.edu.cn/packages/dc/17/7054874b05bfb10edc956a9205b5c63c8e9b6d5d71bb7121265ab309b4df/prettytable-0.6.tar.gz#sha256=4758bfe9d2fe203e7620fb9e6493e5206861297ea089974be0fc32d4b00a780c (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.6 Found link https://pypi.tuna.tsinghua.edu.cn/packages/dd/12/6b03e7731c51d5bfdbdea33c2107914cdc1c34bff1d03eb2853e7688f18a/prettytable-0.6.zip#sha256=cc107f07fa8373c82b84e8b12b2bd14d7ddf09558538b01b0d7ebbd83f8f427f (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.6 Found link https://pypi.tuna.tsinghua.edu.cn/packages/ea/cc/f72eb63ea90fcca0a89eaa476e156205320b1ceefcd4ab37b8b83f5a9842/prettytable-0.7.1.tar.bz2#sha256=599bc5b4b9602e28294cf795733c889c26dd934aa7e0ee9cff9b905d4fbad188 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.7.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/ff/a4/6d21b97807e910d8a8523c6c20d53732a10cccee04a56e4ee80a77cca9e7/prettytable-0.7.1.tar.gz#sha256=686bda277474e5cc3cff02596d72c2d6f171170225af3dedffe78cbf958c6348 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.7.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/b9/a5/2bf4329f87105289a3b9bdd806baf0726f81a6b73dd429b5e6b1792cdcf2/prettytable-0.7.1.zip#sha256=0e0a9c663cdd2c084ca3090702a8449cae9e804d46ef29f0a909629467524ddb (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.7.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/ef/30/4b0746848746ed5941f052479e7c23d2b56d174b82f4fd34a25e389831f5/prettytable-0.7.2.tar.bz2#sha256=853c116513625c738dc3ce1aee148b5b5757a86727e67eff6502c7ca59d43c36 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.7.2 Found link https://pypi.tuna.tsinghua.edu.cn/packages/e0/a1/36203205f77ccf98f3c6cf17cf068c972e6458d7e58509ca66da949ca347/prettytable-0.7.2.tar.gz#sha256=2d5460dc9db74a32bcc8f9f67de68b2c4f4d2f01fa3bd518764c69156d9cacd9 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.7.2 Found link https://pypi.tuna.tsinghua.edu.cn/packages/23/4a/9785a37ed6425918af69909af715ced0fa261e518601a0c70309a708fd08/prettytable-0.7.2.zip#sha256=a53da3b43d7a5c229b5e3ca2892ef982c46b7923b51e98f0db49956531211c4f (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/), version: 0.7.2 Found link https://pypi.tuna.tsinghua.edu.cn/packages/cc/16/d40b604035012ec5ed0588098b876f5c433de66bb615db647743bcc45886/prettytable-1.0.0-py2.py3-none-any.whl#sha256=d3fa464010bf7fec9384d3ea1a1e14398a9e3f2f0c5d052219366897bf6cb19c (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*), version: 1.0.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/39/c6/9e2067eef39a677367887d6e41a8d0332d9fcbb98878f52e9192ffbd748a/prettytable-1.0.0.tar.gz#sha256=98a3b74b1980e6a9392498e3a2a5406f6bd836f412843c2be23d9c88671747ac (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*), version: 1.0.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/39/da/8336296a830caa495a25304e12ffb32a8c3a9d2d08ba995f066fe16152e1/prettytable-1.0.1-py2.py3-none-any.whl#sha256=e7e464e8f7ecfd9a74c67f8da35f2a7da3d827235ba0a4737bb6d4b19f4a04bb (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*), version: 1.0.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/69/89/564e58a41c8593be42e2522c43adc29f8a0f387cccec6ea0038c02113f6d/prettytable-1.0.1.tar.gz#sha256=6bb7f539903cb031fecb855b615cbcac8cd245ebc6fa51c6e23ab3386db89771 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*), version: 1.0.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/94/d5/52e48f3bcf66f838d411ad85c3ac9550c2451d082623e2d4d4df7411ed5c/prettytable-2.0.0-py3-none-any.whl#sha256=5dc7fcaca227f48deacd86958ae9d7b8c31a186fcb354bbb066763f20adf3eb9 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.0.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/78/dc/96f8633fcd49fad2189dd57918ff410627818ff3ebe1649678d8ac2e7126/prettytable-2.0.0.tar.gz#sha256=e37acd91976fe6119172771520e58d1742c8479703489321dc1d9c85e7259922 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.0.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/26/1b/42b59a4038bc0442e3a0085bc0de385658131eef8a88946333f870559b09/prettytable-2.1.0-py3-none-any.whl#sha256=bb5abc72bdfae6f3cdadb04fb7726f6915af0ddb7c897a41d4ad7736d9bfd8fd (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.1.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/d4/c6/d388b3d4992acf413d1b67101107b7f4651cc2835abd0bbd6661678eb2c1/prettytable-2.1.0.tar.gz#sha256=5882ed9092b391bb8f6e91f59bcdbd748924ff556bb7c634089d5519be87baa0 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.1.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/bd/b5/c09f8d237e060a9e7b5d2d1577c2a6bc49fa298a7b4aefd52146f2b9a62e/prettytable-2.2.0-py3-none-any.whl#sha256=b186f1db9c9377cb552cfa95a3b7a0feab6ec55d7cad7e0763bdcbea1e8f4687 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.2.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/00/8d/95441120aa870aa800f8b4c6cf650bf0739d7a41883fe81769ab593556c9/prettytable-2.2.0.tar.gz#sha256=bd81678c108e6c73d4f1e47cd4283de301faaa6ff6220bcd1d4022038c56b416 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.2.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/e1/77/821a93d77111aee2525841b6116287f99eeefc482f4f28765fd8d7ef1c64/prettytable-2.2.1-py3-none-any.whl#sha256=09fb2c7f93e4f93e0235f05ae199ac3f16da3a251b2cfa1c7108b34ede298fa3 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.2.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/81/ba/ead3c121d6e59ea4e31bba0976b28ff0369210c66901e84fad20878299e2/prettytable-2.2.1.tar.gz#sha256=6d465005573a5c058d4ca343449a5b28c21252b86afcdfa168cdc6a440f0b24c (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.2.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/c2/98/3372c23c561cbaaa05bb60b2c3d30bfdad9ab504bf1ddefc7368b4545958/prettytable-2.3.0-py3-none-any.whl#sha256=74ba6d10555c93e2d4697751744207f6baadf77010914b2bcd8d5b3b546f84de (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.3.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/8b/7d/a08e1331281f237cbbff594d34696a76dc8b6cea5dca895d0b7487c14309/prettytable-2.3.0.tar.gz#sha256=efd6f72d453bc0513b90f5b10fb4d085b919ca0f4c5ef033bda1dd894572ba64 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.3.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/de/56/554603797416219cae8fd3eae33e5e2d58a7fc73419129b62fa419a67856/prettytable-2.4.0-py3-none-any.whl#sha256=2492f29e8686bdbcce815a568bff74cb71cbb704747c3abb9c9c6cfe25f985a2 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.4.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/ea/36/a96f1d0f434e1658b3fde011df028efdc3d38bde563339f0fc9e8beadc59/prettytable-2.4.0.tar.gz#sha256=18e56447f636b447096977d468849c1e2d3cfa0af8e7b5acfcf83a64790c0aca (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.4.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/9e/6d/40a24eaa03ea4418129708fd3f0f17eda73d568f16d4d4fd412566168b4c/prettytable-2.5.0-py3-none-any.whl#sha256=1411c65d21dca9eaa505ba1d041bed75a6d629ae22f5109a923f4e719cfecba4 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.5.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/e4/35/21bf22e21b29102bbe81730caf498dfb3e1eed2642ac71f323472ead673a/prettytable-2.5.0.tar.gz#sha256=f7da57ba63d55116d65e5acb147bfdfa60dceccabf0d607d6817ee2888a05f2c (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.6), version: 2.5.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/71/4f/82c03ec59c6b9b1caaa60e1e7d7713f4587a75824207e41698effc8ca5b7/prettytable-3.0.0-py3-none-any.whl#sha256=d55bc2547611bd8c40f1c69bbb8daf1b6b2c326214a265d211ec9c57fc252093 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.0.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/71/19/d65d4c39aa12a5630a8aa02ead8324cfaae3217146b19dd25d88d763bbdf/prettytable-3.0.0.tar.gz#sha256=69fe75d78ac8651e16dd61265b9e19626df5d630ae294fc31687aa6037b97a58 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.0.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/bf/f5/2ec9f14ac0a8efc292d003ff60d001ce28994a3b3109fda1d786be3415c8/prettytable-3.1.0-py3-none-any.whl#sha256=e87c6a7d9ef34230556fa0b4bb5ea465fdada6912cd90401afb0ce4bfa106448 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.1.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/01/55/a4a1a0f73f7665744cd5712fd6f982e5406c8e7459a0730a69299a3c1e2b/prettytable-3.1.0.tar.gz#sha256=7c2e104031614b5ba013516440241702bfaa369534069de3bacca015ffd0f27b (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.1.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/f9/b5/7775772482999e0659def71de81cb888a822b29284ca2b7d55f37ba512bb/prettytable-3.1.1-py3-none-any.whl#sha256=f546d42de21ac14d791c91e4e9814f02271f4a5bf27b894457914be7513dc92b (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.1.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/89/c1/3043e85bf06f252f51817dad51a37368daaf7b1c101b43cd5aa6100f09b1/prettytable-3.1.1.tar.gz#sha256=43c9e23272ca253d038ae76fe3adde89794e92e7fcab2ddf5b94b38642ef4f21 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.1.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/96/53/91638391af5a68d27402b920ccc3fdfae51dd3e333476b414393d4478a70/prettytable-3.2.0-py3-none-any.whl#sha256=f6c5ec87c3ef9df5bba1d32d826c1b862ecad0344dddb6082e3562caf71fe085 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.2.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/cb/7d/7e6bc4bd4abc49e9f4f5c4773bb43d1615e4b476d108d1b527318b9c6521/prettytable-3.2.0.tar.gz#sha256=ae7d96c64100543dc61662b40a28f3b03c0f94a503ed121c6fca2782c5816f81 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.2.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/5f/ab/64371af206988d7b15c8112c9c277b8eb4618397c01471e52b902a17f59c/prettytable-3.3.0-py3-none-any.whl#sha256=d1c34d72ea2c0ffd6ce5958e71c428eb21a3d40bf3133afe319b24aeed5af407 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.3.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/10/88/ef38a6e4bc375600d3031e405a8d3b3dc4a154fccffd21d5d06e66c96230/prettytable-3.3.0.tar.gz#sha256=118eb54fd2794049b810893653b20952349df6d3bc1764e7facd8a18064fa9b0 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.3.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/a7/b7/691a836347df9610c2264e7e60461f9991ca36ce9f2179a38ebc9e4a2682/prettytable-3.4.0-py3-none-any.whl#sha256=8ea12e615fee421090ca3954c2e006280f7ecdf4adf940dbc1c6ec014d4eca9d (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.4.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/63/42/b8b24cfe616a8217515011fc54ed37b45077cd4467230b3a0132166696a1/prettytable-3.4.0.tar.gz#sha256=d16747b5108c252bf065ea1cd239aab3c87bd8bb10a9f7973c9f192bbcfed26e (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.4.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/5b/c9/4e7dbae5054c5bbaed9e7aa7a78e1ceff003d0b0699318e5d6993a0a10c9/prettytable-3.4.1-py3-none-any.whl#sha256=0d23ff81e165077d93367e1379d97893c7a51541483d25bad45b9647660ef06f (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.4.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/a5/aa/0852b0ee91587a766fbc872f398ed26366c7bf26373d5feb974bebbde8d2/prettytable-3.4.1.tar.gz#sha256=7d7dd84d0b206f2daac4471a72f299d6907f34516064feb2838e333a4e2567bd (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.4.1 Found link https://pypi.tuna.tsinghua.edu.cn/packages/fa/4c/9b2bbb92a14a09ed929afa40282c088d8e50f79303eb3873fbeba1d96e89/prettytable-3.5.0-py3-none-any.whl#sha256=fe391c3b545800028edf5dbb6a5360893feb398367fcc1cf8d7a5b29ce5c59a1 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.5.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/51/d8/f4739a1971029c00fdb97c9ea4abbfb20ea041f6aa7613343f12a468e217/prettytable-3.5.0.tar.gz#sha256=52f682ba4efe29dccb38ff0fe5bac8a23007d0780ff92a8b85af64bc4fc74d72 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.5.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/51/fd/52b6d8a28f8dabf05e5fcbb5ef639d62326a5bccfa93b98fb7e54d414509/prettytable-3.6.0-py3-none-any.whl#sha256=3b767129491767a3a5108e6f305cbaa650f8020a7db5dfe994a2df7ef7bad0fe (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.6.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/ba/b6/8e78337766d4c324ac22cb887ecc19487531f508dbf17d922b91492d55bb/prettytable-3.6.0.tar.gz#sha256=2e0026af955b4ea67b22122f310b90eae890738c08cb0458693a49b6221530ac (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.6.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/7a/cd/bec5850e23eb005c6fe30fe4c26bafd9a07b3d2524771f22a0fa01270078/prettytable-3.7.0-py3-none-any.whl#sha256=f4aaf2ed6e6062a82fd2e6e5289bbbe705ec2788fe401a3a1f62a1cea55526d2 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.7.0 Found link https://pypi.tuna.tsinghua.edu.cn/packages/95/8d/f6b4448e386eb1382a99cbceabe3899f3aa431992582cc90496843548303/prettytable-3.7.0.tar.gz#sha256=ef8334ee40b7ec721651fc4d37ecc7bb2ef55fde5098d994438f0dfdaa385c0c (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.7), version: 3.7.0 Link requires a different Python (3.7.10 not in: '>=3.8'): https://pypi.tuna.tsinghua.edu.cn/packages/25/1e/4c284713b092ec384fad4399452f43f6446ad9aabc9c0b3c3c0920cc53b6/prettytable-3.8.0-py3-none-any.whl#sha256=03481bca25ae0c28958c8cd6ac5165c159ce89f7ccde04d5c899b24b68bb13b7 (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.8) Link requires a different Python (3.7.10 not in: '>=3.8'): https://pypi.tuna.tsinghua.edu.cn/packages/18/fa/82e719efc465238383f099c08b5284b974f5002dbe12050bcbbc912366eb/prettytable-3.8.0.tar.gz#sha256=031eae6a9102017e8c7c7906460d150b7ed78b20fd1d8c8be4edaf88556c07ce (from https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/) (requires-python:>=3.8) Skipping link: not a file: https://pypi.tuna.tsinghua.edu.cn/simple/prettytable/ Given no hashes to check 56 links for project 'prettytable': discarding no candidates Collecting prettytable Created temporary directory: /tmp/pip-unpack-ozq7ow62 Looking up "https://pypi.tuna.tsinghua.edu.cn/packages/7a/cd/bec5850e23eb005c6fe30fe4c26bafd9a07b3d2524771f22a0fa01270078/prettytable-3.7.0-py3-none-any.whl" in the cache No cache entry available https://pypi.tuna.tsinghua.edu.cn:443 "GET /packages/7a/cd/bec5850e23eb005c6fe30fe4c26bafd9a07b3d2524771f22a0fa01270078/prettytable-3.7.0-py3-none-any.whl HTTP/1.1" 200 27508 Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7a/cd/bec5850e23eb005c6fe30fe4c26bafd9a07b3d2524771f22a0fa01270078/prettytable-3.7.0-py3-none-any.whl (27 kB) Updating cache with response from "https://pypi.tuna.tsinghua.edu.cn/packages/7a/cd/bec5850e23eb005c6fe30fe4c26bafd9a07b3d2524771f22a0fa01270078/prettytable-3.7.0-py3-none-any.whl" Added prettytable from https://pypi.tuna.tsinghua.edu.cn/packages/7a/cd/bec5850e23eb005c6fe30fe4c26bafd9a07b3d2524771f22a0fa01270078/prettytable-3.7.0-py3-none-any.whl#sha256=f4aaf2ed6e6062a82fd2e6e5289bbbe705ec2788fe401a3a1f62a1cea55526d2 (from mmsegmentation==1.0.0) to build tracker '/tmp/pip-req-tracker-6uwjlvvx' Removed prettytable from https://pypi.tuna.tsinghua.edu.cn/packages/7a/cd/bec5850e23eb005c6fe30fe4c26bafd9a07b3d2524771f22a0fa01270078/prettytable-3.7.0-py3-none-any.whl#sha256=f4aaf2ed6e6062a82fd2e6e5289bbbe705ec2788fe401a3a1f62a1cea55526d2 (from mmsegmentation==1.0.0) from build tracker '/tmp/pip-req-tracker-6uwjlvvx' Requirement already satisfied: scipy in /environment/miniconda3/lib/python3.7/site-packages (from mmsegmentation==1.0.0) (1.7.3) Requirement already satisfied: kiwisolver>=1.0.1 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmsegmentation==1.0.0) (1.3.2) Requirement already satisfied: pyparsing>=2.2.1 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmsegmentation==1.0.0) (3.0.6) Requirement already satisfied: cycler>=0.10 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmsegmentation==1.0.0) (0.11.0) Requirement already satisfied: setuptools-scm>=4 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmsegmentation==1.0.0) (6.3.2) Requirement already satisfied: pillow>=6.2.0 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmsegmentation==1.0.0) (8.4.0) Requirement already satisfied: fonttools>=4.22.0 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmsegmentation==1.0.0) (4.28.3) Requirement already satisfied: python-dateutil>=2.7 in /environment/miniconda3/lib/python3.7/site-packages (from matplotlib->mmsegmentation==1.0.0) (2.8.2) Requirement already satisfied: six>=1.5 in /environment/miniconda3/lib/python3.7/site-packages (from python-dateutil>=2.7->matplotlib->mmsegmentation==1.0.0) (1.16.0) Requirement already satisfied: tomli>=1.0.0 in /environment/miniconda3/lib/python3.7/site-packages (from setuptools-scm>=4->matplotlib->mmsegmentation==1.0.0) (1.2.2) Requirement already satisfied: setuptools in /environment/miniconda3/lib/python3.7/site-packages (from setuptools-scm>=4->matplotlib->mmsegmentation==1.0.0) (52.0.0.post20210125) Requirement already satisfied: wcwidth in /environment/miniconda3/lib/python3.7/site-packages (from prettytable->mmsegmentation==1.0.0) (0.2.5) Requirement already satisfied: importlib-metadata in /environment/miniconda3/lib/python3.7/site-packages (from prettytable->mmsegmentation==1.0.0) (4.8.2) Requirement already satisfied: zipp>=0.5 in /environment/miniconda3/lib/python3.7/site-packages (from importlib-metadata->prettytable->mmsegmentation==1.0.0) (3.6.0) Requirement already satisfied: typing-extensions>=3.6.4 in /environment/miniconda3/lib/python3.7/site-packages (from importlib-metadata->prettytable->mmsegmentation==1.0.0) (4.0.1) Created temporary directory: /tmp/pip-unpack-spszn6yr Installing collected packages: prettytable, mmsegmentation Running setup.py develop for mmsegmentation Running command /environment/miniconda3/bin/python -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/home/featurize/data/mmsegmentation/setup.py'"'"'; __file__='"'"'/home/featurize/data/mmsegmentation/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' develop --no-deps running develop running egg_info creating mmsegmentation.egg-info writing mmsegmentation.egg-info/PKG-INFO writing dependency_links to mmsegmentation.egg-info/dependency_links.txt writing requirements to mmsegmentation.egg-info/requires.txt writing top-level names to mmsegmentation.egg-info/top_level.txt writing manifest file 'mmsegmentation.egg-info/SOURCES.txt' reading manifest template 'MANIFEST.in' writing manifest file 'mmsegmentation.egg-info/SOURCES.txt' running build_ext Creating /environment/miniconda3/lib/python3.7/site-packages/mmsegmentation.egg-link (link to .) Adding mmsegmentation 1.0.0 to easy-install.pth file Installed /home/featurize/data/mmsegmentation Successfully installed mmsegmentation-1.0.0 prettytable-3.7.0 Removed build tracker: '/tmp/pip-req-tracker-6uwjlvvx'
# 准备权重文件和素材
#-----------------创建文件夹---------------------------
# 创建 checkpoint 文件夹,用于存放预训练模型权重文件
os.mkdir('checkpoint')
# 创建 outputs 文件夹,用于存放预测结果
os.mkdir('outputs')
# 创建 data 文件夹,用于存放图片和视频素材
os.mkdir('data')
#------------------------------------------------------
# 从 Model Zoo 获取 PSPNet 预训练模型,下载并保存在 checkpoint 文件夹中
# Model Zoo:https://github.com/open-mmlab/mmsegmentation/blob/master/docs/en/model_zoo.md
!wget https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth -P checkpoint
--2023-06-17 19:09:43-- https://download.openmmlab.com/mmsegmentation/v0.5/pspnet/pspnet_r50-d8_512x1024_40k_cityscapes/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth 正在连接 172.16.0.13:5848... 已连接。 已发出 Proxy 请求,正在等待回应... 200 OK 长度: 196205945 (187M) [application/octet-stream] 正在保存至: “checkpoint/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth” pspnet_r50-d8_512x1 100%[===================>] 187.12M 8.46MB/s 用时 19s 2023-06-17 19:10:03 (9.78 MB/s) - 已保存 “checkpoint/pspnet_r50-d8_512x1024_40k_cityscapes_20200605_003338-2966598c.pth” [196205945/196205945])
3. 准备数据(作业不需要,此步骤可跳过) #
# 伦敦街景图片
!wget https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20220713-mmdetection/images/street_uk.jpeg -P data
# 上海驾车街景视频,视频来源:https://www.youtube.com/watch?v=ll8TgCZ0plk
!wget https://zihao-download.obs.cn-east-3.myhuaweicloud.com/detectron2/traffic.mp4 -P data
# 街拍视频,2022年3月30日
!wget https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20220713-mmdetection/images/street_20220330_174028.mp4 -P data
--2023-06-17 19:10:22-- https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20220713-mmdetection/images/street_uk.jpeg 正在连接 172.16.0.13:5848... 已连接。 已发出 Proxy 请求,正在等待回应... 200 OK 长度: 469065 (458K) [image/jpeg] 正在保存至: “data/street_uk.jpeg” street_uk.jpeg 100%[===================>] 458.07K 2.13MB/s 用时 0.2s 2023-06-17 19:10:22 (2.13 MB/s) - 已保存 “data/street_uk.jpeg” [469065/469065]) --2023-06-17 19:10:22-- https://zihao-download.obs.cn-east-3.myhuaweicloud.com/detectron2/traffic.mp4 正在连接 172.16.0.13:5848... 已连接。 已发出 Proxy 请求,正在等待回应... 200 OK 长度: 3686362 (3.5M) [video/mp4] 正在保存至: “data/traffic.mp4” traffic.mp4 100%[===================>] 3.51M 10.6MB/s 用时 0.3s 2023-06-17 19:10:23 (10.6 MB/s) - 已保存 “data/traffic.mp4” [3686362/3686362]) --2023-06-17 19:10:23-- https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20220713-mmdetection/images/street_20220330_174028.mp4 正在连接 172.16.0.13:5848... 已连接。 已发出 Proxy 请求,正在等待回应... 200 OK 长度: 13575276 (13M) [video/mp4] 正在保存至: “data/street_20220330_174028.mp4” street_20220330_174 100%[===================>] 12.95M 18.4MB/s 用时 0.7s 2023-06-17 19:10:24 (18.4 MB/s) - 已保存 “data/street_20220330_174028.mp4” [13575276/13575276])
4. 检查安装 #
# 检查 Pytorch
print('='*30)
import torch, torchvision
print('Pytorch 版本', torch.__version__)
print('CUDA 是否可用',torch.cuda.is_available())
print('-'*30)
# 检查 mmcv
import mmcv
from mmcv.ops import get_compiling_cuda_version, get_compiler_version
print('MMCV版本', mmcv.__version__)
print('CUDA版本', get_compiling_cuda_version())
print('编译器版本', get_compiler_version())
print('-'*30)
# 检查 mmsegmentation
import mmseg
from mmseg.utils import register_all_modules
from mmseg.apis import inference_model, init_model
print('mmsegmentation版本', mmseg.__version__)
print('='*30)
============================== Pytorch 版本 1.10.1+cu113 CUDA 是否可用 True ------------------------------ MMCV版本 2.0.0rc4 CUDA版本 11.3 编译器版本 GCC 9.3 ------------------------------ mmsegmentation版本 1.0.0 ==============================
5. 设置 Matplotlib 中文显示 #
# 找到 Matplotlib 的安装位置
import matplotlib
print(matplotlib.__file__)
/environment/miniconda3/lib/python3.7/site-packages/matplotlib/__init__.py
# 然后在命令行中将 SimHei.ttf 移入上述路径的 matplotlib/mpl-data/fonts/ttf/ 中。
# wget https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20220716-mmclassification/dataset/SimHei.ttf
# 设置中文字体并显示
import matplotlib
import matplotlib.pyplot as plt
matplotlib.rc("font",family='SimHei') # 中文字体
plt.plot([1,2,3], [100,500,300])
plt.title('matplotlib中文字体测试', fontsize=25)
plt.xlabel('X轴', fontsize=15)
plt.ylabel('Y轴', fontsize=15)
plt.show()
二、准备数据集 #
1. 获取数据集(已准备好) #
# 确认当前路径
os.getcwd()
'/home/featurize/data/mmsegmentation'
# 下载数据集
!wget https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20230130-mmseg/dataset/watermelon/Watermelon87_Semantic_Seg_Mask.zip
# 完成后重命名:mv Watermelon87_Semantic_Seg_Mask watermelon-dataset
--2023-06-17 19:20:18-- https://zihao-openmmlab.obs.cn-east-3.myhuaweicloud.com/20230130-mmseg/dataset/watermelon/Watermelon87_Semantic_Seg_Mask.zip 正在连接 172.16.0.13:5848... 已连接。 已发出 Proxy 请求,正在等待回应... 200 OK 长度: 13230222 (13M) [application/zip] 正在保存至: “Watermelon87_Semantic_Seg_Mask.zip” Watermelon87_Semant 100%[===================>] 12.62M 26.8MB/s 用时 0.5s 2023-06-17 19:20:19 (26.8 MB/s) - 已保存 “Watermelon87_Semantic_Seg_Mask.zip” [13230222/13230222])
2. 可视化探索数据集 #
# 导入相关库
import os
import cv2
import numpy as np
from PIL import Image
from tqdm import tqdm
import matplotlib.pyplot as plt
%matplotlib inline
# 指定图像和标注路径
# 提前修改好 21746 和 01bd155 两张图片的名称,使之对应
PATH_IMAGE = 'watermelon-dataset/img_dir/train'
PATH_MASKS = 'watermelon-dataset/ann_dir/train'
# n行n列可视化
n = 3
# 标注区域透明度
opacity = 0.5
fig, axes = plt.subplots(nrows=n, ncols=n, sharex=True, figsize=(12,12))
for i, file_name in enumerate(os.listdir(PATH_IMAGE)[:n**2]):
# 载入图像和标注
img_path = os.path.join(PATH_IMAGE, file_name)
mask_path = os.path.join(PATH_MASKS, file_name.split('.')[0]+'.png')
img = cv2.imread(img_path)
mask = cv2.imread(mask_path)
# 可视化
axes[i//n, i%n].imshow(img)
axes[i//n, i%n].imshow(mask[:,:,0], alpha=opacity)
axes[i//n, i%n].axis('off') # 关闭坐标轴显示
matplotlib.rc("font",family='SimHei') # 中文字体
fig.suptitle('可视化西瓜数据集', fontsize=30)
plt.tight_layout()
plt.show()
三、配置文件 #
1. 导入依赖库 #
import numpy as np
from PIL import Image
import os.path as osp
from tqdm import tqdm
import mmcv
import mmengine
import matplotlib.pyplot as plt
%matplotlib inline
2. 定义数据集类(各类别名称及配色) #
mmseg/datasets/WatermelonDataset.py
from mmseg.registry import DATASETS
from .basesegdataset import BaseSegDataset
@DATASETS.register_module()
class WatermelonDataset(BaseSegDataset):
# 类别和对应的可视化配色
METAINFO = {
'classes':['red', 'green', 'white', 'seed-black', 'seed-white', 'Unlabeled'],
'palette':[[255, 75, 104], [100, 245, 141], [251, 255, 163], [0, 65, 130], [17, 141, 240], [63, 193, 201]]
}
# 指定图像扩展名、标注扩展名
def __init__(self,
img_suffix='.jpg',
seg_map_suffix='.png',
reduce_zero_label=False, # 类别ID为0的类别是否需要除去
**kwargs) -> None:
super().__init__(
img_suffix=img_suffix,
seg_map_suffix=seg_map_suffix,
reduce_zero_label=reduce_zero_label,
**kwargs)
3. 注册数据类 #
在 mmseg/datasets/__init__.py
中添加以下内容:
from .WatermelonDataset import WatermelonDataset
以及:
'WatermelonDataset'
内容如下(仅修改#26,#61):
# Copyright (c) OpenMMLab. All rights reserved. <span id="CopyrightcOpenMMLabAllrightsreserved" style="position: relative; top: -100px;"></span><a class="anchor-link" href="#CopyrightcOpenMMLabAllrightsreserved">#</a>
# yapf: disable <span id="yapf:disable" style="position: relative; top: -100px;"></span><a class="anchor-link" href="#yapf:disable">#</a>
from .ade import ADE20KDataset
from .basesegdataset import BaseCDDataset, BaseSegDataset
from .chase_db1 import ChaseDB1Dataset
from .cityscapes import CityscapesDataset
from .coco_stuff import COCOStuffDataset
from .dark_zurich import DarkZurichDataset
from .dataset_wrappers import MultiImageMixDataset
from .decathlon import DecathlonDataset
from .drive import DRIVEDataset
from .dsdl import DSDLSegDataset
from .hrf import HRFDataset
from .isaid import iSAIDDataset
from .isprs import ISPRSDataset
from .levir import LEVIRCDDataset
from .lip import LIPDataset
from .loveda import LoveDADataset
from .mapillary import MapillaryDataset_v1, MapillaryDataset_v2
from .night_driving import NightDrivingDataset
from .pascal_context import PascalContextDataset, PascalContextDataset59
from .potsdam import PotsdamDataset
from .refuge import REFUGEDataset
from .stare import STAREDataset
from .synapse import SynapseDataset
from .WatermelonDataset import WatermelonDataset
# yapf: disable <span id="yapf:disable" style="position: relative; top: -100px;"></span><a class="anchor-link" href="#yapf:disable">#</a>
from .transforms import (CLAHE, AdjustGamma, Albu, BioMedical3DPad,
BioMedical3DRandomCrop, BioMedical3DRandomFlip,
BioMedicalGaussianBlur, BioMedicalGaussianNoise,
BioMedicalRandomGamma, ConcatCDInput, GenerateEdge,
LoadAnnotations, LoadBiomedicalAnnotation,
LoadBiomedicalData, LoadBiomedicalImageFromFile,
LoadImageFromNDArray, LoadMultipleRSImageFromFile,
LoadSingleRSImageFromFile, PackSegInputs,
PhotoMetricDistortion, RandomCrop, RandomCutOut,
RandomMosaic, RandomRotate, RandomRotFlip, Rerange,
ResizeShortestEdge, ResizeToMultiple, RGB2Gray,
SegRescale)
from .voc import PascalVOCDataset
# yapf: enable <span id="yapf:enable" style="position: relative; top: -100px;"></span><a class="anchor-link" href="#yapf:enable">#</a>
__all__ = [
'BaseSegDataset', 'BioMedical3DRandomCrop', 'BioMedical3DRandomFlip',
'CityscapesDataset', 'PascalVOCDataset', 'ADE20KDataset',
'PascalContextDataset', 'PascalContextDataset59', 'ChaseDB1Dataset',
'DRIVEDataset', 'HRFDataset', 'STAREDataset', 'DarkZurichDataset',
'NightDrivingDataset', 'COCOStuffDataset', 'LoveDADataset',
'MultiImageMixDataset', 'iSAIDDataset', 'ISPRSDataset', 'PotsdamDataset',
'LoadAnnotations', 'RandomCrop', 'SegRescale', 'PhotoMetricDistortion',
'RandomRotate', 'AdjustGamma', 'CLAHE', 'Rerange', 'RGB2Gray',
'RandomCutOut', 'RandomMosaic', 'PackSegInputs', 'ResizeToMultiple',
'LoadImageFromNDArray', 'LoadBiomedicalImageFromFile',
'LoadBiomedicalAnnotation', 'LoadBiomedicalData', 'GenerateEdge',
'DecathlonDataset', 'LIPDataset', 'ResizeShortestEdge',
'BioMedicalGaussianNoise', 'BioMedicalGaussianBlur',
'BioMedicalRandomGamma', 'BioMedical3DPad', 'RandomRotFlip',
'SynapseDataset', 'REFUGEDataset', 'MapillaryDataset_v1',
'MapillaryDataset_v2', 'Albu', 'LEVIRCDDataset',
'LoadMultipleRSImageFromFile', 'LoadSingleRSImageFromFile',
'ConcatCDInput', 'BaseCDDataset', 'DSDLSegDataset', 'WatermelonDataset'
]
4. 定义训练及测试 pipeline #
创建文件configs/_base_/datasets/WatermelonDataset.py
,仅修改数据类名和数据集路径(#2, #3):
# dataset settings <span id="datasetsettings" style="position: relative; top: -100px;"></span><a class="anchor-link" href="#datasetsettings">#</a>
dataset_type = 'WatermelonDataset' # 数据集类名
data_root = 'watermelon-dataset/' # 数据集路径(相对于mmsegmentation主目录)
crop_size = (64, 64)
train_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='LoadAnnotations'),
dict(
type='RandomResize',
scale=(2048, 1024),
ratio_range=(0.5, 2.0),
keep_ratio=True),
dict(type='RandomCrop', crop_size=crop_size, cat_max_ratio=0.75),
dict(type='RandomFlip', prob=0.5),
dict(type='PhotoMetricDistortion'),
dict(type='PackSegInputs')
]
test_pipeline = [
dict(type='LoadImageFromFile'),
dict(type='Resize', scale=(2048, 1024), keep_ratio=True),
# add loading annotation after ``Resize`` because ground truth
# does not need to do resize data transform
dict(type='LoadAnnotations'),
dict(type='PackSegInputs')
]
img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75]
tta_pipeline = [
dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')),
dict(
type='TestTimeAug',
transforms=[
[
dict(type='Resize', scale_factor=r, keep_ratio=True)
for r in img_ratios
],
[
dict(type='RandomFlip', prob=0., direction='horizontal'),
dict(type='RandomFlip', prob=1., direction='horizontal')
], [dict(type='LoadAnnotations')], [dict(type='PackSegInputs')]
])
]
train_dataloader = dict(
batch_size=2,
num_workers=2,
persistent_workers=True,
sampler=dict(type='InfiniteSampler', shuffle=True),
dataset=dict(
type=dataset_type,
data_root=data_root,
data_prefix=dict(
img_path='img_dir/train', seg_map_path='ann_dir/train'),
pipeline=train_pipeline))
val_dataloader = dict(
batch_size=1,
num_workers=4,
persistent_workers=True,
sampler=dict(type='DefaultSampler', shuffle=False),
dataset=dict(
type=dataset_type,
data_root=data_root,
data_prefix=dict(
img_path='img_dir/val', seg_map_path='ann_dir/val'),
pipeline=test_pipeline))
test_dataloader = val_dataloader
val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU'])
test_evaluator = val_evaluator
5. 修改配置文件 #
创建配置文件configs/pspnet/pspnet_r50-d8_4xb2-40k_WatermelonDataset.py
,内容如下:
_base_ = [
'../_base_/models/pspnet_r50-d8.py', '../_base_/datasets/WatermelonDataset_pipeline.py',
'../_base_/default_runtime.py', '../_base_/schedules/schedule_40k.py'
]
crop_size = (64, 64) # 输入图像尺寸,根据自己数据集情况修改
data_preprocessor = dict(size=crop_size)
model = dict(data_preprocessor=data_preprocessor)
6. 载入并修改配置文件 #
from mmengine import Config
cfg = Config.fromfile('configs/pspnet/pspnet_r50-d8_4xb2-40k_WatermelonDataset.py')
cfg.norm_cfg = dict(type='BN', requires_grad=True) # 只使用GPU时,BN取代SyncBN
cfg.crop_size = (256, 256)
cfg.model.data_preprocessor.size = cfg.crop_size
cfg.model.backbone.norm_cfg = cfg.norm_cfg
cfg.model.decode_head.norm_cfg = cfg.norm_cfg
cfg.model.auxiliary_head.norm_cfg = cfg.norm_cfg
# modify num classes of the model in decode/auxiliary head
# 模型 decode/auxiliary 输出头,指定为类别个数
cfg.model.decode_head.num_classes = 6
cfg.model.auxiliary_head.num_classes = 6
cfg.train_dataloader.batch_size = 8
cfg.test_dataloader = cfg.val_dataloader
# 结果保存目录
cfg.work_dir = './work_dirs/WatermelonDataset'
# 训练迭代次数
cfg.train_cfg.max_iters = 3000
# 评估模型间隔
cfg.train_cfg.val_interval = 400
# 日志记录间隔
cfg.default_hooks.logger.interval = 100
# 模型权重保存间隔
cfg.default_hooks.checkpoint.interval = 1500
# 随机数种子
cfg['randomness'] = dict(seed=0)
# 查看完整配置文件
print(cfg.pretty_text)
norm_cfg = dict(type='BN', requires_grad=True) data_preprocessor = dict( type='SegDataPreProcessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True, pad_val=0, seg_pad_val=255, size=(64, 64)) model = dict( type='EncoderDecoder', data_preprocessor=dict( type='SegDataPreProcessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True, pad_val=0, seg_pad_val=255, size=(256, 256)), pretrained='open-mmlab://resnet50_v1c', backbone=dict( type='ResNetV1c', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), dilations=(1, 1, 2, 4), strides=(1, 2, 1, 1), norm_cfg=dict(type='BN', requires_grad=True), norm_eval=False, style='pytorch', contract_dilation=True), decode_head=dict( type='PSPHead', in_channels=2048, in_index=3, channels=512, pool_scales=(1, 2, 3, 6), dropout_ratio=0.1, num_classes=6, norm_cfg=dict(type='BN', requires_grad=True), align_corners=False, loss_decode=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), auxiliary_head=dict( type='FCNHead', in_channels=1024, in_index=2, channels=256, num_convs=1, concat_input=False, dropout_ratio=0.1, num_classes=6, norm_cfg=dict(type='BN', requires_grad=True), align_corners=False, loss_decode=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), train_cfg=dict(), test_cfg=dict(mode='whole')) dataset_type = 'WatermelonDataset' data_root = 'watermelon-dataset/' crop_size = (256, 256) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), dict( type='RandomResize', scale=(2048, 1024), ratio_range=(0.5, 2.0), keep_ratio=True), dict(type='RandomCrop', crop_size=(64, 64), cat_max_ratio=0.75), dict(type='RandomFlip', prob=0.5), dict(type='PhotoMetricDistortion'), dict(type='PackSegInputs') ] test_pipeline = [ dict(type='LoadImageFromFile'), dict(type='Resize', scale=(2048, 1024), keep_ratio=True), dict(type='LoadAnnotations'), dict(type='PackSegInputs') ] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] tta_pipeline = [ dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')), dict( type='TestTimeAug', transforms=[[{ 'type': 'Resize', 'scale_factor': 0.5, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 0.75, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.0, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.25, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.5, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.75, 'keep_ratio': True }], [{ 'type': 'RandomFlip', 'prob': 0.0, 'direction': 'horizontal' }, { 'type': 'RandomFlip', 'prob': 1.0, 'direction': 'horizontal' }], [{ 'type': 'LoadAnnotations' }], [{ 'type': 'PackSegInputs' }]]) ] train_dataloader = dict( batch_size=8, num_workers=2, persistent_workers=True, sampler=dict(type='InfiniteSampler', shuffle=True), dataset=dict( type='WatermelonDataset', data_root='watermelon-dataset/', data_prefix=dict( img_path='img_dir/train', seg_map_path='ann_dir/train'), pipeline=[ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), dict( type='RandomResize', scale=(2048, 1024), ratio_range=(0.5, 2.0), keep_ratio=True), dict(type='RandomCrop', crop_size=(64, 64), cat_max_ratio=0.75), dict(type='RandomFlip', prob=0.5), dict(type='PhotoMetricDistortion'), dict(type='PackSegInputs') ])) val_dataloader = dict( batch_size=1, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='WatermelonDataset', data_root='watermelon-dataset/', data_prefix=dict(img_path='img_dir/val', seg_map_path='ann_dir/val'), pipeline=[ dict(type='LoadImageFromFile'), dict(type='Resize', scale=(2048, 1024), keep_ratio=True), dict(type='LoadAnnotations'), dict(type='PackSegInputs') ])) test_dataloader = dict( batch_size=1, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='WatermelonDataset', data_root='watermelon-dataset/', data_prefix=dict(img_path='img_dir/val', seg_map_path='ann_dir/val'), pipeline=[ dict(type='LoadImageFromFile'), dict(type='Resize', scale=(2048, 1024), keep_ratio=True), dict(type='LoadAnnotations'), dict(type='PackSegInputs') ])) val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU']) test_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU']) default_scope = 'mmseg' env_cfg = dict( cudnn_benchmark=True, mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0), dist_cfg=dict(backend='nccl')) vis_backends = [dict(type='LocalVisBackend')] visualizer = dict( type='SegLocalVisualizer', vis_backends=[dict(type='LocalVisBackend')], name='visualizer') log_processor = dict(by_epoch=False) log_level = 'INFO' load_from = None resume = False tta_model = dict(type='SegTTAModel') optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005) optim_wrapper = dict( type='OptimWrapper', optimizer=dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005), clip_grad=None) param_scheduler = [ dict( type='PolyLR', eta_min=0.0001, power=0.9, begin=0, end=40000, by_epoch=False) ] train_cfg = dict(type='IterBasedTrainLoop', max_iters=3000, val_interval=400) val_cfg = dict(type='ValLoop') test_cfg = dict(type='TestLoop') default_hooks = dict( timer=dict(type='IterTimerHook'), logger=dict(type='LoggerHook', interval=100, log_metric_by_epoch=False), param_scheduler=dict(type='ParamSchedulerHook'), checkpoint=dict(type='CheckpointHook', by_epoch=False, interval=1500), sampler_seed=dict(type='DistSamplerSeedHook'), visualization=dict(type='SegVisualizationHook')) work_dir = './work_dirs/WatermelonDataset' randomness = dict(seed=0)
# 保存配置文件(保存到了 mmsegmentation 路径下)
cfg.dump('pspnet-WatermelonDataset_final.py')
四、训练模型 #
# 检查当前路径
os.getcwd()
'/home/featurize/data/mmsegmentation'
1. 导入工具包 #
import numpy as np
import os.path as osp
from tqdm import tqdm
import mmcv
import mmengine
2. 载入配置文件并准备训练 #
from mmengine import Config
from mmengine.runner import Runner
from mmseg.utils import register_all_modules
# 载入配置
cfg = Config.fromfile('pspnet-WatermelonDataset_final.py')
# register all modules in mmseg into the registries
# do not init the default scope here because it will be init in the runner
register_all_modules(init_default_scope=False)
runner = Runner.from_cfg(cfg)
06/17 21:06:20 - mmengine - [4m[37mINFO[0m - ------------------------------------------------------------ System environment: sys.platform: linux Python: 3.7.10 (default, Jun 4 2021, 14:48:32) [GCC 7.5.0] CUDA available: True numpy_random_seed: 0 GPU 0: NVIDIA GeForce RTX 3060 CUDA_HOME: /usr/local/cuda NVCC: Cuda compilation tools, release 11.2, V11.2.152 GCC: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 PyTorch: 1.10.1+cu113 PyTorch compiling details: PyTorch built with: - GCC 7.3 - C++ Version: 201402 - Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications - Intel(R) MKL-DNN v2.2.3 (Git Hash 7336ca9f055cf1bfa13efb658fe15dc9b41f0740) - OpenMP 201511 (a.k.a. OpenMP 4.5) - LAPACK is enabled (usually provided by MKL) - NNPACK is enabled - CPU capability usage: AVX2 - CUDA Runtime 11.3 - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86 - CuDNN 8.2 - Magma 2.5.2 - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.3, CUDNN_VERSION=8.2.0, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.10.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, TorchVision: 0.11.2+cu113 OpenCV: 4.5.4 MMEngine: 0.7.4 Runtime environment: cudnn_benchmark: True mp_cfg: {'mp_start_method': 'fork', 'opencv_num_threads': 0} dist_cfg: {'backend': 'nccl'} seed: 0 Distributed launcher: none Distributed training: False GPU number: 1 ------------------------------------------------------------ 06/17 21:06:20 - mmengine - [4m[37mINFO[0m - Config: norm_cfg = dict(type='BN', requires_grad=True) data_preprocessor = dict( type='SegDataPreProcessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True, pad_val=0, seg_pad_val=255, size=(64, 64)) model = dict( type='EncoderDecoder', data_preprocessor=dict( type='SegDataPreProcessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True, pad_val=0, seg_pad_val=255, size=(256, 256)), pretrained='open-mmlab://resnet50_v1c', backbone=dict( type='ResNetV1c', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), dilations=(1, 1, 2, 4), strides=(1, 2, 1, 1), norm_cfg=dict(type='BN', requires_grad=True), norm_eval=False, style='pytorch', contract_dilation=True), decode_head=dict( type='PSPHead', in_channels=2048, in_index=3, channels=512, pool_scales=(1, 2, 3, 6), dropout_ratio=0.1, num_classes=6, norm_cfg=dict(type='BN', requires_grad=True), align_corners=False, loss_decode=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), auxiliary_head=dict( type='FCNHead', in_channels=1024, in_index=2, channels=256, num_convs=1, concat_input=False, dropout_ratio=0.1, num_classes=6, norm_cfg=dict(type='BN', requires_grad=True), align_corners=False, loss_decode=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), train_cfg=dict(), test_cfg=dict(mode='whole')) dataset_type = 'WatermelonDataset' data_root = 'watermelon-dataset/' crop_size = (256, 256) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), dict( type='RandomResize', scale=(2048, 1024), ratio_range=(0.5, 2.0), keep_ratio=True), dict(type='RandomCrop', crop_size=(64, 64), cat_max_ratio=0.75), dict(type='RandomFlip', prob=0.5), dict(type='PhotoMetricDistortion'), dict(type='PackSegInputs') ] test_pipeline = [ dict(type='LoadImageFromFile'), dict(type='Resize', scale=(2048, 1024), keep_ratio=True), dict(type='LoadAnnotations'), dict(type='PackSegInputs') ] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] tta_pipeline = [ dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')), dict( type='TestTimeAug', transforms=[[{ 'type': 'Resize', 'scale_factor': 0.5, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 0.75, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.0, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.25, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.5, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.75, 'keep_ratio': True }], [{ 'type': 'RandomFlip', 'prob': 0.0, 'direction': 'horizontal' }, { 'type': 'RandomFlip', 'prob': 1.0, 'direction': 'horizontal' }], [{ 'type': 'LoadAnnotations' }], [{ 'type': 'PackSegInputs' }]]) ] train_dataloader = dict( batch_size=8, num_workers=2, persistent_workers=True, sampler=dict(type='InfiniteSampler', shuffle=True), dataset=dict( type='WatermelonDataset', data_root='watermelon-dataset/', data_prefix=dict( img_path='img_dir/train', seg_map_path='ann_dir/train'), pipeline=[ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), dict( type='RandomResize', scale=(2048, 1024), ratio_range=(0.5, 2.0), keep_ratio=True), dict(type='RandomCrop', crop_size=(64, 64), cat_max_ratio=0.75), dict(type='RandomFlip', prob=0.5), dict(type='PhotoMetricDistortion'), dict(type='PackSegInputs') ])) val_dataloader = dict( batch_size=1, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='WatermelonDataset', data_root='watermelon-dataset/', data_prefix=dict(img_path='img_dir/val', seg_map_path='ann_dir/val'), pipeline=[ dict(type='LoadImageFromFile'), dict(type='Resize', scale=(2048, 1024), keep_ratio=True), dict(type='LoadAnnotations'), dict(type='PackSegInputs') ])) test_dataloader = dict( batch_size=1, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='WatermelonDataset', data_root='watermelon-dataset/', data_prefix=dict(img_path='img_dir/val', seg_map_path='ann_dir/val'), pipeline=[ dict(type='LoadImageFromFile'), dict(type='Resize', scale=(2048, 1024), keep_ratio=True), dict(type='LoadAnnotations'), dict(type='PackSegInputs') ])) val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU']) test_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU']) default_scope = 'mmseg' env_cfg = dict( cudnn_benchmark=True, mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0), dist_cfg=dict(backend='nccl')) vis_backends = [dict(type='LocalVisBackend')] visualizer = dict( type='SegLocalVisualizer', vis_backends=[dict(type='LocalVisBackend')], name='visualizer') log_processor = dict(by_epoch=False) log_level = 'INFO' load_from = None resume = False tta_model = dict(type='SegTTAModel') optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005) optim_wrapper = dict( type='OptimWrapper', optimizer=dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005), clip_grad=None) param_scheduler = [ dict( type='PolyLR', eta_min=0.0001, power=0.9, begin=0, end=40000, by_epoch=False) ] train_cfg = dict(type='IterBasedTrainLoop', max_iters=3000, val_interval=400) val_cfg = dict(type='ValLoop') test_cfg = dict(type='TestLoop') default_hooks = dict( timer=dict(type='IterTimerHook'), logger=dict(type='LoggerHook', interval=100, log_metric_by_epoch=False), param_scheduler=dict(type='ParamSchedulerHook'), checkpoint=dict(type='CheckpointHook', by_epoch=False, interval=1500), sampler_seed=dict(type='DistSamplerSeedHook'), visualization=dict(type='SegVisualizationHook')) work_dir = './work_dirs/WatermelonDataset' randomness = dict(seed=0)
/home/featurize/data/mmsegmentation/mmseg/models/backbones/resnet.py:431: UserWarning: DeprecationWarning: pretrained is a deprecated, please use "init_cfg" instead warnings.warn('DeprecationWarning: pretrained is a deprecated, ' /home/featurize/data/mmsegmentation/mmseg/models/builder.py:36: UserWarning: ``build_loss`` would be deprecated soon, please use ``mmseg.registry.MODELS.build()`` warnings.warn('``build_loss`` would be deprecated soon, please use ' /home/featurize/data/mmsegmentation/mmseg/models/losses/cross_entropy_loss.py:236: UserWarning: Default ``avg_non_ignore`` is False, if you would like to ignore the certain label and average loss over non-ignore labels, which is the same with PyTorch official cross_entropy, set ``avg_non_ignore=True``. 'Default ``avg_non_ignore`` is False, if you would like to '
06/17 21:06:27 - mmengine - [4m[37mINFO[0m - Distributed training is not used, all SyncBatchNorm (SyncBN) layers in the model will be automatically reverted to BatchNormXd layers if they are used. 06/17 21:06:27 - mmengine - [4m[37mINFO[0m - Hooks will be executed in the following order: before_run: (VERY_HIGH ) RuntimeInfoHook (BELOW_NORMAL) LoggerHook -------------------- before_train: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (VERY_LOW ) CheckpointHook -------------------- before_train_epoch: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (NORMAL ) DistSamplerSeedHook -------------------- before_train_iter: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook -------------------- after_train_iter: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (NORMAL ) SegVisualizationHook (BELOW_NORMAL) LoggerHook (LOW ) ParamSchedulerHook (VERY_LOW ) CheckpointHook -------------------- after_train_epoch: (NORMAL ) IterTimerHook (LOW ) ParamSchedulerHook (VERY_LOW ) CheckpointHook -------------------- before_val_epoch: (NORMAL ) IterTimerHook -------------------- before_val_iter: (NORMAL ) IterTimerHook -------------------- after_val_iter: (NORMAL ) IterTimerHook (NORMAL ) SegVisualizationHook (BELOW_NORMAL) LoggerHook -------------------- after_val_epoch: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (BELOW_NORMAL) LoggerHook (LOW ) ParamSchedulerHook (VERY_LOW ) CheckpointHook -------------------- after_train: (VERY_LOW ) CheckpointHook -------------------- before_test_epoch: (NORMAL ) IterTimerHook -------------------- before_test_iter: (NORMAL ) IterTimerHook -------------------- after_test_iter: (NORMAL ) IterTimerHook (NORMAL ) SegVisualizationHook (BELOW_NORMAL) LoggerHook -------------------- after_test_epoch: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (BELOW_NORMAL) LoggerHook -------------------- after_run: (BELOW_NORMAL) LoggerHook --------------------
/home/featurize/data/mmsegmentation/mmseg/engine/hooks/visualization_hook.py:61: UserWarning: The draw is False, it means that the hook for visualization will not take effect. The results will NOT be visualized or stored. warnings.warn('The draw is False, it means that the '
3. 开始训练 #
runner.train()
06/17 21:08:21 - mmengine - [5m[4m[33mWARNING[0m - The prefix is not set in metric class IoUMetric. 06/17 21:08:22 - mmengine - [4m[37mINFO[0m - load model from: open-mmlab://resnet50_v1c 06/17 21:08:22 - mmengine - [4m[37mINFO[0m - Loads checkpoint by openmmlab backend from path: open-mmlab://resnet50_v1c
Downloading: "https://download.openmmlab.com/pretrain/third_party/resnet50_v1c-2cccc1ad.pth" to /home/featurize/.cache/torch/hub/checkpoints/resnet50_v1c-2cccc1ad.pth
06/17 21:08:32 - mmengine - [5m[4m[33mWARNING[0m - The model and loaded state dict do not match exactly unexpected key in source state_dict: fc.weight, fc.bias 06/17 21:08:32 - mmengine - [5m[4m[33mWARNING[0m - "FileClient" will be deprecated in future. Please use io functions in https://mmengine.readthedocs.io/en/latest/api/fileio.html#file-io 06/17 21:08:32 - mmengine - [5m[4m[33mWARNING[0m - "HardDiskBackend" is the alias of "LocalBackend" and the former will be deprecated in future. 06/17 21:08:32 - mmengine - [4m[37mINFO[0m - Checkpoints will be saved to /home/featurize/data/mmsegmentation/work_dirs/WatermelonDataset. 06/17 21:08:36 - mmengine - [4m[37mINFO[0m - Exp name: pspnet-WatermelonDataset_final_20230617_210619 06/17 21:08:36 - mmengine - [4m[37mINFO[0m - Iter(train) [ 6/3000] lr: 9.9989e-03 eta: 0:34:15 time: 0.6866 data_time: 0.0152 memory: 5948 loss: 0.1536 decode.loss_ce: 0.1077 decode.acc_seg: 27.1912 aux.loss_ce: 0.0460 aux.acc_seg: 21.8109 06/17 21:09:07 - mmengine - [4m[37mINFO[0m - Iter(train) [ 100/3000] lr: 9.9779e-03 eta: 0:17:02 time: 0.3302 data_time: 0.0090 memory: 3774 loss: 0.0706 decode.loss_ce: 0.0483 decode.acc_seg: 81.8878 aux.loss_ce: 0.0222 aux.acc_seg: 76.5259 06/17 21:09:40 - mmengine - [4m[37mINFO[0m - Iter(train) [ 200/3000] lr: 9.9557e-03 eta: 0:15:56 time: 0.3295 data_time: 0.0097 memory: 3774 loss: 0.0713 decode.loss_ce: 0.0494 decode.acc_seg: 82.7423 aux.loss_ce: 0.0219 aux.acc_seg: 69.0582 06/17 21:10:13 - mmengine - [4m[37mINFO[0m - Iter(train) [ 300/3000] lr: 9.9334e-03 eta: 0:15:12 time: 0.3315 data_time: 0.0102 memory: 3774 loss: 0.0564 decode.loss_ce: 0.0389 decode.acc_seg: 77.0233 aux.loss_ce: 0.0174 aux.acc_seg: 77.9724 06/17 21:10:46 - mmengine - [4m[37mINFO[0m - Iter(train) [ 400/3000] lr: 9.9111e-03 eta: 0:14:33 time: 0.3295 data_time: 0.0097 memory: 3774 loss: 0.0673 decode.loss_ce: 0.0476 decode.acc_seg: 84.5245 aux.loss_ce: 0.0197 aux.acc_seg: 81.3538 06/17 21:10:57 - mmengine - [4m[37mINFO[0m - per class results: 06/17 21:10:57 - mmengine - [4m[37mINFO[0m - +------------+-------+-------+ | Class | IoU | Acc | +------------+-------+-------+ | red | 74.79 | 92.17 | | green | 66.5 | 75.04 | | white | 30.13 | 37.06 | | seed-black | 41.89 | 46.37 | | seed-white | 44.74 | 61.28 | | Unlabeled | 0.0 | 0.0 | +------------+-------+-------+ 06/17 21:10:57 - mmengine - [4m[37mINFO[0m - Iter(val) [11/11] aAcc: 80.3700 mIoU: 43.0100 mAcc: 51.9900 data_time: 0.0322 time: 1.0240 06/17 21:11:31 - mmengine - [4m[37mINFO[0m - Iter(train) [ 500/3000] lr: 9.8888e-03 eta: 0:13:57 time: 0.3313 data_time: 0.0105 memory: 5198 loss: 0.0515 decode.loss_ce: 0.0368 decode.acc_seg: 79.1077 aux.loss_ce: 0.0148 aux.acc_seg: 81.0577 06/17 21:12:04 - mmengine - [4m[37mINFO[0m - Iter(train) [ 600/3000] lr: 9.8665e-03 eta: 0:13:22 time: 0.3327 data_time: 0.0117 memory: 3774 loss: 0.0491 decode.loss_ce: 0.0351 decode.acc_seg: 81.3477 aux.loss_ce: 0.0140 aux.acc_seg: 83.2916 06/17 21:12:37 - mmengine - [4m[37mINFO[0m - Iter(train) [ 700/3000] lr: 9.8442e-03 eta: 0:12:47 time: 0.3271 data_time: 0.0088 memory: 3774 loss: 0.0443 decode.loss_ce: 0.0313 decode.acc_seg: 89.9780 aux.loss_ce: 0.0130 aux.acc_seg: 88.7085 06/17 21:13:10 - mmengine - [4m[37mINFO[0m - Iter(train) [ 800/3000] lr: 9.8218e-03 eta: 0:12:12 time: 0.3318 data_time: 0.0107 memory: 3774 loss: 0.0390 decode.loss_ce: 0.0269 decode.acc_seg: 79.7882 aux.loss_ce: 0.0121 aux.acc_seg: 81.7810 06/17 21:13:12 - mmengine - [4m[37mINFO[0m - per class results: 06/17 21:13:12 - mmengine - [4m[37mINFO[0m - +------------+-------+-------+ | Class | IoU | Acc | +------------+-------+-------+ | red | 80.43 | 88.33 | | green | 74.13 | 90.42 | | white | 62.59 | 77.05 | | seed-black | 52.34 | 57.11 | | seed-white | 49.89 | 82.3 | | Unlabeled | 0.0 | 0.0 | +------------+-------+-------+ 06/17 21:13:12 - mmengine - [4m[37mINFO[0m - Iter(val) [11/11] aAcc: 85.7800 mIoU: 53.2300 mAcc: 65.8700 data_time: 0.0092 time: 0.2328 06/17 21:13:45 - mmengine - [4m[37mINFO[0m - Iter(train) [ 900/3000] lr: 9.7995e-03 eta: 0:11:38 time: 0.3317 data_time: 0.0120 memory: 3774 loss: 0.0388 decode.loss_ce: 0.0270 decode.acc_seg: 88.9923 aux.loss_ce: 0.0118 aux.acc_seg: 85.3424 06/17 21:14:18 - mmengine - [4m[37mINFO[0m - Exp name: pspnet-WatermelonDataset_final_20230617_210619 06/17 21:14:18 - mmengine - [4m[37mINFO[0m - Iter(train) [1000/3000] lr: 9.7772e-03 eta: 0:11:05 time: 0.3283 data_time: 0.0092 memory: 3774 loss: 0.0430 decode.loss_ce: 0.0301 decode.acc_seg: 78.1036 aux.loss_ce: 0.0129 aux.acc_seg: 76.7731 06/17 21:14:51 - mmengine - [4m[37mINFO[0m - Iter(train) [1100/3000] lr: 9.7549e-03 eta: 0:10:31 time: 0.3296 data_time: 0.0102 memory: 3774 loss: 0.0339 decode.loss_ce: 0.0237 decode.acc_seg: 95.1080 aux.loss_ce: 0.0102 aux.acc_seg: 93.9423 06/17 21:15:24 - mmengine - [4m[37mINFO[0m - Iter(train) [1200/3000] lr: 9.7325e-03 eta: 0:09:57 time: 0.3303 data_time: 0.0108 memory: 3774 loss: 0.0433 decode.loss_ce: 0.0298 decode.acc_seg: 87.6892 aux.loss_ce: 0.0134 aux.acc_seg: 88.0310 06/17 21:15:27 - mmengine - [4m[37mINFO[0m - per class results: 06/17 21:15:27 - mmengine - [4m[37mINFO[0m - +------------+-------+-------+ | Class | IoU | Acc | +------------+-------+-------+ | red | 77.47 | 96.41 | | green | 74.31 | 81.12 | | white | 5.51 | 5.59 | | seed-black | 48.27 | 51.45 | | seed-white | 43.11 | 44.44 | | Unlabeled | 0.0 | 0.0 | +------------+-------+-------+ 06/17 21:15:27 - mmengine - [4m[37mINFO[0m - Iter(val) [11/11] aAcc: 82.5800 mIoU: 41.4500 mAcc: 46.5000 data_time: 0.0113 time: 0.2345 06/17 21:16:00 - mmengine - [4m[37mINFO[0m - Iter(train) [1300/3000] lr: 9.7102e-03 eta: 0:09:24 time: 0.3285 data_time: 0.0096 memory: 3774 loss: 0.0392 decode.loss_ce: 0.0277 decode.acc_seg: 69.6686 aux.loss_ce: 0.0115 aux.acc_seg: 70.0745 06/17 21:16:33 - mmengine - [4m[37mINFO[0m - Iter(train) [1400/3000] lr: 9.6878e-03 eta: 0:08:50 time: 0.3305 data_time: 0.0103 memory: 3774 loss: 0.0421 decode.loss_ce: 0.0299 decode.acc_seg: 73.8342 aux.loss_ce: 0.0122 aux.acc_seg: 77.5909 06/17 21:17:06 - mmengine - [4m[37mINFO[0m - Iter(train) [1500/3000] lr: 9.6655e-03 eta: 0:08:17 time: 0.3299 data_time: 0.0100 memory: 3774 loss: 0.0491 decode.loss_ce: 0.0347 decode.acc_seg: 70.8679 aux.loss_ce: 0.0144 aux.acc_seg: 71.0876 06/17 21:17:06 - mmengine - [4m[37mINFO[0m - Saving checkpoint at 1500 iterations 06/17 21:17:41 - mmengine - [4m[37mINFO[0m - Iter(train) [1600/3000] lr: 9.6431e-03 eta: 0:07:46 time: 0.3286 data_time: 0.0095 memory: 3774 loss: 0.0409 decode.loss_ce: 0.0283 decode.acc_seg: 86.9720 aux.loss_ce: 0.0126 aux.acc_seg: 87.4939 06/17 21:17:43 - mmengine - [4m[37mINFO[0m - per class results: 06/17 21:17:43 - mmengine - [4m[37mINFO[0m - +------------+-------+-------+ | Class | IoU | Acc | +------------+-------+-------+ | red | 81.48 | 92.86 | | green | 79.97 | 95.39 | | white | 5.59 | 5.91 | | seed-black | 61.64 | 64.72 | | seed-white | 50.04 | 87.74 | | Unlabeled | 0.0 | 0.0 | +------------+-------+-------+ 06/17 21:17:43 - mmengine - [4m[37mINFO[0m - Iter(val) [11/11] aAcc: 85.4600 mIoU: 46.4500 mAcc: 57.7700 data_time: 0.0095 time: 0.2334 06/17 21:18:17 - mmengine - [4m[37mINFO[0m - Iter(train) [1700/3000] lr: 9.6207e-03 eta: 0:07:12 time: 0.3325 data_time: 0.0104 memory: 3774 loss: 0.0488 decode.loss_ce: 0.0350 decode.acc_seg: 77.4078 aux.loss_ce: 0.0138 aux.acc_seg: 78.0792 06/17 21:18:50 - mmengine - [4m[37mINFO[0m - Iter(train) [1800/3000] lr: 9.5983e-03 eta: 0:06:39 time: 0.3322 data_time: 0.0101 memory: 3774 loss: 0.0370 decode.loss_ce: 0.0260 decode.acc_seg: 84.2041 aux.loss_ce: 0.0110 aux.acc_seg: 82.1930 06/17 21:19:23 - mmengine - [4m[37mINFO[0m - Iter(train) [1900/3000] lr: 9.5760e-03 eta: 0:06:05 time: 0.3316 data_time: 0.0104 memory: 3774 loss: 0.0333 decode.loss_ce: 0.0235 decode.acc_seg: 88.8306 aux.loss_ce: 0.0098 aux.acc_seg: 87.6831 06/17 21:19:56 - mmengine - [4m[37mINFO[0m - Exp name: pspnet-WatermelonDataset_final_20230617_210619 06/17 21:19:56 - mmengine - [4m[37mINFO[0m - Iter(train) [2000/3000] lr: 9.5536e-03 eta: 0:05:32 time: 0.3311 data_time: 0.0107 memory: 3774 loss: 0.0356 decode.loss_ce: 0.0250 decode.acc_seg: 82.6874 aux.loss_ce: 0.0106 aux.acc_seg: 82.1289 06/17 21:19:59 - mmengine - [4m[37mINFO[0m - per class results: 06/17 21:19:59 - mmengine - [4m[37mINFO[0m - +------------+-------+-------+ | Class | IoU | Acc | +------------+-------+-------+ | red | 80.2 | 91.54 | | green | 78.21 | 95.48 | | white | 13.36 | 14.53 | | seed-black | 53.67 | 57.64 | | seed-white | 57.53 | 60.2 | | Unlabeled | 0.0 | 0.0 | +------------+-------+-------+ 06/17 21:19:59 - mmengine - [4m[37mINFO[0m - Iter(val) [11/11] aAcc: 84.6500 mIoU: 47.1600 mAcc: 53.2300 data_time: 0.0117 time: 0.2352 06/17 21:20:32 - mmengine - [4m[37mINFO[0m - Iter(train) [2100/3000] lr: 9.5312e-03 eta: 0:04:59 time: 0.3294 data_time: 0.0096 memory: 3774 loss: 0.0375 decode.loss_ce: 0.0261 decode.acc_seg: 79.6356 aux.loss_ce: 0.0114 aux.acc_seg: 80.7739 06/17 21:21:05 - mmengine - [4m[37mINFO[0m - Iter(train) [2200/3000] lr: 9.5088e-03 eta: 0:04:25 time: 0.3294 data_time: 0.0101 memory: 3774 loss: 0.0407 decode.loss_ce: 0.0288 decode.acc_seg: 94.3726 aux.loss_ce: 0.0120 aux.acc_seg: 93.9697 06/17 21:21:38 - mmengine - [4m[37mINFO[0m - Iter(train) [2300/3000] lr: 9.4864e-03 eta: 0:03:52 time: 0.3295 data_time: 0.0100 memory: 3774 loss: 0.0429 decode.loss_ce: 0.0308 decode.acc_seg: 86.8317 aux.loss_ce: 0.0121 aux.acc_seg: 88.8153 06/17 21:22:11 - mmengine - [4m[37mINFO[0m - Iter(train) [2400/3000] lr: 9.4640e-03 eta: 0:03:19 time: 0.3296 data_time: 0.0099 memory: 3774 loss: 0.0288 decode.loss_ce: 0.0200 decode.acc_seg: 90.9119 aux.loss_ce: 0.0088 aux.acc_seg: 90.5823 06/17 21:22:13 - mmengine - [4m[37mINFO[0m - per class results: 06/17 21:22:13 - mmengine - [4m[37mINFO[0m - +------------+-------+-------+ | Class | IoU | Acc | +------------+-------+-------+ | red | 83.28 | 92.49 | | green | 82.17 | 98.5 | | white | 20.37 | 22.64 | | seed-black | 59.28 | 63.53 | | seed-white | 50.98 | 52.32 | | Unlabeled | 0.0 | 0.0 | +------------+-------+-------+ 06/17 21:22:13 - mmengine - [4m[37mINFO[0m - Iter(val) [11/11] aAcc: 86.9300 mIoU: 49.3500 mAcc: 54.9100 data_time: 0.0099 time: 0.2333 06/17 21:22:46 - mmengine - [4m[37mINFO[0m - Iter(train) [2500/3000] lr: 9.4416e-03 eta: 0:02:46 time: 0.3316 data_time: 0.0117 memory: 3774 loss: 0.0389 decode.loss_ce: 0.0276 decode.acc_seg: 84.8236 aux.loss_ce: 0.0113 aux.acc_seg: 83.3862 06/17 21:23:19 - mmengine - [4m[37mINFO[0m - Iter(train) [2600/3000] lr: 9.4191e-03 eta: 0:02:12 time: 0.3309 data_time: 0.0111 memory: 3774 loss: 0.0430 decode.loss_ce: 0.0305 decode.acc_seg: 89.4226 aux.loss_ce: 0.0125 aux.acc_seg: 89.4623 06/17 21:23:52 - mmengine - [4m[37mINFO[0m - Iter(train) [2700/3000] lr: 9.3967e-03 eta: 0:01:39 time: 0.3297 data_time: 0.0101 memory: 3774 loss: 0.0378 decode.loss_ce: 0.0270 decode.acc_seg: 85.2448 aux.loss_ce: 0.0109 aux.acc_seg: 84.7443 06/17 21:24:25 - mmengine - [4m[37mINFO[0m - Iter(train) [2800/3000] lr: 9.3743e-03 eta: 0:01:06 time: 0.3289 data_time: 0.0090 memory: 3774 loss: 0.0340 decode.loss_ce: 0.0231 decode.acc_seg: 78.6163 aux.loss_ce: 0.0109 aux.acc_seg: 77.5085 06/17 21:24:28 - mmengine - [4m[37mINFO[0m - per class results: 06/17 21:24:28 - mmengine - [4m[37mINFO[0m - +------------+-------+-------+ | Class | IoU | Acc | +------------+-------+-------+ | red | 86.48 | 96.63 | | green | 88.01 | 95.4 | | white | 26.87 | 28.53 | | seed-black | 70.4 | 74.97 | | seed-white | 61.92 | 74.47 | | Unlabeled | 1.73 | 1.73 | +------------+-------+-------+ 06/17 21:24:28 - mmengine - [4m[37mINFO[0m - Iter(val) [11/11] aAcc: 89.8600 mIoU: 55.9000 mAcc: 61.9600 data_time: 0.0103 time: 0.2338 06/17 21:25:01 - mmengine - [4m[37mINFO[0m - Iter(train) [2900/3000] lr: 9.3518e-03 eta: 0:00:33 time: 0.3310 data_time: 0.0105 memory: 3774 loss: 0.0409 decode.loss_ce: 0.0288 decode.acc_seg: 79.4647 aux.loss_ce: 0.0122 aux.acc_seg: 76.2573 06/17 21:25:34 - mmengine - [4m[37mINFO[0m - Exp name: pspnet-WatermelonDataset_final_20230617_210619 06/17 21:25:34 - mmengine - [4m[37mINFO[0m - Iter(train) [3000/3000] lr: 9.3294e-03 eta: 0:00:00 time: 0.3309 data_time: 0.0107 memory: 3774 loss: 0.0375 decode.loss_ce: 0.0274 decode.acc_seg: 89.7949 aux.loss_ce: 0.0100 aux.acc_seg: 88.6841 06/17 21:25:34 - mmengine - [4m[37mINFO[0m - Saving checkpoint at 3000 iterations
EncoderDecoder( (data_preprocessor): SegDataPreProcessor() (backbone): ResNetV1c( (stem): Sequential( (0): Conv2d(3, 32, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) (1): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (2): ReLU(inplace=True) (3): Conv2d(32, 32, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (4): BatchNorm2d(32, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (5): ReLU(inplace=True) (6): Conv2d(32, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (7): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (8): ReLU(inplace=True) ) (maxpool): MaxPool2d(kernel_size=3, stride=2, padding=1, dilation=1, ceil_mode=False) (layer1): ResLayer( (0): Bottleneck( (conv1): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) (downsample): Sequential( (0): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) ) ) (1): Bottleneck( (conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) (2): Bottleneck( (conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): BatchNorm2d(64, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) ) (layer2): ResLayer( (0): Bottleneck( (conv1): Conv2d(256, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(2, 2), padding=(1, 1), bias=False) (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) (downsample): Sequential( (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False) (1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) ) ) (1): Bottleneck( (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) (2): Bottleneck( (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) (3): Bottleneck( (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): BatchNorm2d(128, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) ) (layer3): ResLayer( (0): Bottleneck( (conv1): Conv2d(512, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) (downsample): Sequential( (0): Conv2d(512, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (1): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) ) ) (1): Bottleneck( (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False) (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) (2): Bottleneck( (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False) (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) (3): Bottleneck( (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False) (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) (4): Bottleneck( (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False) (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) (5): Bottleneck( (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False) (bn2): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(1024, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) ) (layer4): ResLayer( (0): Bottleneck( (conv1): Conv2d(1024, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(2, 2), dilation=(2, 2), bias=False) (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) (downsample): Sequential( (0): Conv2d(1024, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False) (1): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) ) ) (1): Bottleneck( (conv1): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(4, 4), dilation=(4, 4), bias=False) (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) (2): Bottleneck( (conv1): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv2): Conv2d(512, 512, kernel_size=(3, 3), stride=(1, 1), padding=(4, 4), dilation=(4, 4), bias=False) (bn2): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (conv3): Conv2d(512, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (relu): ReLU(inplace=True) ) ) ) init_cfg={'type': 'Pretrained', 'checkpoint': 'open-mmlab://resnet50_v1c'} (decode_head): PSPHead( input_transform=None, ignore_index=255, align_corners=False (loss_decode): CrossEntropyLoss(avg_non_ignore=False) (conv_seg): Conv2d(512, 6, kernel_size=(1, 1), stride=(1, 1)) (dropout): Dropout2d(p=0.1, inplace=False) (psp_modules): PPM( (0): Sequential( (0): AdaptiveAvgPool2d(output_size=1) (1): ConvModule( (conv): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (activate): ReLU(inplace=True) ) ) (1): Sequential( (0): AdaptiveAvgPool2d(output_size=2) (1): ConvModule( (conv): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (activate): ReLU(inplace=True) ) ) (2): Sequential( (0): AdaptiveAvgPool2d(output_size=3) (1): ConvModule( (conv): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (activate): ReLU(inplace=True) ) ) (3): Sequential( (0): AdaptiveAvgPool2d(output_size=6) (1): ConvModule( (conv): Conv2d(2048, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (activate): ReLU(inplace=True) ) ) ) (bottleneck): ConvModule( (conv): Conv2d(4096, 512, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn): BatchNorm2d(512, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (activate): ReLU(inplace=True) ) ) init_cfg={'type': 'Normal', 'std': 0.01, 'override': {'name': 'conv_seg'}} (auxiliary_head): FCNHead( input_transform=None, ignore_index=255, align_corners=False (loss_decode): CrossEntropyLoss(avg_non_ignore=False) (conv_seg): Conv2d(256, 6, kernel_size=(1, 1), stride=(1, 1)) (dropout): Dropout2d(p=0.1, inplace=False) (convs): Sequential( (0): ConvModule( (conv): Conv2d(1024, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn): BatchNorm2d(256, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True) (activate): ReLU(inplace=True) ) ) ) init_cfg={'type': 'Normal', 'std': 0.01, 'override': {'name': 'conv_seg'}} )
五、可视化训练日志 #
os.getcwd()
'/home/featurize/data/mmsegmentation'
1. 导入训练日志 #
import pandas as pd
import matplotlib.pyplot as plt
%matplotlib inline
# 日志文件路径
log_path = 'work_dirs/WatermelonDataset/20230617_210619/vis_data/scalars.json'
# 查看日志文件
with open(log_path, "r") as f:
json_list = f.readlines()
print(len(json_list))
print('-'*30)
eval(json_list[4])
38 ------------------------------
{'lr': 0.009911076035273796, 'data_time': 0.009708809852600097, 'loss': 0.06731528230011463, 'decode.loss_ce': 0.04762079007923603, 'decode.acc_seg': 84.5245361328125, 'aux.loss_ce': 0.019694492872804403, 'aux.acc_seg': 81.353759765625, 'time': 0.3294579267501831, 'iter': 400, 'memory': 3774, 'step': 400}
df_train = pd.DataFrame()
df_test = pd.DataFrame()
for each in json_list[:-1]:
if 'aAcc' in each:
df_test = df_test.append(eval(each), ignore_index=True)
else:
df_train = df_train.append(eval(each), ignore_index=True)
df_train
lr | data_time | loss | decode.loss_ce | decode.acc_seg | aux.loss_ce | aux.acc_seg | time | iter | memory | step | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | 0.009999 | 0.015238 | 0.153632 | 0.107654 | 27.191162 | 0.045978 | 21.810913 | 0.686551 | 6.0 | 5948.0 | 6.0 |
1 | 0.009978 | 0.009048 | 0.070571 | 0.048332 | 81.887817 | 0.022239 | 76.525879 | 0.330152 | 100.0 | 3774.0 | 100.0 |
2 | 0.009956 | 0.009704 | 0.071328 | 0.049419 | 82.742310 | 0.021909 | 69.058228 | 0.329530 | 200.0 | 3774.0 | 200.0 |
3 | 0.009933 | 0.010152 | 0.056368 | 0.038947 | 77.023315 | 0.017421 | 77.972412 | 0.331527 | 300.0 | 3774.0 | 300.0 |
4 | 0.009911 | 0.009709 | 0.067315 | 0.047621 | 84.524536 | 0.019694 | 81.353760 | 0.329458 | 400.0 | 3774.0 | 400.0 |
5 | 0.009889 | 0.010487 | 0.051533 | 0.036759 | 79.107666 | 0.014773 | 81.057739 | 0.331338 | 500.0 | 5198.0 | 500.0 |
6 | 0.009866 | 0.011702 | 0.049051 | 0.035058 | 81.347656 | 0.013993 | 83.291626 | 0.332726 | 600.0 | 3774.0 | 600.0 |
7 | 0.009844 | 0.008778 | 0.044250 | 0.031276 | 89.978027 | 0.012975 | 88.708496 | 0.327131 | 700.0 | 3774.0 | 700.0 |
8 | 0.009822 | 0.010705 | 0.038993 | 0.026881 | 79.788208 | 0.012113 | 81.781006 | 0.331781 | 800.0 | 3774.0 | 800.0 |
9 | 0.009800 | 0.011954 | 0.038804 | 0.026971 | 88.992310 | 0.011833 | 85.342407 | 0.331719 | 900.0 | 3774.0 | 900.0 |
10 | 0.009777 | 0.009229 | 0.042971 | 0.030055 | 78.103638 | 0.012916 | 76.773071 | 0.328295 | 1000.0 | 3774.0 | 1000.0 |
11 | 0.009755 | 0.010238 | 0.033921 | 0.023711 | 95.108032 | 0.010211 | 93.942261 | 0.329623 | 1100.0 | 3774.0 | 1100.0 |
12 | 0.009733 | 0.010761 | 0.043262 | 0.029841 | 87.689209 | 0.013420 | 88.031006 | 0.330329 | 1200.0 | 3774.0 | 1200.0 |
13 | 0.009710 | 0.009561 | 0.039193 | 0.027728 | 69.668579 | 0.011465 | 70.074463 | 0.328541 | 1300.0 | 3774.0 | 1300.0 |
14 | 0.009688 | 0.010342 | 0.042140 | 0.029936 | 73.834229 | 0.012204 | 77.590942 | 0.330526 | 1400.0 | 3774.0 | 1400.0 |
15 | 0.009665 | 0.009970 | 0.049107 | 0.034744 | 70.867920 | 0.014363 | 71.087646 | 0.329890 | 1500.0 | 3774.0 | 1500.0 |
16 | 0.009643 | 0.009523 | 0.040935 | 0.028303 | 86.972046 | 0.012632 | 87.493896 | 0.328551 | 1600.0 | 3774.0 | 1600.0 |
17 | 0.009621 | 0.010397 | 0.048824 | 0.034990 | 77.407837 | 0.013834 | 78.079224 | 0.332451 | 1700.0 | 3774.0 | 1700.0 |
18 | 0.009598 | 0.010132 | 0.037008 | 0.026012 | 84.204102 | 0.010996 | 82.192993 | 0.332169 | 1800.0 | 3774.0 | 1800.0 |
19 | 0.009576 | 0.010384 | 0.033336 | 0.023495 | 88.830566 | 0.009841 | 87.683105 | 0.331607 | 1900.0 | 3774.0 | 1900.0 |
20 | 0.009554 | 0.010668 | 0.035602 | 0.024980 | 82.687378 | 0.010622 | 82.128906 | 0.331148 | 2000.0 | 3774.0 | 2000.0 |
21 | 0.009531 | 0.009579 | 0.037542 | 0.026130 | 79.635620 | 0.011412 | 80.773926 | 0.329366 | 2100.0 | 3774.0 | 2100.0 |
22 | 0.009509 | 0.010095 | 0.040746 | 0.028772 | 94.372559 | 0.011975 | 93.969727 | 0.329432 | 2200.0 | 3774.0 | 2200.0 |
23 | 0.009486 | 0.009957 | 0.042884 | 0.030774 | 86.831665 | 0.012109 | 88.815308 | 0.329477 | 2300.0 | 3774.0 | 2300.0 |
24 | 0.009464 | 0.009858 | 0.028786 | 0.019972 | 90.911865 | 0.008815 | 90.582275 | 0.329635 | 2400.0 | 3774.0 | 2400.0 |
25 | 0.009442 | 0.011681 | 0.038919 | 0.027606 | 84.823608 | 0.011313 | 83.386230 | 0.331613 | 2500.0 | 3774.0 | 2500.0 |
26 | 0.009419 | 0.011108 | 0.043007 | 0.030508 | 89.422607 | 0.012499 | 89.462280 | 0.330888 | 2600.0 | 3774.0 | 2600.0 |
27 | 0.009397 | 0.010145 | 0.037845 | 0.026988 | 85.244751 | 0.010857 | 84.744263 | 0.329668 | 2700.0 | 3774.0 | 2700.0 |
28 | 0.009374 | 0.009031 | 0.033991 | 0.023090 | 78.616333 | 0.010901 | 77.508545 | 0.328896 | 2800.0 | 3774.0 | 2800.0 |
29 | 0.009352 | 0.010521 | 0.040949 | 0.028758 | 79.464722 | 0.012191 | 76.257324 | 0.330990 | 2900.0 | 3774.0 | 2900.0 |
df_test
aAcc | mIoU | mAcc | data_time | time | step | |
---|---|---|---|---|---|---|
0 | 80.37 | 43.01 | 51.99 | 0.032238 | 1.023954 | 400.0 |
1 | 85.78 | 53.23 | 65.87 | 0.009210 | 0.232762 | 800.0 |
2 | 82.58 | 41.45 | 46.50 | 0.011313 | 0.234456 | 1200.0 |
3 | 85.46 | 46.45 | 57.77 | 0.009522 | 0.233379 | 1600.0 |
4 | 84.65 | 47.16 | 53.23 | 0.011657 | 0.235186 | 2000.0 |
5 | 86.93 | 49.35 | 54.91 | 0.009893 | 0.233268 | 2400.0 |
6 | 89.86 | 55.90 | 61.96 | 0.010303 | 0.233799 | 2800.0 |
2. 导出训练日志文件 #
df_train.to_csv('训练日志-训练集.csv', index=False)
df_test.to_csv('训练日志-测试集.csv', index=False)
3. 数据可视化 #
# 可视化辅助函数
from matplotlib import colors as mcolors
import random
random.seed(124)
colors = ['b', 'g', 'r', 'c', 'm', 'y', 'k', 'tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan', 'black', 'indianred', 'brown', 'firebrick', 'maroon', 'darkred', 'red', 'sienna', 'chocolate', 'yellow', 'olivedrab', 'yellowgreen', 'darkolivegreen', 'forestgreen', 'limegreen', 'darkgreen', 'green', 'lime', 'seagreen', 'mediumseagreen', 'darkslategray', 'darkslategrey', 'teal', 'darkcyan', 'dodgerblue', 'navy', 'darkblue', 'mediumblue', 'blue', 'slateblue', 'darkslateblue', 'mediumslateblue', 'mediumpurple', 'rebeccapurple', 'blueviolet', 'indigo', 'darkorchid', 'darkviolet', 'mediumorchid', 'purple', 'darkmagenta', 'fuchsia', 'magenta', 'orchid', 'mediumvioletred', 'deeppink', 'hotpink']
markers = [".",",","o","v","^","<",">","1","2","3","4","8","s","p","P","*","h","H","+","x","X","D","d","|","_",0,1,2,3,4,5,6,7,8,9,10,11]
linestyle = ['--', '-.', '-']
def get_line_arg():
'''
随机产生一种绘图线型
'''
line_arg = {}
line_arg['color'] = random.choice(colors)
# line_arg['marker'] = random.choice(markers)
line_arg['linestyle'] = random.choice(linestyle)
line_arg['linewidth'] = random.randint(1, 4)
# line_arg['markersize'] = random.randint(3, 5)
return line_arg
# 训练集损失函数
metrics = ['loss', 'decode.loss_ce', 'aux.loss_ce']
plt.figure(figsize=(16, 8))
x = df_train['step']
for y in metrics:
plt.plot(x, df_train[y], label=y, **get_line_arg())
plt.tick_params(labelsize=20)
plt.xlabel('step', fontsize=20)
plt.ylabel('loss', fontsize=20)
plt.title('训练集损失函数', fontsize=25)
plt.savefig('训练集损失函数.pdf', dpi=120, bbox_inches='tight')
plt.legend(fontsize=20)
plt.show()
# 训练集准确率
metrics = ['decode.acc_seg', 'aux.acc_seg']
plt.figure(figsize=(16, 8))
x = df_train['step']
for y in metrics:
plt.plot(x, df_train[y], label=y, **get_line_arg())
plt.tick_params(labelsize=20)
plt.xlabel('step', fontsize=20)
plt.ylabel('loss', fontsize=20)
plt.title('训练集准确率', fontsize=25)
plt.savefig('训练集准确率.pdf', dpi=120, bbox_inches='tight')
plt.legend(fontsize=20)
plt.show()
# 测试集评估指标
metrics = ['aAcc', 'mIoU', 'mAcc']
plt.figure(figsize=(16, 8))
x = df_test['step']
for y in metrics:
plt.plot(x, df_test[y], label=y, **get_line_arg())
plt.tick_params(labelsize=20)
plt.ylim([0, 100])
plt.xlabel('step', fontsize=20)
plt.ylabel(y, fontsize=20)
plt.title('测试集评估指标', fontsize=25)
plt.savefig('测试集分类评估指标.pdf', dpi=120, bbox_inches='tight')
plt.legend(fontsize=20)
plt.show()
六、模型推理 #
os.getcwd()
'/home/featurize/data/mmsegmentation'
1. 载入配置文件 #
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
from mmseg.apis import init_model, inference_model, show_result_pyplot
import mmcv
import cv2
from mmengine.runner import Runner
from mmseg.utils import register_all_modules
# 载入 config 配置文件
from mmengine import Config
cfg = Config.fromfile('pspnet-WatermelonDataset_final.py')
# register all modules in mmseg into the registries
# do not init the default scope here because it will be init in the runner
register_all_modules(init_default_scope=False)
runner = Runner.from_cfg(cfg)
06/17 21:49:37 - mmengine - [4m[37mINFO[0m - ------------------------------------------------------------ System environment: sys.platform: linux Python: 3.7.10 (default, Jun 4 2021, 14:48:32) [GCC 7.5.0] CUDA available: True numpy_random_seed: 0 GPU 0: NVIDIA GeForce RTX 3060 CUDA_HOME: /usr/local/cuda NVCC: Cuda compilation tools, release 11.2, V11.2.152 GCC: gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 PyTorch: 1.10.1+cu113 PyTorch compiling details: PyTorch built with: - GCC 7.3 - C++ Version: 201402 - Intel(R) Math Kernel Library Version 2020.0.0 Product Build 20191122 for Intel(R) 64 architecture applications - Intel(R) MKL-DNN v2.2.3 (Git Hash 7336ca9f055cf1bfa13efb658fe15dc9b41f0740) - OpenMP 201511 (a.k.a. OpenMP 4.5) - LAPACK is enabled (usually provided by MKL) - NNPACK is enabled - CPU capability usage: AVX2 - CUDA Runtime 11.3 - NVCC architecture flags: -gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86 - CuDNN 8.2 - Magma 2.5.2 - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=11.3, CUDNN_VERSION=8.2.0, CXX_COMPILER=/opt/rh/devtoolset-7/root/usr/bin/c++, CXX_FLAGS= -Wno-deprecated -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -fopenmp -DNDEBUG -DUSE_KINETO -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -DEDGE_PROFILER_USE_KINETO -O2 -fPIC -Wno-narrowing -Wall -Wextra -Werror=return-type -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-sign-compare -Wno-unused-parameter -Wno-unused-variable -Wno-unused-function -Wno-unused-result -Wno-unused-local-typedefs -Wno-strict-overflow -Wno-strict-aliasing -Wno-error=deprecated-declarations -Wno-stringop-overflow -Wno-psabi -Wno-error=pedantic -Wno-error=redundant-decls -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-unused-but-set-variable -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, PERF_WITH_AVX512=1, TORCH_VERSION=1.10.1, USE_CUDA=ON, USE_CUDNN=ON, USE_EXCEPTION_PTR=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=ON, USE_NNPACK=ON, USE_OPENMP=ON, TorchVision: 0.11.2+cu113 OpenCV: 4.5.4 MMEngine: 0.7.4 Runtime environment: cudnn_benchmark: True mp_cfg: {'mp_start_method': 'fork', 'opencv_num_threads': 0} dist_cfg: {'backend': 'nccl'} seed: 0 Distributed launcher: none Distributed training: False GPU number: 1 ------------------------------------------------------------ 06/17 21:49:38 - mmengine - [4m[37mINFO[0m - Config: norm_cfg = dict(type='BN', requires_grad=True) data_preprocessor = dict( type='SegDataPreProcessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True, pad_val=0, seg_pad_val=255, size=(64, 64)) model = dict( type='EncoderDecoder', data_preprocessor=dict( type='SegDataPreProcessor', mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], bgr_to_rgb=True, pad_val=0, seg_pad_val=255, size=(256, 256)), pretrained='open-mmlab://resnet50_v1c', backbone=dict( type='ResNetV1c', depth=50, num_stages=4, out_indices=(0, 1, 2, 3), dilations=(1, 1, 2, 4), strides=(1, 2, 1, 1), norm_cfg=dict(type='BN', requires_grad=True), norm_eval=False, style='pytorch', contract_dilation=True), decode_head=dict( type='PSPHead', in_channels=2048, in_index=3, channels=512, pool_scales=(1, 2, 3, 6), dropout_ratio=0.1, num_classes=6, norm_cfg=dict(type='BN', requires_grad=True), align_corners=False, loss_decode=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=1.0)), auxiliary_head=dict( type='FCNHead', in_channels=1024, in_index=2, channels=256, num_convs=1, concat_input=False, dropout_ratio=0.1, num_classes=6, norm_cfg=dict(type='BN', requires_grad=True), align_corners=False, loss_decode=dict( type='CrossEntropyLoss', use_sigmoid=False, loss_weight=0.4)), train_cfg=dict(), test_cfg=dict(mode='whole')) dataset_type = 'WatermelonDataset' data_root = 'watermelon-dataset/' crop_size = (256, 256) train_pipeline = [ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), dict( type='RandomResize', scale=(2048, 1024), ratio_range=(0.5, 2.0), keep_ratio=True), dict(type='RandomCrop', crop_size=(64, 64), cat_max_ratio=0.75), dict(type='RandomFlip', prob=0.5), dict(type='PhotoMetricDistortion'), dict(type='PackSegInputs') ] test_pipeline = [ dict(type='LoadImageFromFile'), dict(type='Resize', scale=(2048, 1024), keep_ratio=True), dict(type='LoadAnnotations'), dict(type='PackSegInputs') ] img_ratios = [0.5, 0.75, 1.0, 1.25, 1.5, 1.75] tta_pipeline = [ dict(type='LoadImageFromFile', file_client_args=dict(backend='disk')), dict( type='TestTimeAug', transforms=[[{ 'type': 'Resize', 'scale_factor': 0.5, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 0.75, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.0, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.25, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.5, 'keep_ratio': True }, { 'type': 'Resize', 'scale_factor': 1.75, 'keep_ratio': True }], [{ 'type': 'RandomFlip', 'prob': 0.0, 'direction': 'horizontal' }, { 'type': 'RandomFlip', 'prob': 1.0, 'direction': 'horizontal' }], [{ 'type': 'LoadAnnotations' }], [{ 'type': 'PackSegInputs' }]]) ] train_dataloader = dict( batch_size=8, num_workers=2, persistent_workers=True, sampler=dict(type='InfiniteSampler', shuffle=True), dataset=dict( type='WatermelonDataset', data_root='watermelon-dataset/', data_prefix=dict( img_path='img_dir/train', seg_map_path='ann_dir/train'), pipeline=[ dict(type='LoadImageFromFile'), dict(type='LoadAnnotations'), dict( type='RandomResize', scale=(2048, 1024), ratio_range=(0.5, 2.0), keep_ratio=True), dict(type='RandomCrop', crop_size=(64, 64), cat_max_ratio=0.75), dict(type='RandomFlip', prob=0.5), dict(type='PhotoMetricDistortion'), dict(type='PackSegInputs') ])) val_dataloader = dict( batch_size=1, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='WatermelonDataset', data_root='watermelon-dataset/', data_prefix=dict(img_path='img_dir/val', seg_map_path='ann_dir/val'), pipeline=[ dict(type='LoadImageFromFile'), dict(type='Resize', scale=(2048, 1024), keep_ratio=True), dict(type='LoadAnnotations'), dict(type='PackSegInputs') ])) test_dataloader = dict( batch_size=1, num_workers=4, persistent_workers=True, sampler=dict(type='DefaultSampler', shuffle=False), dataset=dict( type='WatermelonDataset', data_root='watermelon-dataset/', data_prefix=dict(img_path='img_dir/val', seg_map_path='ann_dir/val'), pipeline=[ dict(type='LoadImageFromFile'), dict(type='Resize', scale=(2048, 1024), keep_ratio=True), dict(type='LoadAnnotations'), dict(type='PackSegInputs') ])) val_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU']) test_evaluator = dict(type='IoUMetric', iou_metrics=['mIoU']) default_scope = 'mmseg' env_cfg = dict( cudnn_benchmark=True, mp_cfg=dict(mp_start_method='fork', opencv_num_threads=0), dist_cfg=dict(backend='nccl')) vis_backends = [dict(type='LocalVisBackend')] visualizer = dict( type='SegLocalVisualizer', vis_backends=[dict(type='LocalVisBackend')], name='visualizer') log_processor = dict(by_epoch=False) log_level = 'INFO' load_from = None resume = False tta_model = dict(type='SegTTAModel') optimizer = dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005) optim_wrapper = dict( type='OptimWrapper', optimizer=dict(type='SGD', lr=0.01, momentum=0.9, weight_decay=0.0005), clip_grad=None) param_scheduler = [ dict( type='PolyLR', eta_min=0.0001, power=0.9, begin=0, end=40000, by_epoch=False) ] train_cfg = dict(type='IterBasedTrainLoop', max_iters=3000, val_interval=400) val_cfg = dict(type='ValLoop') test_cfg = dict(type='TestLoop') default_hooks = dict( timer=dict(type='IterTimerHook'), logger=dict(type='LoggerHook', interval=100, log_metric_by_epoch=False), param_scheduler=dict(type='ParamSchedulerHook'), checkpoint=dict(type='CheckpointHook', by_epoch=False, interval=1500), sampler_seed=dict(type='DistSamplerSeedHook'), visualization=dict(type='SegVisualizationHook')) work_dir = './work_dirs/WatermelonDataset' randomness = dict(seed=0)
/environment/miniconda3/lib/python3.7/site-packages/mmengine/utils/manager.py:114: UserWarning: <class 'mmseg.visualization.local_visualizer.SegLocalVisualizer'> instance named of visualizer has been created, the method `get_instance` should not accept any other arguments f'{cls} instance named of {name} has been created, ' /home/featurize/data/mmsegmentation/mmseg/models/backbones/resnet.py:431: UserWarning: DeprecationWarning: pretrained is a deprecated, please use "init_cfg" instead warnings.warn('DeprecationWarning: pretrained is a deprecated, ' /home/featurize/data/mmsegmentation/mmseg/models/builder.py:36: UserWarning: ``build_loss`` would be deprecated soon, please use ``mmseg.registry.MODELS.build()`` warnings.warn('``build_loss`` would be deprecated soon, please use ' /home/featurize/data/mmsegmentation/mmseg/models/losses/cross_entropy_loss.py:236: UserWarning: Default ``avg_non_ignore`` is False, if you would like to ignore the certain label and average loss over non-ignore labels, which is the same with PyTorch official cross_entropy, set ``avg_non_ignore=True``. 'Default ``avg_non_ignore`` is False, if you would like to '
06/17 21:49:39 - mmengine - [4m[37mINFO[0m - Distributed training is not used, all SyncBatchNorm (SyncBN) layers in the model will be automatically reverted to BatchNormXd layers if they are used. 06/17 21:49:39 - mmengine - [4m[37mINFO[0m - Hooks will be executed in the following order: before_run: (VERY_HIGH ) RuntimeInfoHook (BELOW_NORMAL) LoggerHook -------------------- before_train: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (VERY_LOW ) CheckpointHook -------------------- before_train_epoch: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (NORMAL ) DistSamplerSeedHook -------------------- before_train_iter: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook -------------------- after_train_iter: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (NORMAL ) SegVisualizationHook (BELOW_NORMAL) LoggerHook (LOW ) ParamSchedulerHook (VERY_LOW ) CheckpointHook -------------------- after_train_epoch: (NORMAL ) IterTimerHook (LOW ) ParamSchedulerHook (VERY_LOW ) CheckpointHook -------------------- before_val_epoch: (NORMAL ) IterTimerHook -------------------- before_val_iter: (NORMAL ) IterTimerHook -------------------- after_val_iter: (NORMAL ) IterTimerHook (NORMAL ) SegVisualizationHook (BELOW_NORMAL) LoggerHook -------------------- after_val_epoch: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (BELOW_NORMAL) LoggerHook (LOW ) ParamSchedulerHook (VERY_LOW ) CheckpointHook -------------------- after_train: (VERY_LOW ) CheckpointHook -------------------- before_test_epoch: (NORMAL ) IterTimerHook -------------------- before_test_iter: (NORMAL ) IterTimerHook -------------------- after_test_iter: (NORMAL ) IterTimerHook (NORMAL ) SegVisualizationHook (BELOW_NORMAL) LoggerHook -------------------- after_test_epoch: (VERY_HIGH ) RuntimeInfoHook (NORMAL ) IterTimerHook (BELOW_NORMAL) LoggerHook -------------------- after_run: (BELOW_NORMAL) LoggerHook --------------------
/home/featurize/data/mmsegmentation/mmseg/engine/hooks/visualization_hook.py:61: UserWarning: The draw is False, it means that the hook for visualization will not take effect. The results will NOT be visualized or stored. warnings.warn('The draw is False, it means that the '
2. 载入模型 #
checkpoint_path = './work_dirs/WatermelonDataset/iter_3000.pth'
model = init_model(cfg, checkpoint_path, 'cuda:0')
Loads checkpoint by local backend from path: ./work_dirs/WatermelonDataset/iter_3000.pth
3. 预测新图像 #
# 读取图像
img = mmcv.imread('data/Watermelon_seg.jpg')
# 推理
result = inference_model(model, img)
pred_mask = result.pred_sem_seg.data[0].cpu().numpy()
# 可视化预测结果
plt.imshow(img[:,:,::-1])
plt.show()
plt.imshow(pred_mask)
plt.show()
visualization = show_result_pyplot(model, img, result, opacity=0.7, out_file='pred.jpg')
plt.imshow(mmcv.bgr2rgb(visualization))
plt.show()
4. 预测视频 #
# 载入模型
import numpy as np
import time
import shutil
import torch
from PIL import Image
import cv2
import mmcv
import mmengine
from mmseg.apis import inference_model
from mmseg.utils import register_all_modules
register_all_modules()
from mmseg.datasets import WatermelonDataset
# 模型 config 配置文件
config_file = 'work_dirs/WatermelonDataset/pspnet-WatermelonDataset_final.py'
# 模型 checkpoint 权重文件
checkpoint_file = 'work_dirs/WatermelonDataset/iter_3000.pth'
from mmseg.apis import init_model
model = init_model(config_file, checkpoint_file, device='cuda:0')
from mmengine.model.utils import revert_sync_batchnorm
if not torch.cuda.is_available():
model = revert_sync_batchnorm(model)
/home/featurize/data/mmsegmentation/mmseg/models/builder.py:36: UserWarning: ``build_loss`` would be deprecated soon, please use ``mmseg.registry.MODELS.build()`` warnings.warn('``build_loss`` would be deprecated soon, please use ' /home/featurize/data/mmsegmentation/mmseg/models/losses/cross_entropy_loss.py:236: UserWarning: Default ``avg_non_ignore`` is False, if you would like to ignore the certain label and average loss over non-ignore labels, which is the same with PyTorch official cross_entropy, set ``avg_non_ignore=True``. 'Default ``avg_non_ignore`` is False, if you would like to '
Loads checkpoint by local backend from path: work_dirs/WatermelonDataset/iter_3000.pth
# 视频路径
input_video = 'data/Watermelon_seg.mp4'
# 存放单帧结果
temp_out_dir = time.strftime('%Y%m%d%H%M%S')
os.mkdir(temp_out_dir)
print('创建临时文件夹 {} 用于存放每帧预测结果'.format(temp_out_dir))
# 视频单帧预测
from mmseg.datasets import WatermelonDataset
classes = WatermelonDataset.METAINFO['classes']
palette = WatermelonDataset.METAINFO['palette']
# 预测函数
def pridict_single_frame(img, opacity=0.2):
result = inference_model(model, img)
# 将分割图按调色板染色
seg_map = np.array(result.pred_sem_seg.data[0].detach().cpu().numpy()).astype('uint8')
seg_img = Image.fromarray(seg_map).convert('P')
seg_img.putpalette(np.array(palette, dtype=np.uint8))
show_img = (np.array(seg_img.convert('RGB')))*(1-opacity) + img*opacity
return show_img
创建临时文件夹 20230617221833 用于存放每帧预测结果
# 读入待预测视频
imgs = mmcv.VideoReader(input_video)
prog_bar = mmengine.ProgressBar(len(imgs))
# 对视频逐帧处理
for frame_id, img in enumerate(imgs):
## 处理单帧画面
show_img = pridict_single_frame(img, opacity=0.15)
temp_path = f'{temp_out_dir}/{frame_id:06d}.jpg' # 保存语义分割预测结果图像至临时文件夹
cv2.imwrite(temp_path, show_img)
prog_bar.update() # 更新进度条
# 把每一帧串成视频文件
mmcv.frames2video(temp_out_dir, 'outputs/watemelon_video.mp4', fps=imgs.fps, fourcc='mp4v')
shutil.rmtree(temp_out_dir) # 删除存放每帧画面的临时文件夹
print('删除临时文件夹', temp_out_dir)
[>>>>>>>>>>>>>>>>>>>>>>>>>>>>>] 783/783, 67.5 task/s, elapsed: 12s, ETA: 0s[ ] 0/783, elapsed: 0s, ETA: 删除临时文件夹 20230617221833
评论(0条)