Skip to content

Instantly share code, notes, and snippets.

@Lexie88rus
Created June 27, 2019 08:44
Show Gist options
  • Save Lexie88rus/8f00340160b85c81bc535942e11d006f to your computer and use it in GitHub Desktop.
Save Lexie88rus/8f00340160b85c81bc535942e11d006f to your computer and use it in GitHub Desktop.
SiLU demo (in class)
# 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