I have seen similar questions, but most seem a little more involved. My problem seems to me to be very straightforward, yet I cannot figure it out. I am simply trying to define a class and then instantiate it, but the arguments passed to the constructor are not recognized.
import torch
import torch.nn as nn
import torch.optim as optim
import torch.nn.functional as F
from torch.utils.data import DataLoader
import torchvision.transforms as transforms
# fully connected network
class NN(nn.Module):
def __int__(self, in_size, num_class):
super(NN, self).__init__()
self.fc1 = nn.Linear(in_size, 50)
self.fc2 = nn.Linear(50, num_class)
def forward(self, x):
x = F.relu(self.fc1(x))
x = self.fc2(x)
return x
# initialize network
model = NN(in_size=input_size, num_class=num_classes)
I get the error: __init__() got an unexpected keyword argument 'in_size'
I am using Python 3.1, PyTorch 1.7.1, using PyCharm on macOS Monterey. Thank you
You have a typo: it should be __init__
instead of __int__
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.