How to copy intermediate layers from a pretrained model

vgg16 = models.vgg16(pretrained=True).features[:16]
brach_A = vgg16.clone()

I get the following error on the above code:
**'Sequential' object has no attribute 'clone'**

Hi,

This is because we don’t have a method to clone nn.Modules.
If you want another ref to the same module, use b = a
If you want a shallow copy, you can use the copy module from python
And if you want a deepcopy, you can use the deepcopy module from python.

2 Likes