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

Fix repeatedly invoke build_detection_model error. #107

Merged
merged 1 commit into from
Nov 4, 2018

Conversation

GuoxiaWang
Copy link
Contributor

Bug

When I repeatedly invoke build_detection_model function to build the model, I will get the error: AttributeError: 'ResNet' object has no attribute 'layer1'.

To Reproduce

model = build_detection_model(cfg)
model = build_detection_model(cfg)

The reason

The variable ResNet50StagesTo4 is a global generator expression, so when we build the model secondly, the code executes to Line 82 for stage_spec in stage_specs: and stage_specs will return empty leading to do not add any stage. Finally, self._freeze_backbone try to freeze the backbone by executing m = getattr(self, "layer" + str(stage_index)) firstly. At the moment, it will throw the AttributeError AttributeError: 'ResNet' object has no attribute 'layer1'.

I guess you want to define ResNet50StagesTo4 as the tuple, so I try to fix by add tuple type qualifier.

The solution

Add the tuple type to ResNet50StagesTo5, ResNet50StagesTo4, ResNet50FPNStagesTo5, ResNet101FPNStagesTo5.

I do not know whether there are similar bugs existing, so you need to review my solution. Thank you!

## Bug
When I repeatedly invoke build_detection_model function to build the model, I will get the error: `AttributeError: 'ResNet' object has no attribute 'layer1'`. 

## To Reproduce
```
model = build_detection_model(cfg)
model = build_detection_model(cfg)
```

## The reason
The variable `ResNet50StagesTo4` is a global generator expression, so when we build the model secondly, the code executes to Line 82 `for stage_spec in stage_specs:` and `stage_specs` will return empty leading to do not add any stage. Finally, `self._freeze_backbone` try to freeze the backbone by executing `m = getattr(self, "layer" + str(stage_index))` firstly. At the moment, it will throw the AttributeError `AttributeError: 'ResNet' object has no attribute 'layer1'`.

I guess you want to define ResNet50StagesTo4 as the tuple, so I try to fix by add tuple type qualifier.

## The solution
Add the tuple type to `ResNet50StagesTo5`, `ResNet50StagesTo4`, `ResNet50FPNStagesTo5`, `ResNet101FPNStagesTo5`.

I do not know whether there are similar bug existing, so you need to review my solution. Thank you!
@facebook-github-bot
Copy link

Thank you for your pull request and welcome to our community. We require contributors to sign our Contributor License Agreement, and we don't seem to have you on file. In order for us to review and merge your code, please sign up at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need the corporate CLA signed.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

Copy link
Contributor

@fmassa fmassa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks a lot for finding and fixing this bug!

@fmassa fmassa merged commit 0527726 into facebookresearch:master Nov 4, 2018
@GuoxiaWang GuoxiaWang deleted the patch-1 branch November 5, 2018 02:44
nprasad2021 pushed a commit to nprasad2021/maskrcnn-benchmark that referenced this pull request Jan 29, 2019
)

## Bug
When I repeatedly invoke build_detection_model function to build the model, I will get the error: `AttributeError: 'ResNet' object has no attribute 'layer1'`. 

## To Reproduce
```
model = build_detection_model(cfg)
model = build_detection_model(cfg)
```

## The reason
The variable `ResNet50StagesTo4` is a global generator expression, so when we build the model secondly, the code executes to Line 82 `for stage_spec in stage_specs:` and `stage_specs` will return empty leading to do not add any stage. Finally, `self._freeze_backbone` try to freeze the backbone by executing `m = getattr(self, "layer" + str(stage_index))` firstly. At the moment, it will throw the AttributeError `AttributeError: 'ResNet' object has no attribute 'layer1'`.

I guess you want to define ResNet50StagesTo4 as the tuple, so I try to fix by add tuple type qualifier.

## The solution
Add the tuple type to `ResNet50StagesTo5`, `ResNet50StagesTo4`, `ResNet50FPNStagesTo5`, `ResNet101FPNStagesTo5`.

I do not know whether there are similar bug existing, so you need to review my solution. Thank you!
@ravichaurasia
Copy link

ravichaurasia commented Aug 31, 2020

Thanks for the answer. Replacing resnet.py code to this worked for me

ResNet50StagesTo5 = tuple(
    StageSpec(index=i, block_count=c, return_features=r)
    for (i, c, r) in ((1, 3, False), (2, 4, False), (3, 6, False), (4, 3, True))
)
# ResNet-50 up to stage 4 (excludes stage 5)

ResNet50StagesTo4 = tuple(
    StageSpec(index=i, block_count=c, return_features=r)
    for (i, c, r) in ((1, 3, False), (2, 4, False), (3, 6, True))
)
# ResNet-50-FPN (including all stages)

ResNet50FPNStagesTo5 = tuple(
    StageSpec(index=i, block_count=c, return_features=r)
    for (i, c, r) in ((1, 3, True), (2, 4, True), (3, 6, True), (4, 3, True))
)
# ResNet-101-FPN (including all stages)

ResNet101FPNStagesTo5 = tuple(
    StageSpec(index=i, block_count=c, return_features=r)
    for (i, c, r) in ((1, 3, True), (2, 4, True), (3, 23, True), (4, 3, True))
)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants