How do you apply Softmax Regression with Fastai V2?

I would like to perform Softmax Regression for image classification using Fastai V2, I do not want to use a pretrained model.

Is there a way to do it? Could you please show me an example?
Thank you,

This is the solution:

class SoftMax(nn.Module):
def init(self, in_size, out_size):
self.linear = nn.Linear(in_size, out_size)

def forward(self,x):
x = x.view(-1, in_size)
out = F.softmax(self.linear(x))
return out

soft_max_model = SoftMax(in_size,out_size)

1 Like