File size: 8,954 Bytes
f4c3b56 c341dbc f4c3b56 c341dbc f4c3b56 c341dbc f4c3b56 c341dbc f4c3b56 c341dbc f4c3b56 c341dbc f4c3b56 c341dbc f4c3b56 c341dbc f4c3b56 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
see 深入理解神经网络:从逻辑回归到CNN.md -> autodl
see doc\lang\programming\pytorch\文本检测\DBNET 论文代码都有
pip install torch==2.0.0+cu118 -f https://download.pytorch.org/whl/torch_stable.html
# apt install -y libsm6 libxrender1 libxext6 libgl1-mesa-glx
# 实测 vgpu-32G 要装这个
# 能正常训练
# 这套用官方训练好的权重 eval 比论文的精度低了很多,但确实框出来了
# 试试用它再继续微调会不会好点
conda create --name DB python==3.7 ipython pip -y \
&& conda activate DB \
&& pip install https://download.pytorch.org/whl/cu100/torch-1.2.0-cp37-cp37m-manylinux1_x86_64.whl \
https://download.pytorch.org/whl/cu100/torch-1.2.0-cp37-cp37m-manylinux1_x86_64.whl
# 最接近 cu10.1 + torch 1.2.0 的是这个
# numpy-1.21.6
# 这套用官方训练好的权重 eval 能达到论文的精度
https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda_10.0.130_410.48_linux
# cuda10.0 for ubuntu 18.04
# python dependencies
pip install -r requirement.txt
# install PyTorch with cuda-10.1
conda install pytorch torchvision cudatoolkit=10.1 -c pytorch
update-alternatives --remove cuda /usr/local/cuda-11.6
update-alternatives --install /usr/local/cuda cuda /usr/local/cuda-11.8 118 &&
ln -sfT /usr/local/cuda-11.8 /etc/alternatives/cuda &&
ln -sfT /etc/alternatives/cuda /usr/local/cuda
# 切换版本
vi ~/.bashrc
if [ -z $LD_LIBRARY_PATH ]; then
LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64
else
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.8/lib64
fi
export LD_LIBRARY_PATH
export PATH=/usr/local/cuda/bin:$PATH
source ~/.bashrc
nvcc --version
apt install build-essential && \
export CUDA_HOME=/usr/local/cuda && \
echo $CUDA_HOME && \
nvcc --version && \
ldconfig -p | grep cuda && \
cd ~/DB/assets/ops/dcn/ && \
sed -i 's/AT_CHECK/TORCH_CHECK/1' /root/DB/assets/ops/dcn/src/deform_conv_cuda.cpp && \
sed -i 's/AT_CHECK/TORCH_CHECK/1' /root/DB/assets/ops/dcn/src/deform_pool_cuda.cpp && \
python setup.py build_ext --inplace
# python setup.py clean --all \
&& rm -rf *.so build/
cd ~/DB && \
pip install -r requirement.txt && \
pip install --upgrade protobuf==3.20.0
~/DB/backbones# vi resnet.py
# 这里可以注释掉下载预训练模型的代码
sed -i 's/batch_size\:\ 16/batch_size\:\ 10/1' ~/DB/experiments/seg_detector/td500_resnet18_deform_thre.yaml && \
sed -i 's/num_workers\:\ 16/num_workers\:\ 10/1' ~/DB/experiments/seg_detector/td500_resnet18_deform_thre.yaml && \
sed -i 's/save_interval\:\ 18000/save_interval\:\ 450/1' ~/DB/experiments/seg_detector/td500_resnet18_deform_thre.yaml && \
sed -i 's/epochs\:\ 1200/epochs\:\ 30/1' ~/DB/experiments/seg_detector/td500_resnet18_deform_thre.yaml
# 禁用 cudnn
torch.backends.cudnn.enabled = False
https://matpool.com/supports/doc-vscode-connect-matpool/
Remote Development 安装插件
VS Code 远程连接矩池云机器教程
# vscode 打开远程文件夹 DB, ctrl + x 安装 python 扩展, ctrl+shift+p 输入 Python,选择选conda的python ,vscode 中修改train.py 在main 函数下加入命令行参数:
vi DB/training/learning_rate.py
lr = State(default=0.007)
vi experiments/seg_detector/ic15_resnet18_deform_thre.yaml
learning_rate:
class: DecayLearningRate
lr: 0.001
epochs: 1200
# 学习率要这两个地方一起改成一至后,logs 显示才正常
vi data/image_dataset.py
if 'TD' in self.data_dir[0] and label == '1':
label = '###'
# 注释掉这两行
# https://github.com/MhLiao/DB/issues/186
File "/root/miniforge3/envs/DB/lib/python3.7/site-packages/anyconfig/processors/utils.py", line 14, in <module>
import importlib.metadata
ModuleNotFoundError: No module named 'importlib.metadata'
# 只有 py3.7 会错
# pip install importlib-metadata
# import importlib_metadata as metadata # 改成这样
def main():
import sys
sys.argv.append( 'experiments/seg_detector/ic15_resnet18_deform_thre.yaml' )
sys.argv.append( '--num_gpus' )
sys.argv.append( '1' )
sys.argv.append( '--batch_size' )
sys.argv.append( '16' )
sys.argv.append( '--epochs' )
sys.argv.append( '1200' )
sys.argv.append( '--lr' )
sys.argv.append( '0.0001' )
sys.argv.append( '--resume' ) # 继续上一次训练
sys.argv.append( '/root/final7' )
#sys.argv.append( '--start_iter' )
#sys.argv.append( '18000' )
#sys.argv.append( '--start_epoch' )
#sys.argv.append( '107' )
torch.backends.cudnn.enabled = False
vscode 中然后F5 调试运行train.py
CUDA_VISIBLE_DEVICES=0 python eval.py experiments/seg_detector/ic15_resnet18_deform_thre.yaml --resume /root/final8 --box_thresh 0.55
CUDA_VISIBLE_DEVICES=0 python demo.py experiments/seg_detector/ic15_resnet18_deform_thre.yaml --image_path datasets/icdar2015/test_images/img_2.jpg --resume /root/final8 --polygon --box_thresh 0.55 --visualize
# img_1 用官方训练好的模型也是框不出的!!!
CUDA_VISIBLE_DEVICES=0 python eval.py experiments/seg_detector/ic15_resnet18_deform_thre.yaml --resume /root/ic15_resnet18 --box_thresh 0.55
# 官方
CUDA_VISIBLE_DEVICES=0 python demo.py experiments/seg_detector/ic15_resnet18_deform_thre.yaml --image_path datasets/icdar2015/test_images/img_2.jpg --resume /root/ic15_resnet18 --polygon --box_thresh 0.55 --visualize
# 官方
https://developer.nvidia.com/compute/cuda/10.1/Prod/local_installers/cuda_10.1.105_418.39_linux.run
# 下载安装
22.04 安装 cuda 10.1 需要降级 gcc
echo "deb http://archive.ubuntu.com/ubuntu focal main universe" | sudo tee /etc/apt/sources.list.d/focal.list \
&& sudo apt update \
&& sudo apt install gcc-7 g++-7 -y
# 设置默认GCC版本
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 2 \
&& sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 1 \
&& sudo update-alternatives --config gcc
# 选择gcc-7
./cuda_10.1.105_418.39_linux.run
# 安装,不要选驱动
Please make sure that
- PATH includes /usr/local/cuda-10.1/bin
- LD_LIBRARY_PATH includes /usr/local/cuda-10.1/lib64, or, add /usr/local/cuda-10.1/lib64 to /etc/ld.so.conf and run ldconfig as root
update-alternatives --remove cuda /usr/local/cuda-11.8
update-alternatives --install /usr/local/cuda cuda /usr/local/cuda-10.1 101 &&
ln -sfT /usr/local/cuda-10.1 /etc/alternatives/cuda &&
ln -sfT /etc/alternatives/cuda /usr/local/cuda
# 切换版本
vi ~/.bashrc
if [ -z $LD_LIBRARY_PATH ]; then
LD_LIBRARY_PATH=/usr/local/cuda-10.1/lib64
else
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-10.1/lib64
fi
export LD_LIBRARY_PATH
export PATH=/usr/local/cuda/bin:$PATH
source ~/.bashrc
nvcc --version
conda install pytorch==1.2.0 -c pytorch
# 官方文档是这个版本
# 但是现在下载不了了
https://download.pytorch.org/whl/torch_stable.html
# 这里看有什么可以装
pip install https://download.pytorch.org/whl/cu101/torch-1.4.0-cp38-cp38-linux_x86_64.whl
# 这样装 1.4.0+cu101
# 实测可以成功训练
# 但是,为什么会自动下载 Downloading: "https://download.pytorch.org/models/resnet18-5c106cde.pth" to /root/.cache/torch/checkpoints/resnet18-5c106cde.pth
# DB\backbones\resnet.py
# def deformable_resnet18(pretrained=True, **kwargs)
# 注释这里就不会下载了
字符级标注
测试
CUDA_VISIBLE_DEVICES=0 python demo.py experiments/seg_detector/ic15_resnet18_deform_thre.yaml --image_path datasets/icdar2015/test_images/img_00000028.jpg --resume /root/final --polygon --box_thresh 0.7 --visualize
实测一张图拆出来的每一行一个图,字符级标注:结果完全不得行
todo:
优化训练原码,自已写
# pip install numpy==1.26.4 opencv-python==4.6.0.66
see /root/DB/experiments/seg_detector/base_ic15.yaml
processes:
- class: AugmentDetectionData
augmenter_args:
- ['Fliplr', 0.5]
- {'cls': 'Affine', 'rotate': [-10, 10]}
- ['Resize', [0.5, 3.0]]
only_resize: False
keep_ratio: False
- class: RandomCropData
size: [640, 640]
max_tries: 10
- class: MakeICDARData
- class: MakeSegDetectionData
- class: MakeBorderMap
- class: NormalizeImage
- class: FilterKeys
superfluous: ['polygons', 'filename', 'shape', 'ignore_tags', 'is_training']
训练阶段图片要经过这些处理
|