mmdetection环境安装

3 篇文章 0 订阅
1 篇文章 0 订阅

mmdetection环境安装: faster-rcnn 使用过程配置 mmdetection

mmdetection 的环境安装参考官方文档

https://github.com/open-mmlab/mmdetection/blob/master/docs/get_started.md

遇到的问题如下

第三步Install mmcv-full时,发现自己的cuda是10.1的,然后pytorch是1.7.1的然后就用了这条命令:
pip install mmcv-full -f https://download.openmmlab.com/mmcv/dist/cu101/torch1.7.1/index.html
实际上是错误的,但是没有报错,他就直接给你按了一个最新版本的mmcv-full,这和我想要的是不一样的,我要的是 cuda10.1,pytorch1.7.1的。并没有这样的组合。

安装过程

  1. conda create -n mmdetection python=3.7 # 创建虚拟环境mmdetection
  2. conda activate mmdetection / source activate mmdetection #(ubuntu服务器上可能是后面的命令)
  3. git clone https://github.com/open-mmlab/mmdetection.git #下载mmdetection
  4. cd mmdetection #要是已经下载过mmdetection,3和4两步不用执行
  5. conda install pytorch=1.6.0 torchvision=0.7.0 cudatoolkit=10.2 -c pytorch
  6. pip install mmcv-full==1.3.8 -f https://download.openmmlab.com/mmcv/dist/cu102/torch1.6.0/index.html
  7. pip install -r requirements/build.txt
  8. pip install -v -e .
    最后两步是在 mmdetection 目录下执行

数据集

mdetection 支持VOC格式数据集,还有COCO数据集格式,还可以自定义数据格式,我们采用VOC的数据格式

-VOC2007
------Annotations
------ImageSets
------Main
------JEPGImages
1.如果数据集没有进行划分, 划分数据集代码如下:(代码用于生成-VOC2007/Main 中的train.txt ,test.txt ,val.txt ,txt已有的话可以不用)参考: link


import os
import random

trainval_percent = 0.8 #划分比例
train_percent = 0.8 #划分比例
xmlfilepath = 'Annotations'
txtsavepath = 'ImageSets\Main'
total_xml = os.listdir(xmlfilepath)

num = len(total_xml)
list = range(num)
tv = int(num * trainval_percent)
tr = int(tv * train_percent)
trainval = random.sample(list, tv)
train = random.sample(trainval, tr)

ftrainval = open('ImageSets/Main/trainval.txt', 'w')
ftest = open('ImageSets/Main/test.txt', 'w')
ftrain = open('ImageSets/Main/train.txt', 'w')
fval = open('ImageSets/Main/val.txt', 'w')

for i in list:
    name = total_xml[i][:-4] + '\n'
    if i in trainval:
        ftrainval.write(name)
        if i in train:
            ftrain.write(name)
        else:
            fval.write(name)
    else:
        ftest.write(name)

ftrainval.close()
ftrain.close()
fval.close()
ftest.close()

修改配置文件

参考大佬的帖子: https://zhuanlan.zhihu.com/p/162730118

  1. cd /mmdetection/configs/base/datasets
    打开voc0712.py 修改如下:带 #*# 就是修改的地方
    train_pipeline 中:
    		# dataset settings
    dataset_type = 'VOCDataset'
    #data_root = 'data/VOCdevkit/'
    data_root = '/data1/lirz/DATA/data_board_pascal/zyc-voc/'
    img_norm_cfg = dict(
        mean=[123.675, 116.28, 103.53], std=[58.395, 57.12, 57.375], to_rgb=True)
    train_pipeline = [
        dict(type='LoadImageFromFile'),
        dict(type='LoadAnnotations', with_bbox=True),
        # dict(type='Resize', img_scale=(1000, 600), keep_ratio=True),
        dict(type='Resize', img_scale=(640, 512), keep_ratio=True),
        dict(type='RandomFlip', flip_ratio=0.5),
        dict(type='Normalize', **img_norm_cfg),
        dict(type='Pad', size_divisor=32),
        dict(type='DefaultFormatBundle'),
        dict(type='Collect', keys=['img', 'gt_bboxes', 'gt_labels']),
    ]
    test_pipeline = [
        dict(type='LoadImageFromFile'),
        dict(
            type='MultiScaleFlipAug',
            # img_scale=(1000, 600),
            img_scale=(640, 512),
            flip=False,
            transforms=[
                dict(type='Resize', keep_ratio=True),
                dict(type='RandomFlip'),
                dict(type='Normalize', **img_norm_cfg),
                dict(type='Pad', size_divisor=32),
                dict(type='ImageToTensor', keys=['img']),
                dict(type='Collect', keys=['img']),
            ])
    ]
    data = dict(
        samples_per_gpu=1,
        # workers_per_gpu=2,
        workers_per_gpu=1,
        train=dict(
            type='RepeatDataset',
            times=3,
            dataset=dict(
                type=dataset_type,
                ann_file=[
                    data_root + 'VOC2007/ImageSets/Main/trainval.txt',
                    # data_root + 'VOC2012/ImageSets/Main/trainval.txt'
                ],
                # img_prefix=[data_root + 'VOC2007/', data_root + 'VOC2012/'],
                img_prefix=[data_root + 'VOC2007/'],
                pipeline=train_pipeline)),
        val=dict(
            type=dataset_type,
            ann_file=data_root + 'VOC2007/ImageSets/Main/test.txt',
            img_prefix=data_root + 'VOC2007/',
            pipeline=test_pipeline),
        test=dict(
            type=dataset_type,
            ann_file=data_root + 'VOC2007/ImageSets/Main/test.txt',
            img_prefix=data_root + 'VOC2007/',
            pipeline=test_pipeline))
    evaluation = dict(interval=1, metric='mAP')
    
    
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值