ubuntu18.04下cuda10.0安装mmdetction

复现过程

vd .bash_history 注释:查看所有在ubuntu终端输入的命令
history是最近的输入命令的历史记录

可以用的新版本

conda create -n mmd python=3.7 -y
conda activate mmd

安装torch

conda install pytorch==1.6.0 torchvision==0.7.0 cudatoolkit=10.1

安装mmcv

pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.6.0/index.html
#上面那个安装更靠谱,不行用下面的
#pip install mmcv-full 

重新下载新包,旧的有编译文件,不要用

git clone https://github.com/open-mmlab/mmdetection.git
cd mmdetection
pip install -r requirements/build.txt

编译

#cd ..
pip install -v -e .   
 # or "python setup.py develop"

跑demo

直接跑个demo测试效果

python demo/image_demo.py demo/demo.jpg configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py checkpoints/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth --device cpu
#其中checkpoints文件下载链接: https://pan.baidu.com/s/1L3u0Kqjk1ZfDUK6QIcD6RQ  密码: 57dd

–来自百度网盘超级会员V1的分享

更改类别

改类别,coco数据集20个类别改3个

mmdetection-master\mmdet\core\evaluation\class_names.py
mmdetection-master\mmdet\datasets\coco.py	

改分类类别

class CocoDataset(CustomDataset):
    CLASSES = ('Benign', 'Malignant', 'none')
    # CLASSES = ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus',
    #            'train', 'truck', 'boat', 'traffic light', 'fire hydrant',
    #            'stop sign', 'parking meter', 'bench', 'bird', 'cat', 'dog',
    #            'horse', 'sheep', 'cow', 'elephant', 'bear', 'zebra', 'giraffe',
    #            'backpack', 'umbrella', 'handbag', 'tie', 'suitcase', 'frisbee',
    #            'skis', 'snowboard', 'sports ball', 'kite', 'baseball bat',
    #            'baseball glove', 'skateboard', 'surfboard', 'tennis racket',
    #            'bottle', 'wine glass', 'cup', 'fork', 'knife', 'spoon', 'bowl',
    #            'banana', 'apple', 'sandwich', 'orange', 'broccoli', 'carrot',
    #            'hot dog', 'pizza', 'donut', 'cake', 'chair', 'couch',
    #            'potted plant', 'bed', 'dining table', 'toilet', 'tv', 'laptop',
    #            'mouse', 'remote', 'keyboard', 'cell phone', 'microwave',
    #            'oven', 'toaster', 'sink', 'refrigerator', 'book', 'clock',
    #            'vase', 'scissors', 'teddy bear', 'hair drier', 'toothbrush')

改gpu数量和分类数量,以及数据位置等

data = dict(
    samples_per_gpu=1,
    workers_per_gpu=1,
    train=dict(
        type='RepeatDataset',
        times=3,
        dataset=dict(
            type=dataset_type,
            ann_file=data_root + 'VOC2012/ImageSets/Main/trainval.txt',
            img_prefix=data_root + 'VOC2012/',
            pipeline=train_pipeline)),
    val=dict(
        type=dataset_type,
        ann_file=data_root + 'VOC2012/ImageSets/Main/test.txt',
        img_prefix=data_root + 'VOC2012/',
        pipeline=test_pipeline),
    test=dict(
        type=dataset_type,
        ann_file=data_root + 'VOC2012/ImageSets/Main/test.txt',
        img_prefix=data_root + 'VOC2012/',
        pipeline=test_pipeline))

改完之后激活,再跑demo

pip install -v -e .
python demo/image_demo.py demo/demo.jpg configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py checkpoints/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth --device cpu

调用cuda

python faster-rnn.py
python tools/train.py cf/faster_rcnn_r50_fpn_1x_coco.py

出现的问题

懒得具体说了,反正就是踩坑

数据集更改

The `num_classes` (3) in Shared2FCBBoxHead of MMDataParallel does not matche

cuda版本不匹配

RuntimeError: nms_impl: implementation for device cuda:0 not found.

mmcv版本不匹配

nms_impl: implementation for device cuda:0 not found.

踩坑

cuda10.0在理论上应该这么装,但是一直用不了,再调试新的

"""
conda create -n mmd python=3.7 -y
conda activate mmd
conda install pytorch=1.8.1 cudatoolkit torchvision=0.9.1
pip install mmcv-full==latest+torch1.6.0+cu101 -f https://download.openmmlab.com/mmcv/dist/index.html
pip install mmcv-full=1.3.10
pip install -v -e .
python demo/image_demo.py demo/demo.jpg configs/faster_rcnn/faster_rcnn_r50_fpn_1x_coco.py 			checkpoints/faster_rcnn_r50_fpn_1x_20181010-3d1b3351.pth --device cpu
git clone https://github.com/open-mmlab/mmdetection.git
python tools/train.py cf/faster.py
"""

之前的log记录

sys.platform: linux
	Python: 3.7.10 (default, Jun  4 2021, 14:48:32) [GCC 7.5.0]
	CUDA available: True
	GPU 0: GeForce RTX 2080 Ti
	CUDA_HOME: /usr/local/cuda-10.0
	NVCC: Cuda compilation tools, release 10.0, V10.0.130
	GCC: gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
	PyTorch: 1.8.1
	PyTorch compiling details: PyTorch built with:
	  - GCC 7.3
	  - C++ Version: 201402
	  - Intel(R) oneAPI Math Kernel Library Version 2021.3-Product Build 20210617 for Intel(R) 64 architecture applications
	  - Intel(R) MKL-DNN v1.7.0 (Git Hash 7aed236906b1f7a05c0917e5257a1af05e9ff683)
	  - OpenMP 201511 (a.k.a. OpenMP 4.5)
	  - NNPACK is enabled
	  - CPU capability usage: AVX2
	  - CUDA Runtime 10.1
	  - 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_61,code=sm_61;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_37,code=compute_37
	  - CuDNN 7.6.3
	  - Magma 2.5.2
	  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, CUDA_VERSION=10.1, CUDNN_VERSION=7.6.3, 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 -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.8.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.9.1
	OpenCV: 4.5.3
	MMCV: 1.3.10
	MMCV Compiler: GCC 7.3
	MMCV CUDA Compiler: 10.1
	MMDetection: 2.14.0+
	-----------------------

数据集制作

# coding=utf-8

import os
import os.path
import xml.dom.minidom

替换xml文件存放路径

路径修改

file_path = "/home/psdz/桌面/mmd-faster-rnn/mmdetection-master/data/voc/VOC2012/Annotations"
	# 替换图片保存路径
	picture_path = "/home/psdz/桌面/mmd-faster-rnn/mmdetection-master/data/voc/VOC2012/JPEGImages"
	files = os.listdir(file_path)  # 得到文件夹下所有文件名称
	s = []
	for xmlFile in files:  # 遍历文件夹
	    if not os.path.isdir(xmlFile):  # 判断是否是文件夹,不是文件夹才打开
	        print(xmlFile)
	        # xml文件读取操作
	        # 将获取的xml文件名送入到dom解析
	        dom = xml.dom.minidom.parse(os.path.join(file_path, xmlFile))  ###最核心的部分,路径拼接,输入的是具体路径
	        root = dom.documentElement
	        # 获取标签对path之间的值
	        original_path = root.getElementsByTagName('path')
	        # 原始信息
	        p0=original_path[0]
	        path0=p0.firstChild.data   #原始路径
	        print(path0)
	        # 修改
	        jpg_name=path0.split('\\')[-1]
	        #获取图片名
	        print(jpg_name)
	        modify_path=picture_path+'/'+jpg_name   #修改后path
	        p0.firstChild.data=modify_path
	
	        # 保存修改到xml文件中
	        with open(os.path.join(file_path, xmlFile), 'w') as fh:
	            dom.writexml(fh)
	            print('修改path OK!')

聚类分类

这块单独写吧

  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值