How to initialize pretrained weights to my CNN?

I am attempting to build a convolutional neural network from scratch for object recognition. My input image size is (3, 256, 256)

Here’s my architecture for CNN.

class NutSnackClassication(MultiLabelImageClassificationBase):
    def __init__(self):
        super().__init__()
        
        self.network = nn.Sequential(
            nn.Conv2d(3, 32, kernel_size = 3, stride = 1, padding = 1),
            nn.ReLU(),
            nn.MaxPool2d(2,2),
            nn.Conv2d(32, 32, kernel_size = 3, stride = 1, padding = 1),
            nn.ReLU(),
            nn.MaxPool2d(2,2),
            
            nn.Conv2d(32, 64, kernel_size = 3, stride = 1, padding = 1),
            nn.ReLU(),
            nn.Conv2d(64, 128, kernel_size = 3, stride = 1, padding = 1),
            nn.ReLU(),
            nn.MaxPool2d(2, 2),
            nn.Conv2d(128, 256, kernel_size = 3, stride = 1, padding = 1),
            nn.ReLU(),
            nn.Conv2d(256, 256, kernel_size = 3, stride = 1, padding = 1), 
            nn.ReLU(),
            nn.MaxPool2d(2, 2),
            
            nn.Flatten(),
            nn.Linear(7*7*256, 512),
            nn.ReLU(),
            nn.Linear(512, 258),
            nn.LogSoftmax(dim = 1),
        )
    
    def forward(self, xb):
        return self.network(xb)

Instead of using pretrained model I want to initialize pretrained weights from ResNet34 and then use it for predictions. A lot of examples show how to download the model and then use it which doesn’t solve my query. So how do I approach this?

You could use the state_dict of the pretrained resnet, manipulate its keys to match the layer names of your new model (assuming all parameters have the same shape), and load it to your model.
Something like this should work:

model = NutSnackClassication()
reference = models.resnet34(pretrained=True)
sd = reference.state_dict()

# change the keys of sd here

model.load_state_dict(sd)