Vision: ResNet identity (line 55) mustn't be mutable

Created on 20 Nov 2019  路  3Comments  路  Source: pytorch/vision

The identity variable in line 55 is mutable
def forward(self, x):
identity = x

It must be immutable as follows:

def forward(self, x):
    identity = 1*x
models question

All 3 comments

Why do you think so? If I'm not mistaken no inplace operation is performed on identity and thus x is never changed inplace:

https://github.com/pytorch/vision/blob/8aec85deb447d415abc0788d8dc301a727cc69fb/torchvision/models/resnet.py#L57-L73

Additionally, if we go through with your proposal, it would be clearer to do

identity = x.clone()

than a multiplication by one.

Oh, my mistake, you are right. x is never changed. it was another implementation, with similar residual conenction that x was getting changed hence identitiy.

Thanks for helping out @pmeier !

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alpha-gradient picture alpha-gradient  路  3Comments

chinglamchoi picture chinglamchoi  路  3Comments

martinarjovsky picture martinarjovsky  路  4Comments

datumbox picture datumbox  路  3Comments

Wadaboa picture Wadaboa  路  3Comments