Open kumarsiddappa-git opened 9 months ago
Just changing the input shape in the nn.linear region to 49 should solve the problem ig..
I suggest to add a "debug print" in your forward method like this:
(note: add log_shapes:bool = True to your model's class)
def forward(self, x):
if self.log_shapes : print(f"\nInput shape: {x.shape}")
x = self.conv_block_1(x)
if self.log_shapes : print(f"Conv Block 1 returns a shape of: {x.shape}")
x = self.conv_block_2(x)
if self.log_shapes : print(f"Conv Block 2 returns a shape of: {x.shape}")
x = self.classifier(x)
if self.log_shapes : print(f"Classifier returns a shape of (should fit count of classes): {x.shape}")
self.log_shapes = False
return x
This way you see the shape of the data within your layers.
Additional note: For productive use always combine all layer steps for the sake of performance:
return self.classifier(self.conv_block_2((self.conv_block_1(x))))
self.classifier = nn.Sequential(
nn.Flatten(),
nn.Linear(in_features=hidden_units,
out_features=output_shape
)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (10x49 and 490x10)
self.classifier = nn.Sequential(
nn.Flatten(),
nn.Linear(in_features=hidden_units *7*7, # since hidden_units = 10 and 10 * 7* 7 = 490 [matrix multiplication]
out_features=output_shape
)
RuntimeError: mat1 and mat2 shapes cannot be multiplied (10x49 and 10x10)
self.classifier = nn.Sequential(
nn.Flatten(),
nn.Linear(in_features=hidden_units * (49/10), # since hidden_units = 10 and 10 * 7/10 = 49 [matrix multiplication]
# if division doesnt work try float division hidden_units * (49//10)
out_features=output_shape
)
What is the input we need to provide for the model Conv2d (Tiny VGG) . When i send the image in shape [1,28,28] it fails , but when i unsqueeze(dim=0) to dim=0 which becomes the shape [1,1,28,28]
do we need to send the [batchsize,color channel, image width and image height]
my Model is
The model instantiation
Model train
Error thrown is
so i got the image shape is not proper when pushed to linear of classifier
when its changed the in_features = hidden_features77 , it goes to 490 , but mat problem
Can you please check on this