Hi,
the following code is my customized layer.
In one of my network, I used the customized layer MSConved and torch.nn.Conv2d in one of my network.
at present, I would like use the torch.nn.Conv2d.weight to init the self.weight of my MScon2d.weight, how to do this?
as I asked in another topic: Nn.parameter re-define question 1
could parameter in customized layer be re-assigned?
is there any doc about the difference among parameter, tensor and variable in pytorch?
import os
import numpy as np 
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.modules.utils import _pair
from torch.nn.common_types import _size_2_t

class MSConv2d(nn.modules.conv._ConvNd):
    def __init__(self, in_channels: int, out_channels: int, kernel_size: _size_2_t, stride: _size_2_t = 1 ) -> None:
        super(MSConv2d, self).__init__(in_channels, out_channels, kernel_size, stride)

        self.in_channels = in_channels
        self.out_channels = out_channels    
        self.kernel_size = _pair(kernel_size)
        
        self.weight = nn.Parameter(torch.empty((out_channels, in_channels, *self.kernel_size)))
        self.gamma = nn.Parameter(torch.empty((out_channels,self.num_groups,1,*self.kernel_size)))
        # nn.init.xavier_normal_(self.weight)
        # nn.init.constant_(self.gamma,1)

    def forward(self, x):
        # self.weight = self.weight*self.gamma
        ret = F.conv2d(F.pad(input), self.weight*self.gamma)
        return ret