From d469dcb94e6442d57606355304f00687f6a9f38d Mon Sep 17 00:00:00 2001 From: Jinbo Bi Date: Sat, 11 Dec 2021 14:21:39 -0500 Subject: [PATCH] Add files via upload --- MLModel.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 MLModel.py diff --git a/MLModel.py b/MLModel.py new file mode 100644 index 0000000..8f26bc6 --- /dev/null +++ b/MLModel.py @@ -0,0 +1,40 @@ +# Several basic machine learning models +import torch +from torch import nn + + +class LogisticRegression(nn.Module): + """A simple implementation of Logistic regression model""" + def __init__(self, num_feature, output_size): + super(LogisticRegression, self).__init__() + self.linear = nn.Linear(num_feature, output_size) + + def forward(self, x): + return self.linear(x) + + + +class NeuralNet(nn.Module): + def __init__(self): + super(NeuralNet, self).__init__() + self.conv1 = nn.Conv2d(1, 6, 5) + self.conv2 = nn.Conv2d(6, 16, 5) + #self.fc1 = nn.Linear(16*5*5, 120) + self.fc1 = nn.Linear(16*4*4, 120) + self.fc2 = nn.Linear(120, 84) + self.fc3 = nn.Linear(84, 10) + + def forward(self, x): + x = F.relu(self.conv1(x)) + x = F.max_pool2d(x, 2, 2) + x = F.relu(self.conv2(x)) + x = F.max_pool2d(x, 2, 2) + #x = x.view(-1, 4*4*50) + x = x.view(-1, 16*4*4) + x = F.relu(self.fc1(x)) + x= F.relu(self.fc2(x)) + #x = self.fc2(x) + x = self.fc3(x) + return F.log_softmax(x, dim=1) + +