Skip to content
Snippets Groups Projects
Commit 4a2f7f6a authored by Olegs NIKISINS's avatar Olegs NIKISINS
Browse files

A simple two-layer MLP model

parent 9c130f65
No related branches found
No related tags found
1 merge request!14MLP class and config to train it
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
@author: Olegs Nikisins
"""
#==============================================================================
# Import here:
from torch import nn
#==============================================================================
# Define the network:
class TwoLayerMLP(nn.Module):
"""
A simple two-layer MLP for binary classification.
Attributes
----------
in_features : int
Dimensionality of the input feature vectors.
n_hidden_relu : int
Number of ReLU units in the hidden layer of the MLP
"""
def __init__(self, in_features, n_hidden_relu):
super(TwoLayerMLP, self).__init__()
"""
Init method.
"""
self.in_features = in_features
self.n_hidden_relu = n_hidden_relu
self.fc1 = nn.Linear(in_features = self.in_features, out_features = self.n_hidden_relu, bias=True)
self.fc2 = nn.Linear(in_features = self.n_hidden_relu, out_features = 1, bias=True)
def forward(self, x):
"""
The forward method.
"""
# input is a batch of the size: [batch_size, 1, self.in_features],
# convert it to the size [batch_size, self.in_features] as expected by FC layer:
x = x.squeeze()
# first fully connected activated by ReLu:
x = self.fc1(x)
x = F.relu(x)
# second fully connected activated by sigmoid:
x = self.fc2(x)
x = F.sigmoid(x)
return x
......@@ -12,6 +12,7 @@ from .ConditionalGAN import ConditionalGAN_generator
from .ConditionalGAN import ConditionalGAN_discriminator
from .ConvAutoencoder import ConvAutoencoder
from .TwoLayerMLP import TwoLayerMLP
from .utils import weights_init
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment