@ptrblck sir please explain what is input shape …i forgot …and also  …i am having a similar error with my code …plz help me figure it out …
here is the snippet::
-- coding: utf-8 --
import cv2
import torch
import torch.nn as nn
import torch.nn.functional as F
import os
from PIL import Image
import torch.optim as optim
from torch.autograd import Variable
import numpy as np
import json
#loading the cascades
face_cascade =cv2.CascadeClassifier(“haarcascade_frontalface_default.xml”)
eye_cascade =cv2.CascadeClassifier(“haarcascade_eye.xml”)
#definnig a function that will do the detections
def detect(gray,frame):
faces=face_cascade.detectMultiScale(gray,1.3,5)
for (x,y,w,h) in faces :
cv2.rectangle(frame,(x,y),(x+w,y+h),(255,0,0),2)
roi_gray=gray[y:y+h,x:x+w]
roi_color=frame[y:y+h,x:x+w]
eyes=eye_cascade.detectMultiScale(roi_gray,1.1,3)
for (ex,ey,ew,eh) in eyes :
cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)
return frame
#applying the detect function
class CNN(nn.Module):
def init(self,num_inputs):
super(CNN, self).init()
self.conv1 = nn.Conv2d(num_inputs, 32, 3, stride=2, padding=1)
self.conv2 = nn.Conv2d(32, 32, 3, stride=2, padding=1)
self.conv3 = nn.Conv2d(32, 32, 3, stride=2, padding=1)
self.conv4 = nn.Conv2d(32, 32, 3, stride=2, padding=1)
self.fc1 = nn.Linear(in_features =3233 , out_features = 40)
self.fc2 = nn.Linear(in_features = 40, out_features = 2)
def forward(self,x):
x = F.relu(F.max_pool2d(self.conv1(x), 3, 2))
x = F.relu(F.max_pool2d(self.conv2(x), 3, 2))
x = F.relu(F.max_pool2d(self.conv3(x), 3, 2))
x = x.view(x.size(0), -1)
x = F.relu(self.fc1(x))
x = self.fc2(x)
return x
#train your neural network
cnn=CNN(3)#specify the number of input parameters
Setting some hyperparameters
batchSize = 4 # We set the size of the batch.
imageSize = 64 # We set the size of the generated images (64x64).
path=r"C:\Users\SHRIKANT\Music\Downloads\Simple_Linear_Regression\computer-vision\Module 3 - GANs"
Creating the transformations
#transform = transforms.Compose([transforms.Scale(imageSize), transforms.ToTensor(), transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),]) # We create a list of transformations (scaling, tensor conversion, normalization) to apply to the input images.
#dataloader = torch.utils.data.DataLoader(dataset, batch_size = batchSize, shuffle = True, num_workers = 2) # We use dataLoader to get the images of the training set batch by batch.
os.chdir(path)
loss = nn.MSELoss()
for epoch in range(25):
#train to find adarsh pandey
  for l in range(1,66):
      fak=Image.open(str(l)+".png").convert("RGB")
      img = Image.open(self.paths[index])
      x = TF.to_tensor(img)
      x = x[:3]
       #with open (str(l)+".png",'rb') as fak:  
      input=Variable(torch.from_numpy(np.array(fak,dtype='uint8'))).unsqueeze(0)
      #np.array( img, dtype='uint8' )
      output=cnn(input)
      optimizer = optim.Adam(cnn.parameters(), lr = 0.001)
      #what if optimizer.zero_grad()was here?? any effect .......plz check it 
      loss_error=loss(output,input)
      optimizer.zero_grad()
      
      loss_error.backward()
      optimizer.step()
  #training for identyfying of shubhi pandey
  
  
  #training ends here 
  probs=F.softmax(output)
  label=probs.multinomial()[0]
  print(label)

video_capture=cv2.VideoCapture(0)
#f_name=100
while True:
_,frame=video_capture.read()
gray=cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
canvas=detect(gray,frame)



#os.chdir(path)

#cv2.imwrite(str(f_name)+".png",frame)
cv2.imshow('Video',canvas)
#f_name=f_name+1
if cv2.waitKey(1) & 0xFF ==ord('q'):
    break

video_capture.release()
cv2.destroyAllWindows()