If you're using a notebook, then you most likely must have mixed up the variables. As input_dim
is not defined in your snippet but might have been previously in your scope.
Assuming you are using summary
from torchsummary
, you don't need data to infer the model's structure, only the input shape. The following will work:
class LogisticRegression(nn.Module):
def __init__(self, input_features, num_classes):
super(LogisticRegression, self).__init__()
self.fc1 = nn.Linear(input_features, num_classes) # <- was input_dim
def forward(self, x_in, apply_softmax = False):
y_pred = self.fc1(x_in)
if apply_softmax:
y_pred = F.softmax(y_pred, dim = 1)
return y_pred
INPUT_DIM = 10
NUM_CLASSES = 100
model = LogisticRegression(input_features=INPUT_DIM, num_classes=NUM_CLASSES)
summary(model, input_size=(INPUT_DIM,))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…