-1

i'm making a code that classifies numbers by using pytorch

  epochess =[]
  train_losses = []
  test_losses = []
  acc_training =[]
  acc_testing = []
  for epoch in range (epochs):
    train_acc, train_epoch_loss = train_CNN(model,loss_function, optimizer, train_load, device)
    print('epoch',epoch ,'training loss',train_epoch_loss)
    train_losses.append(train_epoch_loss)
    print('epoch',epoch,'training accuracy',train_acc)
    acc_training.append(train_acc)
  
    test_acc, test_epoch_loss = validate_CNN(model, loss_function, test_load, device)
    print('epoch',epoch,'testing loss',test_epoch_loss)
    test_losses.append(test_epoch_loss)
    print('epoch',epoch,'testing accuracy',test_acc)
    acc_testing.append(test_acc)


    epochess.append(epoch)

and I get an erreur , I was following the right path just like it said on youtube here's the following erreur

---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
<ipython-input-17-0bcb51ebbc3d> in <module>
      5 acc_testing = []
      6 for epoch in range (epochs):
----> 7   train_acc, train_epoch_loss = train_CNN(model,loss_function, optimizer, train_load, device)
      8   print('epoch',epoch ,'training loss',train_epoch_loss)
      9   train_losses.append(train_epoch_loss)

2 frames
/usr/local/lib/python3.8/dist-packages/torch/nn/modules/module.py in _forward_unimplemented(self, *input)
    242         registered hooks while the latter silently ignores them.
    243     """
--> 244     raise NotImplementedError(f"Module [{type(self).__name__}] is missing the required \"forward\" function")
    245 
    246 

NotImplementedError: Module [CNN] is missing the required "forward" function

1 Answers1

0

How did you implement your model? Did you use a built-in model from PyTorch or did you create a custom model?

If you created a custom model, make sure you use the right components from PyTorch (e.g. torch.nn.Linear and torch.nn.Conv2d https://pytorch.org/tutorials/beginner/introyt/modelsyt_tutorial.html), otherwise PyTorch might complain about certain functions missing, like is happening in your case.

ykerus
  • 29
  • 4