Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
bob.learn.pytorch
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
bob
bob.learn.pytorch
Commits
8881e90f
Commit
8881e90f
authored
6 years ago
by
Olegs NIKISINS
Browse files
Options
Downloads
Patches
Plain Diff
Sigmoid is now optional in the TwoLayerMLP
parent
bc460d80
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!14
MLP class and config to train it
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bob/learn/pytorch/architectures/TwoLayerMLP.py
+15
-3
15 additions, 3 deletions
bob/learn/pytorch/architectures/TwoLayerMLP.py
with
15 additions
and
3 deletions
bob/learn/pytorch/architectures/TwoLayerMLP.py
+
15
−
3
View file @
8881e90f
...
...
@@ -14,10 +14,10 @@ import torch.nn.functional as F
#==============================================================================
# Define the network:
class
TwoLayerMLP
(
nn
.
Module
):
"""
A simple two-layer MLP for binary classification.
A simple two-layer MLP for binary classification. The output activation
function is sigmoid.
Attributes
----------
...
...
@@ -26,9 +26,13 @@ class TwoLayerMLP(nn.Module):
n_hidden_relu : int
Number of ReLU units in the hidden layer of the MLP.
apply_sigmoid : bool
If set to ``True`` the sigmoid will be applied to the output of the
hidden FC layer. If ``False`` the sigmoid is not applied.
"""
def
__init__
(
self
,
in_features
,
n_hidden_relu
):
def
__init__
(
self
,
in_features
,
n_hidden_relu
,
apply_sigmoid
=
True
):
super
(
TwoLayerMLP
,
self
).
__init__
()
"""
Init method.
...
...
@@ -38,10 +42,13 @@ class TwoLayerMLP(nn.Module):
self
.
n_hidden_relu
=
n_hidden_relu
self
.
apply_sigmoid
=
apply_sigmoid
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.
...
...
@@ -57,6 +64,11 @@ class TwoLayerMLP(nn.Module):
# second fully connected activated by sigmoid:
x
=
self
.
fc2
(
x
)
if
not
self
.
apply_sigmoid
:
return
x
x
=
F
.
sigmoid
(
x
)
return
x
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment