赞
踩
代码:https://github.com/facebookresearch/maskrcnn-benchmark
首先按照官方文档配置环境
https://github.com/facebookresearch/maskrcnn-benchmark/blob/0ce8f6f64b5c462dc2e8cad14620a188f98b4411/INSTALL.md
就按照步骤一步一步来,要注意安pytorch的时候自己去官网选:https://pytorch.org/get-started/locally/ 不要直接复制人家的
我首先想把train跑通,所以我们要看的是github的Perform training on COCO dataset的步骤
这一部分就是在maskrcnn-benchmark 下创一个目录datasets/coco
mkdir -p datasets/coco
然后把你coco数据集在的地方移到你新创建的这个文件夹下
我的coco2017数据集在/home/coco2017 下所以我的操作是
ln -s /home/coco2017/annotations datasets/coco/annotations
ln -s /home/coco2017/train2017 datasets/coco/train2017
ln -s /home/coco2017/test2017 datasets/coco/test2017
ln -s /home/coco2017/val2017 datasets/coco/val2017
然后他代码里默认用的是coco2014,如果你的数据集是2017的话,你要去yaml文件中改一下
比如说我用的是faster_rcnn_R_101_FPN_1x.yaml,我就找到这个文件然后把14改成17,
/home/zxf/maskrcnn-benchmark/configs/e2e_faster_rcnn_R_101_FPN_1x.yaml
作者也在原文说了
P.S. COCO_2017_train = COCO_2014_train + valminusminival , COCO_2017_val = minival
所以我们要改的方式如下:
以下命令是专门为单GPU设计的
python tools/train_net.py --config-file "configs/e2e_mask_rcnn_R_50_FPN_1x.yaml" SOLVER.IMS_PER_BATCH 2 SOLVER.BASE_LR 0.0025 SOLVER.MAX_ITER 720000 SOLVER.STEPS "(480000, 640000)" TEST.IMS_PER_BATCH 1 MODEL.RPN.FPN_POST_NMS_TOP_N_TRAIN 2000
你看你要用哪种网络训练,这个yaml文件在maskrcnn-benchmark/configs/下
我下面出现的这些问题是我当初没有按官方文档配置,才出现了各种各样的奇怪的问题,后来按照官方的重新配一遍环境后,就几乎没有什么问题了。所以如果你没有配,建议先去配一下。
当然跑是不可能这么容易跑通的,下面就记录一下我出现的问题及解决方法
import sys
sys.path.append('/home/zxf/maskrcnn-benchmark')
2. ImportError: cannot import name ‘_C’ from ‘maskrcnn_benchmark’ (/home/zxf/maskrcnn-benchmark/maskrcnn_benchmark/init.py)
这个我们找到
maskrcnn_benchmark/layers
5
①对于layers下面的文件,nms.py、roi_align.py等出现这个错误的from maskrcnn_benchmark import _C都换成from ._utils import _C就解决了
②对于dcn
因为_utils和dcn同级,所以我们要做如下的操作
import sys
sys.path.append('/home/zxf/maskrcnn-benchmark/maskrcnn_benchmark/layers')
from _utils import _C
3. TypeError: Class advice impossible in Python3. Use the @Implementer class decorator instead.
pip uninstall apex
git clone https://www.github.com/nvidia/apex
cd apex
python setup.py install
修改/home/zxf/maskrcnn-benchmark/maskrcnn_benchmark/data/datasets/coco.py
coco.py的
也就是把上面三行注释掉,换成:
masks = [obj["segmentation"] for obj in anno if any(obj["segmentation"])]
通过main函数
model = train(cfg, args.local_rank, args.distributed)
得到的模型如下:
GeneralizedRCNN( (backbone): Sequential( (body): ResNet( (stem): StemWithFixedBatchNorm( (conv1): Conv2d(3, 64, kernel_size=(7, 7), stride=(2, 2), padding=(3, 3), bias=False) (bn1): FrozenBatchNorm2d() ) (layer1): Sequential( (0): BottleneckWithFixedBatchNorm( (downsample): Sequential( (0): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (1): FrozenBatchNorm2d() ) (conv1): Conv2d(64, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) (1): BottleneckWithFixedBatchNorm( (conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) (2): BottleneckWithFixedBatchNorm( (conv1): Conv2d(256, 64, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(64, 64, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(64, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) ) (layer2): Sequential( (0): BottleneckWithFixedBatchNorm( (downsample): Sequential( (0): Conv2d(256, 512, kernel_size=(1, 1), stride=(2, 2), bias=False) (1): FrozenBatchNorm2d() ) (conv1): Conv2d(256, 128, kernel_size=(1, 1), stride=(2, 2), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) (1): BottleneckWithFixedBatchNorm( (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) (2): BottleneckWithFixedBatchNorm( (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) (3): BottleneckWithFixedBatchNorm( (conv1): Conv2d(512, 128, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(128, 128, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(128, 512, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) ) (layer3): Sequential( (0): BottleneckWithFixedBatchNorm( (downsample): Sequential( (0): Conv2d(512, 1024, kernel_size=(1, 1), stride=(2, 2), bias=False) (1): FrozenBatchNorm2d() ) (conv1): Conv2d(512, 256, kernel_size=(1, 1), stride=(2, 2), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) (1): BottleneckWithFixedBatchNorm( (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) (2): BottleneckWithFixedBatchNorm( (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) (3): BottleneckWithFixedBatchNorm( (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) (4): BottleneckWithFixedBatchNorm( (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) (5): BottleneckWithFixedBatchNorm( (conv1): Conv2d(1024, 256, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn1): FrozenBatchNorm2d() (conv2): Conv2d(256, 256, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), bias=False) (bn2): FrozenBatchNorm2d() (conv3): Conv2d(256, 1024, kernel_size=(1, 1), stride=(1, 1), bias=False) (bn3): FrozenBatchNorm2d() ) ) (layer4): Sequential( (0): BottleneckWithFixedBatchNorm( (downsample): Sequential( (0): Conv2d(1024, 2048, kernel_size=(1, 1), stride=(2, 2), bias=False) (1): FrozenBatchNorm2d() ) (conv1): Conv2d(1024, 512, kernel_size=(1, 1), stride=(2, 2), bias=False) (bn1): FrozenBatchNorm2d() (
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。