Created
June 27, 2019 08:44
-
-
Save Lexie88rus/8f00340160b85c81bc535942e11d006f to your computer and use it in GitHub Desktop.
SiLU demo (in class)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create class for basic fully-connected deep neural network | |
class ClassifierSiLU(nn.Module): | |
''' | |
Demo classifier model class to demonstrate SiLU | |
''' | |
def __init__(self): | |
super().__init__() | |
# initialize layers | |
self.fc1 = nn.Linear(784, 256) | |
self.fc2 = nn.Linear(256, 128) | |
self.fc3 = nn.Linear(128, 64) | |
self.fc4 = nn.Linear(64, 10) | |
def forward(self, x): | |
# make sure the input tensor is flattened | |
x = x.view(x.shape[0], -1) | |
# apply silu function | |
x = silu(self.fc1(x)) | |
# apply silu function | |
x = silu(self.fc2(x)) | |
# apply silu function | |
x = silu(self.fc3(x)) | |
x = F.log_softmax(self.fc4(x), dim=1) | |
return x | |
# Create demo model | |
model = ClassifierSiLU() | |
# Run training | |
train_model(model) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment