ValueError: Input dimension should be at least 3

#adding the extra layers 
class added_layers(nn.Module):
  def __init__(self):
    super(added_layers,self).__init__()
    self.add = nn.Sequential(
        
        nn.AdaptiveMaxPool2d((1, 1)),
        nn.Linear(2048,256),nn.ReLU(),
        nn.Linear(256,3),nn.Softmax(dim=1)
    )

  def forward(self,x):
    add = self.add(x)

    return add

added_layer = added_layers().to('cuda')

model = nn.Sequential(model,added_layer) 
model.to('cuda')

and

#removing the fully connected layer
class nochange(nn.Module):
    def __init__(self):
        super(nochange, self).__init__()
        
    def forward(self, x):
        return x
model.fc = nochange()

#freeze the trained layers
for parameters in model.parameters():
  parameters.requires_grad = False

these are my code for combining pretrained model exception with additional layers. I am getting the following error:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-13-3b76556c6596> in <module>
      1 #model training for num_ epoch
----> 2 training_loss,val_loss  = training(model,optimizer,train_loader,val_loader,test_loader,num_epoch,device = 'cuda',save_dir = '/content/drive/MyDrive/Applied_Artificial_intelligence/saved_model')
      3 plt.plot(training_loss)

12 frames
/usr/local/lib/python3.9/dist-packages/torch/nn/modules/utils.py in _list_with_default(out_size, defaults)
     34         return out_size
     35     if len(defaults) <= len(out_size):
---> 36         raise ValueError(
     37             "Input dimension should be at least {}".format(len(out_size) + 1)
     38         )

ValueError: Input dimension should be at least 3

what would be the issue here,

(conv2): DwsConvBlock(
          (activ): ReLU()
          (conv): DwsConv(
            (dw_conv): Conv2d(1536, 1536, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=1536, bias=False)
            (pw_conv): Conv2d(1536, 2048, kernel_size=(1, 1), stride=(1, 1), bias=False)
          )
          (bn): BatchNorm2d(2048, eps=1e-05, momentum=0.1, affine=True, track_running_stats=True)
        )
        (activ): ReLU(inplace=True)
        (pool): AvgPool2d(kernel_size=10, stride=1, padding=0)
      )
    )
    (output): Linear(in_features=2048, out_features=1000, bias=True)
    (fc): nochange()
  )
  (1): added_layers(
    (add): Sequential(
      (0): AdaptiveMaxPool2d(output_size=(1, 1))
      (1): Linear(in_features=2048, out_features=256, bias=True)
      (2): ReLU()
      (3): Linear(in_features=256, out_features=3, bias=True)
      (4): Softmax(dim=1)
    )
  )
)

my last few layers are looking like this

Your input seems to be missing a dimension and I guess AdaptiveMaxPool2d is raising the error as seen here:

pool = nn.AdaptiveMaxPool2d((1, 1))

# works since [batch_size, channels, height, width] is provided
x = torch.randn(1, 3, 24, 24)
out = pool(x)
print(out.shape)
# torch.Size([1, 3, 1, 1])

# works since [channels, height, width] is provided
x = torch.randn(3, 24, 24)
out = pool(x)
print(out.shape)
# torch.Size([3, 1, 1])

# breaks
x = torch.randn(3, 24)
out = pool(x)
# ValueError: Input dimension should be at least 3
for img, label in train_loader:
  print(img.shape)
  break

my dimensions are already as you mentioned torch.Size([16, 3, 299, 299]), but still getting this error.

will it this model architecture Is correct,

        (pool): AvgPool2d(kernel_size=10, stride=1, padding=0)
      )
    )
    (output): Linear(in_features=2048, out_features=1000, bias=True)
    (fc): nochange()
  )
  (1): added_layers(
    (add): Sequential(
      (0): AdaptiveMaxPool2d(output_size=(1, 1))
      (1): Linear(in_features=2048, out_features=256, bias=True)
      (2): ReLU()
      (3): Linear(in_features=256, out_features=3, bias=True)
      (4): Softmax(dim=1)
    )
  )

did my input and output features of added_layers correct?

What is a dimension of the output tensor after

(output): Linear(in_features=2048, out_features=1000, bias=True)

According to AdaptiveMaxPool2d — PyTorch 2.0 documentation, 2D Pooling requires at least 3 dimensions as an input.

I guess the input of added_layers has 2 dimensions.
Check this by,

class added_layers(nn.Module):
  def __init__(self):
    super(added_layers,self).__init__()
    self.add = nn.Sequential(
        
        nn.AdaptiveMaxPool2d((1, 1)),
        nn.Linear(2048,256),nn.ReLU(),
        nn.Linear(256,3),nn.Softmax(dim=1)
    )

  def forward(self,x):
    print(x.shape) ######## print ##########
    add = self.add(x)

    return add

I have sought out my issue. Actually, the problem was with the Fully Connected layer, where I Have added over the existing fully connected layer in my model. After deleting the existing layer it worked. Thank you for all the replies.