[英]unexpected keyword argument trying to instantiate a class inheriting from torch.nn.Module
我見過類似的問題,但大多數似乎都涉及更多。 我的問題在我看來很簡單,但我無法弄清楚。 我只是想定義一個 class 然后實例化它,但是傳遞給構造函數的 arguments 無法識別。
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)
我得到錯誤: __init__() got an unexpected keyword argument 'in_size'
我正在使用 Python 3.1、PyTorch 1.7.1,在 CMonterey.macOS 上使用 Z4149CE0EE30A909A28362C583ZFF20 謝謝
你有一個錯字:它應該是__init__
而不是__int__
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.