Regarding initializing old_conv_layer to some base layer


This is design decision. If you need to fall back to some network then only you should do this. Otherwise, have assert to ensure you get the error.
How to add assert?  assert(old_conv_layer), “Old Conv Layer is not initialized”


Regarding int(_i) > 2


it is iterating over module items and is number is classifier net of current model.
I would recommend to print model and model.classifier just to understand which all layers are there
also print model.classifier._modules.items()
If condition is ensuring you are replacing first Conv2d placed after two layers.
This is again design decision.
Try to understand the architecture and what is being accomplished and why second layer needs to be replaced.
I guess, if old_conv_layer is None i.e. not found then you don’t have to use old_weights. So, just use initialized values as new_weights and ensure you don’t use old_conv_layer related variables (this will avoid use of assert)