Skip to content

Instantly share code, notes, and snippets.

@regonn
Last active March 29, 2019 23:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save regonn/86fe60a714082a4639f8bcd5af56d110 to your computer and use it in GitHub Desktop.
Save regonn/86fe60a714082a4639f8bcd5af56d110 to your computer and use it in GitHub Desktop.
@pydef mutable struct MLP <: Chain
function __init__(self, n_mid_units=100, n_out=10)
pybuiltin(:super)(MLP, self)[:__init__]()
@pywith self.init_scope() begin
self.l1 = L.Linear(py"None", n_mid_units)
self.l2 = L.Linear(py"None", n_mid_units)
self.l3 = L.Linear(py"None", n_out)
end
end
function forward(self, x)
h1 = F.relu(self.l1(x))
h2 = F.relu(self.l2(h1))
return self.l3(h2)
end
end
class MLP(Chain):
def __init__(self, n_mid_units=100, n_out=10):
super(MLP, self).__init__()
with self.init_scope():
self.l1 = L.Linear(None, n_mid_units)
self.l2 = L.Linear(None, n_mid_units)
self.l3 = L.Linear(None, n_out)
def forward(self, x):
h1 = F.relu(self.l1(x))
h2 = F.relu(self.l2(h1))
return self.l3(h2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment