1.服务器Ubuntu系统编程环境安装指令

0.cuda版本切换
gedit /etc/profile
export PATH=$PATH:/usr/local/cuda-11.8/bin
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.8/lib64
export PATH=/usr/local/cuda-11.8/bin${PATH:+:${PATH}}
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
export PATH=/usr/local/cuda-11.8/bin:$PATH
export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64:$LD_LIBRARY_PATH
/usr/local/MATLAB/R2024a/bin/matlab
export PATH=/usr/local/MATLAB/R2024a/bin/matlab:$PATH
find / -type
d -name "MATLAB_R2024a"
2>/dev/null
一:pytorch___version__
import torch
print(torch.cuda.is_available())
print(torch.cuda.get_device_name())
print(torch.cuda.current_device())
print(torch.cuda.device_count())
print(torch.__version__)
print(torch.version.cuda)
二TZB天智杯4+基本的数据处理
#export PATH=/home/zkti/0.Test_tang/miniconda3/bin:$PATH
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n tzb_4 python=3.8 -y #注意环境命名必须用小写,大写用pycharm调试不通过
source activate tzb_4
conda search gdal
(2.2.4,3.0.2)
conda install gdal==3.0.2
pip install pillow matplotlib scikit-image opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install scikit-image -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tqdm -i https://pypi.tuna.tsinghua.edu.cn/simple
三、YOLOv5
1)模型环境配置
https://github.com/ultralytics/yolov5 这里选择yolov5-4.0版本
export PATH=/home/zkti/0.Test_tang/miniconda3/bin:$PATH
conda create -n yolov5 python=3.8 -y
source activate yolov5
conda install pytorch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 pytorch-cuda=12.1 -c pytorch -c nvidia
注意点是:在这里先去掉
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
2)自定义数据集
Yolo官网格式:https://github.com/ultralytics/yolov5/wiki/Train-Custom-Data
pascalvoc转yolo格式
程序在utrla_voc2yolo文件夹里面
1. voc_labelname.py 统计数据库的类别
2. voc2txt,py 将XML文件生成对于txt文件,这里包含坐标转换
3. makedata.py 根据txt文件来移动图像,生成yolo数据集
4. 坐标转换:https://blog.csdn.net/angelbeats11/article/details/88427359
coco转yolo格式
3)训练pascalvoc格式
1)新建文件夹
在yolov5-master内新建predict和weights文件夹
predict:用于存储测试后的图像和TXT
weights:存放预训练模型
2)修改模型参数
Yolov5-master\models\ yolov5l.yaml: nc: 80 # number of classes
/yolov5-4.0/data/hyp.scratch.yaml #从头训练,不借助预训练数据集
yolov5-4.0/data/hyp.finetune.yaml #借助预训练训练,这里可以对超参数修改
3)修改python程序
Yolov5-master\data\ VOC.yaml:
注意点:这里names一定要与voc2txt.py 保持一致
# PASCAL VOC dataset http://host.robots.ox.ac.uk/pascal/VOC/
# Train command: python train.py --data VOC.yaml
# Default dataset location is next to YOLOv5:
# /parent
# /datasets/VOC
# /yolov5
# Train/val/test sets as 1) dir: path/to/imgs, 2) file: path/to/imgs.txt, or 3) list: [path/to/imgs1, path/to/imgs2, ..]
path: /home/zkti/data_4T/1.datasets/2.Optical/0.DIOR/DIOR_yolov5/
train: # train images (relative to 'path') 16551 images
- /home/zkti/data_4T/1.datasets/2.Optical/0.DIOR/DIOR_yolov5/images/train
val: # val images (relative to 'path') 4952 images
- /home/zkti/data_4T/1.datasets/2.Optical/0.DIOR/DIOR_yolov5/images/val
test: # test images (optional)
- /home/zkti/data_4T/1.datasets/2.Optical/0.DIOR/DIOR_yolov5/images/test
# Classes
nc: 20 # number of classes
# class names
names: ['windmill', 'stadium', 'overpass', 'ship', 'Expressway-Service-area', 'trainstation', 'storagetank', 'airport', 'tenniscourt', 'chimney', 'groundtrackfield', 'vehicle', 'golffield', 'bridge', 'dam', 'basketballcourt', 'Expressway-toll-station', 'harbor', 'airplane', 'baseballfield']
4)运行训练
(1)配置train.py的模型和数据集格式
#指定GPU训练
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
#修改parser配置文件
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--weights', type=str, default='yolov5s.pt', help='initial weights path') #修改初始化模型位置
parser.add_argument('--cfg', type=str, default='models/yolov5s.yaml', help='model.yaml path') #修改模型配置文件参数的路径
parser.add_argument('--data', type=str, default='data/VOC_DIOR.yaml', help='data.yaml path') #修改数据集路径
parser.add_argument('--hyp', type=str, default='data/hyp.finetune.yaml', help='hyperparameters path') #一定要配置借助预训练模型的超参数
parser.add_argument('--epochs', type=int, default=300)
parser.add_argument('--batch-size', type=int, default=16, help='total batch size for all GPUs')
parser.add_argument('--img-size', nargs='+', type=int, default=[640, 640], help='[train, test] image sizes')
parser.add_argument('--rect', action='store_true', help='rectangular training')
parser.add_argument('--resume', nargs='?', const=True, default=False, help='resume most recent training')
parser.add_argument('--nosave', action='store_true', help='only save final checkpoint')
parser.add_argument('--notest', action='store_true', help='only test final epoch')
parser.add_argument('--noautoanchor', action='store_true', help='disable autoanchor check')
parser.add_argument('--evolve', action='store_true', help='evolve hyperparameters')
parser.add_argument('--bucket', type=str, default='', help='gsutil bucket')
parser.add_argument('--cache-images', action='store_true', help='cache images for faster training')
parser.add_argument('--image-weights', action='store_true', help='use weighted image selection for training')
parser.add_argument('--device', default='0', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
parser.add_argument('--multi-scale', action='store_true', help='vary img-size +/- 50%%')
parser.add_argument('--single-cls', action='store_true', help='train multi-class data as single-class')
parser.add_argument('--adam', action='store_true', help='use torch.optim.Adam() optimizer')
parser.add_argument('--sync-bn', action='store_true', help='use SyncBatchNorm, only available in DDP mode')
parser.add_argument('--local_rank', type=int, default=-1, help='DDP parameter, do not modify')
parser.add_argument('--log-imgs', type=int, default=16, help='number of images for W&B logging, max 100')
parser.add_argument('--log-artifacts', action='store_true', help='log artifacts, i.e. final trained model')
parser.add_argument('--workers', type=int, default=8, help='maximum number of dataloader workers')
parser.add_argument('--project', default='runs/train', help='save to project/name')
parser.add_argument('--name', default='exp', help='save to project/name')
parser.add_argument('--exist-ok', action='store_true', help='existing project/name ok, do not increment')
parser.add_argument('--quad', action='store_true', help='quad dataloader')
opt = parser.parse_args()
(3) 指定GPU:
import os
#多块使用逗号隔开
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
(4)python tran.py
5)运行测试
运行前需要将DIOR_classes的类型顺序要与之前保持一致
Python detect_tang_v5.py
输出格式:类别+置信度+坐标(xmin,ymin,xmax,ymax)
6)得出map
(1) Python detect_tang_v5.py 这里要注意,一定要设置置信度为0.01,具体看mAP
(2) map_tang.py :
超参数:这里一定要这样设置,否则计算map极其慢
parser.add_argument('-na', '--no-animation',default=True, help="no animation is shown.", action="store_true")
parser.add_argument('-np', '--no-plot',default=False, help="no plot is shown.", action="store_true")
四、YOLOv8
参考网址
yolov8测试图片并保存预测结果,用于map的计算
https://blog.csdn.net/qq_42178122/article/details/133688916
yolov8的predict使用方法,更改predict.py的输出结果,输出label的真实坐标,保存图片和txt文档,图片中没有异物生成空的txt文档
https://blog.csdn.net/m0_57847261/article/details/134319876?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ECtr-2-134319876-blog-133688916.235%5Ev43%5Epc_blog_bottom_relevance_base7&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ECtr-2-134319876-blog-133688916.235%5Ev43%5Epc_blog_bottom_relevance_base7&utm_relevant_index=5
YOLOv8的训练、验证、预测及导出[目标检测实践篇]
https://blog.csdn.net/weixin_45144684/article/details/138454441
目标检测项目实战——使用Yolo v8识别图片中验证拼图位置
https://zhuanlan.zhihu.com/p/667220840
YOLOv8打印检测框坐标
https://blog.csdn.net/GuoKe_L/article/details/136903386?spm=1001.2101.3001.6650.7&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-7-136903386-blog-139767590.235%5Ev43%5Epc_blog_bottom_relevance_base7&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ERate-7-136903386-blog-139767590.235%5Ev43%5Epc_blog_bottom_relevance_base7&utm_relevant_index=12
YOLOv8目标检测结果分析
https://blog.csdn.net/weixin_38566632/article/details/140690304
0.模型环境配置完整版-服务器
https://github.com/ultralytics/ultralytics
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n yolov8 python=3.8 -y
source activate yolov8
conda install pytorch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 pytorch-cuda=12.1 -c pytorch -c nvidia
pip install ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pycuda -i https://pypi.tuna.tsinghua.edu.cn/simple
1. 模型环境配置
https://github.com/ultralytics/ultralytics
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n yolov8 python=3.8 -y
source activate yolov8
conda install pytorch==2.2.1 torchvision==0.17.1 pytorch-cuda=12.1 -c pytorch -c nvidia
pip install ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple
##########TensorRT###############
pip install tensorrt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnx -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxsim -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxslim -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxruntime -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pycuda -i https://pypi.tuna.tsinghua.edu.cn/simple
###################SAHI################
pip install opencv-python sahi tabulate podm tqdm argparse -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install object_detection_metrics -i https://pypi.tuna.tsinghua.edu.cn/simple
2. 自定义数据集
数据集格式参考网址为:https://docs.ultralytics.com/datasets/detect/,介绍了Ultralytics YOLO 格式,该格式是为了ultralytics旗下的yolo模型标准数据集格式,使用其他数据集训练时,必须得进行数据转换
1)VOC数据集转Ultralytics YOLO格式
可以借鉴转Ultralytics 给的官方转换方法:2023-Yolov8/ultralytics-main/ultralytics/cfg/datasets/VOC.yaml
使用/home/zkti/0.Test_tang/0.Python_Script/1.HBB/0.Coordinate transformation/utrla_voc2yolo文件下的python脚本
1. voc_labelname.py 统计数据库的类别
2. voc2txt,py 将XML文件生成对于txt文件,这里包含坐标转换
3. makedata.py 根据txt文件来移动图像,生成yolo数据集
2)VisDrone转Ultralytics YOLO格式
参考:https://blog.csdn.net/u012305034/article/details/134655981
自己的python脚本
3.在ultralytics/cfg/datasets/文件夹下建立自定义数据集的yaml文件
值得注意的是yaml文件里面的names的形式可以为:
# class names
names: ['windmill', 'stadium', 'overpass', 'ship', 'Expressway-Service-area', 'trainstation', 'storagetank', 'airport', 'tenniscourt', 'chimney', 'groundtrackfield', 'vehicle', 'golffield', 'bridge', 'dam', 'basketballcourt', 'Expressway-toll-station', 'harbor', 'airplane', 'baseballfield']
4.修改模型参数:ultralytics/cfg/models/v8/yolov8.yaml
修改nc参数,与上述的class names个数一致
值得注意的是,yolov8.yaml定义了五种不同复杂度的模型,yolov8n.yaml为最小模型
5. 训练模型
可以写一个train.py脚本,如以下形式:
##这里指定了训练模型的类型,输入图像大小,训练批次和学习率
from ultralytics import YOLO
import os
os.environ['CUDA_VISIBLE_DEVICES'] = '0'
# Load a model
model = YOLO("yolov8n.yaml") # build a new model from YAML
model = YOLO("yolov8n.pt") # load a pretrained model (recommended for training)
model = YOLO("yolov8n.yaml").load("yolov8n.pt") # build from YAML and transfer weights
# Train the model
#results = model.train(data="VisDrone_tang.yaml", epochs=100, imgsz=640)
results = model.train(data="VisDrone_tang.yaml", epochs=100, imgsz=640,batch=32,lr0=0.001)
6.运行测试
1)单张图像测试:
yolo predict model=yolov8n.pt source='https://ultralytics.com/images/bus.jpg'
2)多张图像批量测试:
参考:
(1)直接解决yolov8的预测方法
yolov8的predict使用方法,更改predict.py的输出结果,输出label的真实坐标,保存图片和txt文档,图片中没有异物生成空的txt文档
https://blog.csdn.net/m0_57847261/article/details/134319876?spm=1001.2101.3001.6650.2&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ECtr-2-134319876-blog-133688916.235%5Ev43%5Epc_blog_bottom_relevance_base7&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7ECtr-2-134319876-blog-133688916.235%5Ev43%5Epc_blog_bottom_relevance_base7&utm_relevant_index=5
(2)自己写的
运行前需要将DIOR_classes的类型顺序要与之前保持一致
Python detect_tang_v5.py
输出格式:类别+置信度+坐标(xmin,ymin,xmax,ymax)
6)得出map
(1) Python detect_tang_v5.py 这里要注意,一定要设置置信度为0.01,具体看mAP
(2) map_tang.py :
超参数:这里一定要这样设置,否则计算map极其慢
parser.add_argument('-na', '--no-animation',default=True, help="no animation is shown.", action="store_true")
parser.add_argument('-np', '--no-plot',default=False, help="no plot is shown.", action="store_true")
7) python版本TensorRT部署
参考:
视频教程:YOLOv8目标检测实战:ONNX模型转换及TensorRT部署
https://edu.csdn.net/learn/39292/635091
参考:https://zhuanlan.zhihu.com/p/667220840
Tensorrt安装及使用(python版本):https://blog.csdn.net/stivory/article/details/135847529
1)ultralytics官方做法
(1)适用于 YOLOv8 模型的 ONNX 导出,可以学习ONNX是什么
网址:https://docs.ultralytics.com/integrations/onnx/
(2)YOLOv8 模型的 TensorRT 导出
网址:https://docs.ultralytics.com/integrations/tensorrt/#why-should-i-use-ultralytics-yolov8-cli
***环境部署:
pip install tensorrt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnx -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxsim -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxruntime -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pycuda -i https://pypi.tuna.tsinghua.edu.cn/simple
1)ultralytics官方做法
(1)适用于 YOLOv8 模型的 ONNX 导出,可以学习ONNX是什么
网址:https://docs.ultralytics.com/integrations/onnx/
(2)YOLOv8 模型的 TensorRT 导出
网址:https://docs.ultralytics.com/integrations/tensorrt/#why-should-i-use-ultralytics-yolov8-cli
2)正常做法:pt先转ONNX格式,然后ONNX转换成TensorRT engine
3)TensorRT部署前和部署后的推理时间测试脚本
from ultralytics import YOLO
import time
#from openvino.inference_engine import IENetwork
#from onnxruntime import InferenceSession
old_time = time.time()
# Load a model
# model = YOLO('yolov8n.pt') # load an official model
#model = YOLO('best_openvino_model') # load a custom model
#model = YOLO('best.pt')
model = YOLO('best.engine')
# Predict with the model
results = model('datasets/images/1.jpg', save=True) # predict on an image
current_time = time.time()
print("推理耗时" + str(current_time - old_time) + "s")
8)YOLOv8+SAHI
参考:
使用YOLOv8+SAHI增强小目标检测效果并计算评估指标
https://blog.csdn.net/Dora_blank/article/details/140236280
pip install opencv-python sahi tabulate podm tqdm argparse -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install object_detection_metrics -i https://pypi.tuna.tsinghua.edu.cn/simple
ModuleNotFoundError: No module named 'podm.metrics'
解决办法:https://pypi.org/project/object-detection-metrics/0.1/
https://github.com/rafaelpadilla/Object-Detection-Metrics
pip install object_detection_metrics -i https://pypi.tuna.tsinghua.edu.cn/simple
9)YOLOv8+UI界面
参考:https://mbd.pub/o/bread/mbd-ZZyWlZ9y
########################################
requirements.txt 里面内容如下
certifi==2023.7.22
charset-normalizer==3.3.0
colorama==0.4.6
contourpy==1.1.1
cycler==0.12.1
fonttools==4.43.1
idna==3.4
importlib-resources==6.1.0
kiwisolver==1.4.5
matplotlib
###numpy==1.26.1
opencv-python==4.8.1.78
packaging==23.2
psutil==5.9.6
py-cpuinfo==9.0.0
pyparsing==3.1.1
python-dateutil==2.8.2
pyyaml==6.0.1
requests==2.31.0
scipy
seaborn==0.13.0
six==1.16.0
thop==0.1.1-2209072238
####torch==1.9.0
tqdm==4.66.1
typing-extensions==4.8.0
ultralytics==8.0.199
urllib3==2.0.6
zipp==3.17.0
PyQt5==5.15.2
pyqt5-tools==5.15.2.3.1
#################################
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n yolov8_ui python=3.8 -y
source activate yolov8_ui
conda install pytorch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 pytorch-cuda=12.1 -c pytorch -c nvidia
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip uninstall opencv-python
pip install opencv-python-headless -i https://pypi.tuna.tsinghua.edu.cn/simple
解决expected np.ndarray (got numpy.ndarray)报错
https://blog.csdn.net/m0_56182552/article/details/140854252
QObject::moveToThread: Current thread is not the object`s thread. Cannot move to target thread
https://blog.csdn.net/ustczhng2012/article/details/115137510
pip uninstall opencv-python
pip install opencv-python-headless -i https://pypi.tuna.tsinghua.edu.cn/simple
四-1:YOLOv8-OBB推理详解及部署实现
https://gitcode.csdn.net/66262bb39c80ea0d2270d7e0.html?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6MzE5NjYxNSwiZXhwIjoxNzI0MTQ3NTIxLCJpYXQiOjE3MjM1NDI3MjEsInVzZXJuYW1lIjoid3V4aW56aGlzaG91In0.2hsLzH_RMer4-Zpckp3tLbCG1mFfE2XcjhHW20zTzbI
四-2:YOLOv8-OBB推理详解及部署实现
四-3:ultralytics
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
source activate ultralytics-8.3.16
1. 模型环境配置
https://github.com/ultralytics/ultralytics
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n ultralytics-8.3.16 python=3.8 -y
source activate ultralytics-8.3.16
conda install pytorch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 pytorch-cuda=12.1 -c pytorch -c nvidia
pip install ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple
##########TensorRT###############
pip install tensorrt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnx -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxslim -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxruntime -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxruntime-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pycuda -i https://pypi.tuna.tsinghua.edu.cn/simple
###################SAHI################
pip install opencv-python sahi tabulate podm tqdm argparse -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install object_detection_metrics -i https://pypi.tuna.tsinghua.edu.cn/simple
需要进一步更新:pip install ultralytics -i https://pypi.tuna.tsinghua.edu.cn/simple
conda search gdal
(2.2.4,3.0.2)
conda install gdal==3.0.2
五、mmrotate
https://mmrotate.readthedocs.io/en/latest/install.html
1.:基于MMRotate训练自定义数据集 做旋转目标检测 2022-3-30
https://blog.csdn.net/qq_43581224/article/details/123838415?spm=1001.2101.3001.6661.1&utm_medium=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ETopBlog-1.topblog&depth_1-utm_source=distribute.pc_relevant_t0.none-task-blog-2%7Edefault%7ECTRLIST%7ETopBlog-1.topblog&utm_relevant_index=1
2.MMRotate 详细使用教程
https://blog.csdn.net/Sylvia_Lan/article/details/124008837?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.pc_relevant_default&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7ECTRLIST%7Edefault-1.pc_relevant_default&utm_relevant_index=2
3.【AI目标检测】MMROTATE踩坑记录
https://blog.csdn.net/jaz_y/article/details/123983506
1. 模型环境配置
https://github.com/ultralytics/ultralytics
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n mmrotate python=3.8 -y
source activate mmrotate
#conda install pytorch==2.2.0 torchvision==0.17.0 torchaudio==2.2.0 pytorch-cuda=12.1 -c pytorch -c nvidia
conda install pytorch==2.0.0 torchvision==0.15.0 torchaudio==2.0.0 pytorch-cuda=11.7 -c pytorch -c nvidia
pip install -U openmim -i https://pypi.tuna.tsinghua.edu.cn/simple
#安装mmcv-full ,一定要安装和cuda版本、pytorch版本对应的版本,如下命令
##pip install mmcv-full=={MMCV_VERSION} -f https://download.openmmlab.com/mmcv/dist/{CUDA_VERSION}/{TORCH_VERSION}/index.html
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu117/torch2.0/index.html -i https://pypi.tuna.tsinghua.edu.cn/simple
##Install mmcv
https://mmcv.readthedocs.io/zh-cn/latest/get_started/installation.html
pip install mmdet -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install -r requirements/build.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
##其中pip install -v -e .or python setup.py develop将会安装为开发模式,所有对源码的修改都将生效。(pip install -v -e .最后的.表示当前路径,不要漏掉!)
#pip install -v -e . -i https://pypi.tuna.tsinghua.edu.cn/simple
python setup.py develop
pip install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install scikit-image -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install timm -i https://pypi.tuna.tsinghua.edu.cn/simple
bash: /home/zkti/data_16T/miniconda3/envs/mmrotate/bin/pip: /home/zkti/0.Test_tang/miniconda3/envs/mmrotate/bin/python: bad interpreter: No such file or directory
https://blog.csdn.net/weixin_44162814/article/details/143332667
关于MMrotate踩坑记录(ValueError:need at least one array to cancatenate)
https://blog.csdn.net/weixin_40493382/article/details/123897405?spm=1001.2101.3001.6650.1&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ECtr-1-123897405-blog-127943250.235%5Ev43%5Epc_blog_bottom_relevance_base5&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCommendFromBaidu%7ECtr-1-123897405-blog-127943250.235%5Ev43%5Epc_blog_bottom_relevance_base5&utm_relevant_index=2
ICCV 2023 | LSKNet【保姆级】训练自己的目标检测模型
https://blog.csdn.net/weixin_51670564/article/details/132590489?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-132590489-blog-127943250.235^v43^pc_blog_bottom_relevance_base5&spm=1001.2101.3001.4242.1&utm_relevant_index=3
报错:RuntimeError: indices should be either on cpu or on the same device as the indexed tensor (cpu)
https://blog.csdn.net/weixin_51670564/article/details/132605642
【mmlab】mmrotate如何计算模型参数量
https://blog.csdn.net/weixin_44037500/article/details/141194256
https://mmrotate.readthedocs.io/zh-cn/v0.3.0/useful_tools.html
FPS计算
https://mmrotate.readthedocs.io/zh-cn/v0.3.0/useful_tools.html
成功解决error:unrecognized argument: --local-rank=0
https://blog.csdn.net/qq_43826289/article/details/131564035
2.数据集处理
1)类似DOTA大图的数据集
(1)都得先转换成DOTA格式
这里得 熟悉DOTA数据集格式和相关工具
DOTA遥感数据集以及相关工具DOTA_devkit的整理(踩坑记录)
DOTA数据集大图标签格式
注意点:大图格式里面,带imagesource和gsd两项
DOTA数据集切图后,小图切片的格式为
大图切图的程序,可以用/home/zkti/0.Test_tang/test_tang/detection_OBB/1.DOTA_bigimg/0.mmrotate/mmrotate_DIOR/tools/data/dota/split/img_split.py函数
里面需要配置好/home/zkti/0.Test_tang/test_tang/detection_OBB/1.DOTA_bigimg/0.mmrotate/mmrotate_DIOR/tools/data/dota/split/split_configs/ss_train.json等json文件
之后执行:
python mmrotate-main/tools/data/dota/split/img_split.py --base_json mmrotate-main/tools/data/dota/split/split_configs/ss_train.json
2)类似DIOR-R的小图数据集
(1)DIOR-R转换成DOTA小图数据集格式
使用XML2txt_8_DOTA.py脚本进行转换
3.配置参数进行训练
1)修改mmrotate_DIOR/mmrotate/datasets/dota.py的配置参数
(1)修改CLASSES
(2)将.png格式换成自定义数据集的图像格式
2)在0.mmrotate_DIOR文件夹下,新建configs_DIOR_R文件夹
3)将configs文件夹里面的_base_和你想要的方法,复制到到configs_DIOR_R文件夹下
4)修改configs_DIOR_R/_base_/datasets/dotav1.py的配置参数
(1)修改自定义数据集的路径:data_root = '/home/zkti/data_4T/1.datasets/2.Optical/0.DIOR/DIOR_R_DOTA/'
(2)修改img_scale=(800, 800)参数,将参数修改成与检测模型匹配的参数
(3)修改data = dict(
samples_per_gpu=2,
workers_per_gpu=2,
train=dict(
type=dataset_type,
ann_file=data_root + 'train/annfiles/',
img_prefix=data_root + 'train/images/',
pipeline=train_pipeline),
val=dict(
type=dataset_type,
ann_file=data_root + 'val/annfiles/',
img_prefix=data_root + 'val/images/',
pipeline=test_pipeline),
test=dict(
type=dataset_type,
ann_file=data_root + 'test/images/',
img_prefix=data_root + 'test/images/',
pipeline=test_pipeline))
5)修改configs_DIOR_R/oriented_rcnn/oriented_rcnn_r50_fpn_1x_dota_le90.py的配置参数
(1)修改num_classes=20,等于数据集类别个数,不加背景
(2)修改img_scale=(800, 800)参数,将参数修改成与检测模型匹配的参数
6)在0.mmrotate_DIOR文件下新建train_oriented_rcnn.sh的训练配置参数
CUDA_VISIBLE_DEVICES=0 python tools/train.py /home/zkti/0.Test_tang/test_tang/detection_OBB/0.DIOR_R/0.mmrotate_DIOR/configs_DIOR_R/oriented_rcnn/oriented_rcnn_r50_fpn_1x_dota_le90.py
4.常见问题:
1)ImportError: /home/zkti/0.Test_tang/miniconda3/envs/mmrotate/lib/python3.8/site-packages/mmcv/_ext.cpython-38-x86_64-linux-gnu.so: undefined symbol: _ZNK2at6Tensor10transpose_Ell
解决办法:https://github.com/open-mmlab/mmdetection/issues/4291
Same here, refer to the document: https://mmcv.readthedocs.io/zh-cn/latest/get_started/installation.html
reinstall mmcv with proper version according to your torch and cuda version, and the problem solved.
Note: In MMCV-v2.x, mmcv-full is rename to mmcv.
2)ImportError: cannot import name 'Config' from 'mmcv' (/home/zkti/0.Test_tang/miniconda3/envs/mmrotate/lib/python3.8/site-packages/mmcv/__init__.py)
解决办法:https://blog.csdn.net/M_TDM/article/details/133046534
python -c 'import torch;print(torch.__version__);print(torch.version.cuda)'
#安装mmcv-full ,一定要安装和cuda版本、pytorch版本对应的版本,如下命令
##pip install mmcv-full=={MMCV_VERSION} -f https://download.openmmlab.com/mmcv/dist/{CUDA_VERSION}/{TORCH_VERSION}/index.html
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu117/torch2.0/index.html -i https://pypi.tuna.tsinghua.edu.cn/simple
##Install mmcv
https://mmcv.readthedocs.io/zh-cn/latest/get_started/installation.html
3)KeyError: "DOTADataset: 'expressway-toll-station'"
解决方法:
mmrotate_DIOR/mmrotate/datasets/dota.py的CLASSES的大写都改成小写
再执行pip install -v -e . -i https://pypi.tuna.tsinghua.edu.cn/simple
六、HI-Diff-Hierarchical Integration Diffusion Model for Realistic Image Deblurring
# Clone the github repo and go to the default directory 'HI-Diff'.
git clone https://github.com/zhengchen1999/HI-Diff.git
cd HI-Diff
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n hi_diff python=3.9
conda create -n hi_diff_2 python=3.9 (可行)
source activate hi_diff
source activate hi_diff_2
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple #先把torch和torchvision注释,让其独立安装
#ERROR: No matching distribution found for tb-nightly
python -m pip install tb-nightly -i https://mirrors.aliyun.com/pypi/simple
在安装basicsr==1.4.2时候,发现安装始终出错。
https://blog.csdn.net/qq_45100200/article/details/141284517?spm=1001.2101.3001.6650.3&utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EYuanLiJiHua%7ECtr-3-141284517-blog-133925899.235%5Ev43%5Epc_blog_bottom_relevance_base7&depth_1-utm_source=distribute.pc_relevant.none-task-blog-2%7Edefault%7EYuanLiJiHua%7ECtr-3-141284517-blog-133925899.235%5Ev43%5Epc_blog_bottom_relevance_base7&utm_relevant_index=4
pip install basicsr -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install安装的时候在Preparing metadata (setup.py) ...卡住
https://blog.csdn.net/sinat_29957455/article/details/130285223
pip install --upgrade pip setuptools wheel -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install --verbose basicsr --use-pep517 -i https://pypi.tuna.tsinghua.edu.cn/simple
conda install pytorch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 pytorch-cuda=12.1 -c pytorch -c nvidia
# CUDA 11.3
conda install pytorch==1.9.0 torchvision==0.10.0 torchaudio==0.9.0 cudatoolkit=11.3 -c pytorch -c conda-forge(可行)
Generate image patches from GoPro dataset for training.
python generate_patches_gopro.py ##注释 from data.hdfs import copy, mkdir
#You can also specify --nproc_per_node=X with X>1.
解决报错:train.py: error: unrecognized arguments: --local-rank=1 或 local-rank=0
解决方法:https://blog.csdn.net/qq_43826289/article/details/132953452
python -m torch.distributed.run --nproc_per_node=2 --master_port=4321 train.py -opt options/train/GoPro_S1.yml --launcher pytorch
python -m torch.distributed.launch --nproc_per_node=1 --master_port=4321 train.py -opt options/train/GoPro_S2.yml --launcher pytorch
#python train.py -opt options/train/GoPro_S2.yml --launcher pytorch
pip install einops -i https://pypi.tuna.tsinghua.edu.cn/simple
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.2 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.
pip install numpy==1.26.4 -i https://pypi.tuna.tsinghua.edu.cn/simple
七、AutofocusSAR
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n AutofocusSAR python=3.8
source activate AutofocusSAR
pip install cython i
pip install torchbox torchsar -i https://pypi.tuna.tsinghua.edu.cn/simple
八、LoFormer
https://github.com/INVOKERer/LoFormer
https://github.com/INVOKERer/LoFormer
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
source activate hi_diff_2
九。DEA-Net
DEA-Net: Single image dehazing based on detail-enhanced convolution and content-guided attention
(IEEE TIP 2024)
https://github.com/cecret3350/DEA-Net
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n DEA-Net python=3.8
source activate DEA-Net
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
CUDA_VISIBLE_DEVICES=0 python train.py --epochs 300 --iters_per_epoch 5000 --finer_eval_step 1400000 --w_loss_L1 1.0 --w_loss_CR 0.1 --start_lr 0.0001 --end_lr 0.000001 --exp_dir ../experiment/ --model_name DEA-Net-CR --dataset HAZE4K
File "/home/zkti/data_16T/2.Test_SAR_imaging/1.Deep_SAR_Imaging/DEA-Net-main/code/model/modules/cga.py", line 14, in forward
x2 = torch.concat([x_avg, x_max], dim=1)
AttributeError: module 'torch' has no attribute 'concat'
十、DehazeFormer
Vision Transformers for Single Image Dehazing
https://github.com/IDKiro/DehazeFormer?tab=readme-ov-file
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n DehazeFormer python=3.8
source activate DehazeFormer
pip install torch==1.9.0+cu111 torchvision==0.10.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html
十一、C2PNet
https://github.com/YuZheng9/C2PNet
https://github.com/hpc203/C2PNet-onnxrun
[CVPR 2023] Curricular Contrastive Regularization for Physics-aware Single Image Dehazing
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n c2pnet python=3.7.11
source activate c2pnet
pip install torch==1.10.0+cu111 torchvision==0.11.0+cu111 -f https://download.pytorch.org/whl/torch_stable.html
pip install -r requirements.txt
pip install tqdm -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install h5py -i https://pypi.tuna.tsinghua.edu.cn/simple
CUDA_VISIBLE_DEVICES=0 python main.py --crop --crop_size=240 --blocks=19 --gps=3 --bs=2 --lr=0.0001 --trainset='its_train' --testset='its_test' --steps=1000000 --eval_step=5000 --clcrloss --clip
十二、NAFNet
https://github.com/megvii-research/NAFNet/tree/main
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n NAFNet python=3.9.5
source activate NAFNet
# CUDA 11.3
pip install torch==1.11.0+cu113 torchvision==0.12.0+cu113 --extra-index-url https://download.pytorch.org/whl/cu113
十二、mmediting
1. 模型环境配置
https://github.com/Libyte/mmediting/tree/main
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n mmediting python=3.8 -y
source activate mmediting
conda install pytorch==2.0.0 torchvision==0.15.0 pytorch-cuda=11.8 -c pytorch -c nvidia
pip install -U openmim -i https://pypi.tuna.tsinghua.edu.cn/simple
#安装mmcv-full ,一定要安装和cuda版本、pytorch版本对应的版本,如下命令
##pip install mmcv-full=={MMCV_VERSION} -f https://download.openmmlab.com/mmcv/dist/{CUDA_VERSION}/{TORCH_VERSION}/index.html
pip install mmcv==2.0.0 -f https://download.openmmlab.com/mmcv/dist/cu118/torch2.0/index.html -i https://pypi.tuna.tsinghua.edu.cn/simple
##Install mmcv
https://mmcv.readthedocs.io/zh-cn/latest/get_started/installation.html
pip3 install -e . -i https://pypi.tuna.tsinghua.edu.cn/simple
AssertionError: mmcv==2.2.0 is used but incompatible. Please install mmcv-full>=[2, 0, -1, 1], <[2, 1, 0].
【Python报错】已解决 ModuleNotFoundError: No module named ‘transformers‘
pip install transformers -i https://pypi.tuna.tsinghua.edu.cn/simple
# single-gpu train
CUDA_VISIBLE=0 python tools/train.py configs/nafnet/nafnet_c64eb11128mb1db1111_8xb8-lr1e-3-400k_gopro.py --work-dir work_dirs/nafnet_c64eb11128mb1db1111_8xb8-lr1e-3-400k_gopro
CUDA_VISIBLE=0 python tools/train.py config_tang/nafnet/nafnet_SAR_Imaging.py
CUDA_VISIBLE=0 python tools/train.py config_tang/nafnet_v2/nafnet_SAR_Imaging.py
CUDA_VISIBLE=0 python tools/train.py config_tang/deblurganv2/deblurganv2_fpn-inception_1xb1_gopro.py
CUDA_VISIBLE=0 python tools/train.py configs/example_config.py --work-dir work_dirs/example
十三、Sparse_SAR_Imaging(师弟)
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n Sparse_SAR_Imaging python=3.11 -y
source activate Sparse_SAR_Imaging
conda install pytorch==2.2.2 torchvision==0.17.2 pytorch-cuda=12.1 -c pytorch -c nvidia
十四、SRCNN
https://github.com/yjn870/SRCNN-pytorch?tab=readme-ov-file
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
source activate c2pnet
python train.py --train-file "BLAH_BLAH/91-image_x2_converted.h5" \
--eval-file "BLAH_BLAH/91-image_x2_converted.h5" \
--outputs-dir "BLAH_BLAH/outputs" \
--scale 2 \
--lr 1e-4 \
--batch-size 16 \
--num-epochs 400 \
--num-workers 8 \
--seed 123
python test.py --weights-file "/home/zkti/data_16T/2.Test_SAR_imaging/1.Deep_SAR_Imaging/3.image_super/0.SRCNN/code2/SRCNN-pytorch-master/BLAH_BLAH/outputs/x2/epoch_26.pth" \
--image-file "data/butterfly_GT.bmp" \
--scale 2
十五、SimDeblur
https://github.com/ljzycmd/SimDeblur
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
source activate c2pnet (torch==1.10.0)
bash Install.sh -i https://pypi.tuna.tsinghua.edu.cn/simple
CUDA_VISIBLE_DEVICES=0 bash ./tools/train.sh ./configs/mscnn/mscnn_gopro.yaml 1
If you installed CuPy via wheels (cupy-cudaXXX or cupy-rocm-X-X), make sure that the package matches with the version of CUDA or ROCm installed.
pip install cupy-cuda122 -i https://pypi.tuna.tsinghua.edu.cn/simple
conda install cupy -i https://pypi.tuna.tsinghua.edu.cn/simple
十六、MIRNetv2
https://github.com/swz30/MIRNetv2/tree/main
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
source activate NAFNet
pip install matplotlib scikit-learn scikit-image opencv-python yacs joblib natsort h5py tqdm -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install einops gdown addict future lmdb numpy pyyaml requests scipy tb-nightly yapf lpips -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tb-nightly -i https://mirrors.aliyun.com/pypi/simple
python setup.py develop --no_cuda_ext
https://github.com/Kobaayyy/Awesome-ECCV2024-ECCV2020-Low-Level-Vision/blob/master/ECCV2024.md
十七:sentinel
https://github.com/Rich-Hall/sentinel1decoder?tab=readme-ov-file
https://github.com/Rich-Hall/sentinel1Level0DecodingDemo
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
source activate sentinel
conda create -n sentinel python=3.8
source activate sentinel
pip install nbconvert -i https://pypi.tuna.tsinghua.edu.cn/simple
jupyter nbconvert --to script sentinel1Level0DecodingDemo.ipynb
pip install object_detection_metrics -i https://pypi.tuna.tsinghua.edu.cn/simple
#pip install pillow matplotlib scikit-image opencv-python pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install scikit-image -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tqdm -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install pandas -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install scipy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install h5py -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install sympy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install cupy -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install rasterio -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install tifffile -i https://pypi.tuna.tsinghua.edu.cn/simple
conda search gdal
conda install gdal==3.6.2
conda install pytorch==2.2.1 torchvision==0.17.1 torchaudio==2.2.1 pytorch-cuda=12.1 -c pytorch -c nvidia
圣保罗
ASF下载,时间选取2020至2023,选取S3条带模式,HH,VV,Dual H,Dual V,Dual HV,Dual VH
https://github.com/jmfriedt/sentinel1_level0?tab=readme-ov-file#point-like-target-the-sao-paulo-stripmap-sm-dataset
十七-1 SSFocus
https://github.com/sirbastiano/SSFocus/tree/main
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
source activate activate SSFocus
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n SSFocus python=3.8
pip install pillow matplotlib scikit-image opencv-python tqdm pandas scipy h5py sympy cupy netcdf4 h5netcdf rasterio rioxarray rioxarray scikit-learn xarray geopandas asf_search seaborn tzlocal regex -i https://pypi.tuna.tsinghua.edu.cn/simple
conda search gdal
conda install gdal==3.6.2
运行具有“SSFocus (Python 3.8.20)”的单元格需要ipykernel包。
运行以下命令,将 "ipykernel" 安装到 Python 环境中。
命令: "conda install -n SSFocus ipykernel --update-deps --force-reinstall"
git https://github.com/Rich-Hall/sentinel1decoder
cd sentinel1decoder
pip install .
pip install torch==2.0.0+cu118 torchvision==0.15.1+cu118 -f https://download.pytorch.org/whl/torch_stable.html -i https://pypi.tuna.tsinghua.edu.cn/simple
十八:CI-CDNet
https://github.com/bianlab/CI-CDNet/tree/main
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
source activate c2pnet
十九:ADMM-CSNet
https://github.com/yangyan92/Pytorch_ADMM-CSNet/tree/main
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
source activate hi_diff
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
二十:mmdetection
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
source activate mmdetection
https://blog.csdn.net/xiao_9626/article/details/136803906
首先确定已安装好MMDetection环境,能正常运行 demo/image_demo.py 输出内容。
这里需要注意一点,如果高版本MMDetection安装输出有问题,建议安装低版本的库 mmcv<2.0以及mmdet<3.0,以及更低版本的pytorch<2.0,这一点非常关键,在MMDetection高版本上运行不了的程序,在低版本上是可以运行的。
————————————————
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/xiao_9626/article/details/136803906
1. 模型环境配置
https://github.com/ultralytics/ultralytics
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create -n mmdet_214 python=3.8 -y
source activate mmdet_214
#conda install pytorch==2.2.0 torchvision==0.17.0 torchaudio==2.2.0 pytorch-cuda=12.1 -c pytorch -c nvidia
#conda install pytorch==2.0.0 torchvision==0.15.0 torchaudio==2.0.0 pytorch-cuda=11.7 -c pytorch -c nvidia
conda install pytorch==1.13.0 torchvision==0.14.0 torchaudio==0.13.0 pytorch-cuda=11.7 -c pytorch -c nvidia
import torch
print(torch.cuda.is_available())
print(torch.cuda.get_device_name())
print(torch.cuda.current_device())
print(torch.cuda.device_count())
print(torch.__version__)
print(torch.version.cuda)
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu117/torch1.13.0/index.html -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install mmdet -i https://pypi.tuna.tsinghua.edu.cn/simple
#安装mmcv-full ,一定要安装和cuda版本、pytorch版本对应的版本,如下命令
##pip install mmcv-full=={MMCV_VERSION} -f https://download.openmmlab.com/mmcv/dist/{CUDA_VERSION}/{TORCH_VERSION}/index.html
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu117/torch2.0/index.html -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install -r requirements/build.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
python setup.py develop
##Install mmcv
https://mmcv.readthedocs.io/zh-cn/latest/get_started/installation.html
pip install mmcv==2.2.0 -f https://download.openmmlab.com/mmcv/dist/cu117/torch2.0/index.html -i https://pypi.tuna.tsinghua.edu.cn/simple
问题:AssertionError: MMCV==2.2.0 is used but incompatible. Please install mmcv>=2.0.0rc4, <2.2.0.
解决方法: pip uninstall mmcv
pip install mmcv==2.0.0 -f https://download.openmmlab.com/mmcv/dist/cu117/torch2.0/index.html
pip install mmdet<3.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install -r requirements/build.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
##其中pip install -v -e .or python setup.py develop将会安装为开发模式,所有对源码的修改都将生效。(pip install -v -e .最后的.表示当前路径,不要漏掉!)
#pip install -v -e . -i https://pypi.tuna.tsinghua.edu.cn/simple
python setup.py develop
pip install pillow -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install matplotlib -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install scikit-image -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install timm
1.1.3 训练自己数据集
Faster RCNN训练pascalvoc数据集:
https://zhuanlan.zhihu.com/p/162730118
【mmdetection】使用自定义的coco格式数据集进行训练及测试
https://blog.csdn.net/gaoyi135/article/details/90613895
https://zhuanlan.zhihu.com/p/101983661
https://blog.csdn.net/qq122716072/article/details/115245410
SourceURL:file:///home/zkti/data_16T/0.Test_tang/test_tang/经典目标检测模型使用教程-20240715.docx
Faster RCNN训练pascalvoc数据集:
https://zhuanlan.zhihu.com/p/162730118
【mmdetection】使用自定义的coco格式数据集进行训练及测试
https://blog.csdn.net/gaoyi135/article/details/90613895
https://zhuanlan.zhihu.com/p/101983661
https://blog.csdn.net/qq122716072/article/details/115245410
1.1.3.1 不重写Dataset加载模块
1.训练pascalvoc数据集
参考https://blog.csdn.net/weixin_41010198/article/details/106258366
mmdetectionv2.14版本
1)新建文件夹
在mmdetection内新建configs_tang_voc_COCO和work_dirs两个文件夹
configs_tang_voc_COCO:放入读入数据库和运行pascalvoc数据集的模型
work_dirs:放入训练时的缓存模型
2)复制文件夹
首先将mmdetection/config中的‘_base_’和‘pascal_voc’ 文件夹复制到configs_tang_voc_COCO内
‘_base_/datasets’:存放读取voc数据集的程序voc0712.py
‘pascal_voc’ :存放运行pascalvoc数据集的模型
3)修改python程序
mmdetection/configs_tang_voc_COCO/_base_/datasets/voc0712.py:data_root='文件夹位置'
mmdetection/mmdet/core/evaluation/class_names.py: 修改类别def voc_classes()
mmdetection/mmdet/datasets/voc.py : 修改类别CLASSES=()
模型修改
mmdetection/configs_tang_voc_COCO/pascal_voc/retinanet_r50_fpn_1x_voc0712.py: num_classes=20
4)运行训练
python tools/train.py configs_tang_voc_COCO/pascal_voc/retinanet_r50_fpn_1x_voc0712.py --gpus 1
mmdetection中出现 loss为 nan的情况
参考网址:http://events.jianshu.io/p/f111eaf4393d
5)运行测试
Python demo_batch_test_mmdet.py
(1) demo_batch_test_mmdet.py 这里要注意,一定要设置置信度为0.01,具体看mAP
(2) map_tang.py :
超参数:这里一定要这样设置,否则计算map极其慢
图像,真值,输出结果路径
7)DIOR的test数据集测试结果(训练集为train,不是trainval)
模型:
2. 训练coco数据集
1)coco数据集格式
coco
-anancontions
-train2017
-val2017
-test2017
2)pascalvoc转coco格式
(1)创建coco格式文件夹
(2)查看数据集类别: voc_labelname.py
(3)移动/VOCdevkit/VOC2007/JPEGImages到
coco/train2017,coco/val2017,coco/test2017文件夹:select_test.py
(4)pascalvoc转coco格式程序:2.voc2coco_mmdetection.py
(参考mmdetection/tools/dataset_converters/pascal_voc.py)
(5)COCO格式可视化:4.visual_coco.py
3)新建文件夹
在mmdetection内新建configs_tang_voc_COCO和work_dirs两个文件夹
configs_tang_voc_COCO:放入读入数据库和运行coco数据集的模型
work_dirs:放入训练时的缓存模型
4)复制文件夹
首先将mmdetection/config中的‘_base_’和‘retinanet’ 文件夹复制到configs_tang_voc_COCO内
‘_base_/datasets’:存放读取voc数据集的程序voc0712.py
‘retinanet’ :存放运行coco数据集的retinanet模型
5)修改python程序
mmdetection/configs_tang_voc_COCO/_base_/datasets/coco_detection.py:data_root='文件夹位置'
mmdetection/configs_tang_voc_COCO/_base_/datasets/coco_instance.py:data_root='文件夹位置'
#mmdetection/mmdet/core/evaluation/class_names.py: 修改类别def coco_classes()
mmdetection-main/mmdet/evaluation/functional/class_names.py: 修改类别def coco_classes()
mmdetection/mmdet/datasets/coco.py : 修改类别CLASSES=()
注意:只要修改一次,就得执行python setup.py install命令,否则mmdete会按照以前的类别计算,报错。
模型修改
mmdetection/configs_tang_voc_COCO/_base_/models/retinanet_r50_fpn.py: num_classes=80
6)运行训练
configs_tang_voc_COCO/retinanet/retinanet_r50_caffe_fpn_1x_coco.py
python tools/train.py configs_tang_voc_COCO/retinanet/retinanet_r50_caffe_fpn_1x_coco.py --gpus 1
7)运行测试
Python demo_batch_test_mmdet.py
(1) demo_batch_test_mmdet.py 这里要注意,一定要设置置信度为0.01,具体看mAP
(2) map_tang.py :
超参数:这里一定要这样设置,否则计算map极其慢
图像,真值,输出结果路径
mmdetection ValueError: need at least one array to concatenate 已解决
https://blog.csdn.net/weixin_52869984/article/details/137930813
21:X-AnyLabeling
https://github.com/CVHub520/X-AnyLabeling/blob/main/docs/zh_cn/get_started.md
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
source activate x-anylabeling
python anylabeling/app.py
export PATH=/home/zkti/data_16T/miniconda3/bin:$PATH
conda create --name x-anylabeling python=3.9 -y
source activate x-anylabeling
pip install onnxruntime -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install onnxruntime-gpu -i https://pypi.tuna.tsinghua.edu.cn/simple
pip install -r requirements-gpu.txt -i https://pypi.tuna.tsinghua.edu.cn/simple
pyrcc5 -o anylabeling/resources/resources.py anylabeling/resources/resources.qrc
python anylabeling/app.py