Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Can't build a model a second time #57

Closed
hadim opened this issue Oct 29, 2018 · 4 comments
Closed

Can't build a model a second time #57

hadim opened this issue Oct 29, 2018 · 4 comments
Labels
bug Something isn't working

Comments

@hadim
Copy link
Contributor

hadim commented Oct 29, 2018

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: 3308cd9

@fmassa fmassa added the bug Something isn't working label Oct 29, 2018
@fmassa
Copy link
Contributor

fmassa commented Oct 29, 2018

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 :-)

@GuoxiaWang
Copy link
Contributor

GuoxiaWang commented Nov 4, 2018

@fmassa

Please see PR107.

I have found the reason, and give the solution.

@hadim
Copy link
Contributor Author

hadim commented Nov 4, 2018

I confirm #107 fix the issue.

@fmassa
Copy link
Contributor

fmassa commented Nov 4, 2018

Fixed via #107.

Thanks a lot @GuoxiaWang

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants