I’m new to Pytorch and I want to use a
Since the output dimension of 512 is hardcoded in the ResNet code, you will need to write your own custom ResNet class, and redefine this value.
Since there is no block expansion in ResNet18, you don’t have to worry about this particular aspect, and I simply changing the value (on lines 112 and 114) should work (it does on my machine).
I think this is due to this line in the original code.
Since you initialize self.layer4 twice, in
super(...).__init__(...) and on the next line, this line gets called again and modifies the
self.inplanes variable, which then breaks your code. I think you really need to modify the original code and not simply extend it like you have!
Another thing, since you mentioned loading a pretrained model: as you modified a dimension in the model, the shapes of the weight and bias matrices between your architecture and the pretrained model won’t agree at that location, so you will have to either take a portion of the original matrices, or remove the faulty layers altogether and finetune your network to populate them with better values than random.
Problem solved, thanks a lot