Hi all,
I am using a feature extraction module as given below:
class FeatureExtractionModule(nn.Module):
def __init__(self,feature_dimension,input_channels, kernel_size = 5, dropout_p = 0.3,leakiness = 0.01):
super(FeatureExtractionModule,self).__init__()
# Defining the hyperparameters of the convolutinal feature extraction network
self.feature_dimension = feature_dimension
self.input_channels = input_channels
self.kernel_size = kernel_size
self.dropout_p = dropout_p
self.leakiness = leakiness
# Below defined are the smaller modules (individual operartions) in the convolutional network using the hyperparameters defined above
self.conv1 = nn.Conv2d(self.input_channels,64,kernel_size = self.kernel_size)
self.bn1 = nn.BatchNorm2d(64)
self.max_pool1 = nn.MaxPool2d(2)
self.leaky_relu1 = nn.LeakyReLU(negative_slope = self.leakiness, inplace=True)
self.conv2 = nn.Conv2d(64,50,kernel_size = self.kernel_size)
self.bn2 = nn.BatchNorm2d(50)
self.drop1 = nn.Dropout2d(p=self.dropout_p)
self.max_pool2 = nn.MaxPool2d(2)
self.leaky_relu2 = nn.LeakyReLU(negative_slope = self.leakiness, inplace=True)
self.flatten = nn.Flatten()
# Defining the forward function which does the forward pass through the network - this function returns the features extracted from an image when it is passed though the feature extraction CNN
def forward(self,x):
x = self.conv1(x)
x = self.bn1(x)
x = self.max_pool1(x)
x = self.leaky_relu1(x)
x = self.conv2(x)
x = self.bn2(x)
x = self.drop1(x)
x = self.max_pool2(x)
x = self.leaky_relu2(x)
x = self.flatten(x)
x = F.linear(x,(self.feature_dimension,x.shape[1]))
return x
But, whenever I do a forward pass through this model I get the following error in the second to last line
( x = F.linear(x,(self.feature_dimension,x.shape[1]))
) which is as follows:
File "/Users/megh/Work/github-repos/iisc_project/deep-domain-adaptation/dann/mnist/scripts/train/cnn_modules.py", line 45, in forward
x = F.linear(x,(self.feature_dimension,x.shape[1]))
File "/Users/megh/anaconda3/envs/pytorch/lib/python3.8/site-packages/torch/nn/functional.py", line 1612, in linear
output = input.matmul(weight.t())
AttributeError: 'tuple' object has no attribute 't'
I have been trying to find an answer to this but have not been successful so far, not sure why the linear layer throws this error. Please help if anyone has any ideas.
Thanks