Maskrcnn-benchmark: Can't build a model a second time

Created on 29 Oct 2018  路  4Comments  路  Source: facebookresearch/maskrcnn-benchmark

Consider the following code in a Jupyter notebook:

from maskrcnn_benchmark.config import cfg
from maskrcnn_benchmark.modeling.detector import build_detection_model

model = build_detection_model(cfg)

It works if you execute it a first time. If you try to execute it a second time without restarting the kernel, it raises the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-3-c924cbd11273> in <module>
      2 from maskrcnn_benchmark.modeling.detector import build_detection_model
      3 
----> 4 model = build_detection_model(cfg)

~/local/conda/envs/nn/lib/python3.6/site-packages/maskrcnn_benchmark/modeling/detector/detectors.py in build_detection_model(cfg)
      8 def build_detection_model(cfg):
      9     meta_arch = _DETECTION_META_ARCHITECTURES[cfg.MODEL.META_ARCHITECTURE]
---> 10     return meta_arch(cfg)

~/local/conda/envs/nn/lib/python3.6/site-packages/maskrcnn_benchmark/modeling/detector/generalized_rcnn.py in __init__(self, cfg)
     27         super(GeneralizedRCNN, self).__init__()
     28 
---> 29         self.backbone = build_backbone(cfg)
     30         self.rpn = build_rpn(cfg)
     31         self.roi_heads = build_roi_heads(cfg)

~/local/conda/envs/nn/lib/python3.6/site-packages/maskrcnn_benchmark/modeling/backbone/backbone.py in build_backbone(cfg)
     42     if cfg.MODEL.BACKBONE.CONV_BODY.endswith("-FPN"):
     43         return build_resnet_fpn_backbone(cfg)
---> 44     return build_resnet_backbone(cfg)

~/local/conda/envs/nn/lib/python3.6/site-packages/maskrcnn_benchmark/modeling/backbone/backbone.py in build_resnet_backbone(cfg)
      9 
     10 def build_resnet_backbone(cfg):
---> 11     body = resnet.ResNet(cfg)
     12     model = nn.Sequential(OrderedDict([("body", body)]))
     13     return model

~/local/conda/envs/nn/lib/python3.6/site-packages/maskrcnn_benchmark/modeling/backbone/resnet.py in __init__(self, cfg)
    101 
    102         # Optionally freeze (requires_grad=False) parts of the backbone
--> 103         self._freeze_backbone(cfg.MODEL.BACKBONE.FREEZE_CONV_BODY_AT)
    104 
    105     def _freeze_backbone(self, freeze_at):

~/local/conda/envs/nn/lib/python3.6/site-packages/maskrcnn_benchmark/modeling/backbone/resnet.py in _freeze_backbone(self, freeze_at)
    108                 m = self.stem  # stage 0 is the stem
    109             else:
--> 110                 m = getattr(self, "layer" + str(stage_index))
    111             for p in m.parameters():
    112                 p.requires_grad = False

~/local/conda/envs/nn/lib/python3.6/site-packages/torch/nn/modules/module.py in __getattr__(self, name)
    516                 return modules[name]
    517         raise AttributeError("'{}' object has no attribute '{}'".format(
--> 518             type(self).__name__, name))
    519 
    520     def __setattr__(self, name, value):

AttributeError: 'ResNet' object has no attribute 'layer1'

Version used: 3308cd926bacef22bc907d508d624580245cc0d1

bug

Most helpful comment

@fmassa

Please see PR107.

I have found the reason, and give the solution.

All 4 comments

Thanks for the bug report!

I've reproduced this locally. I'm not yet sure where the problem is, but it might be related to the fact that we use a python module to hold the config.

I'll dig a bit further, but I'm currently working on implementing other parts of the system (like adding support for Keypoints), so if anyone finds out a solution please do let me know :-)

@fmassa

Please see PR107.

I have found the reason, and give the solution.

I confirm #107 fix the issue.

Fixed via #107.

Thanks a lot @GuoxiaWang

Was this page helpful?
0 / 5 - 0 ratings