Last active
March 18, 2017 08:51
-
-
Save LittleWat/2922aeec5fc81983aae022c3bd98a70e to your computer and use it in GitHub Desktop.
chainerで2つの違うモーダルを共通空間に射影するときのモデルコード ref: http://qiita.com/LittleWat/items/3539cda08e3b01ae079e
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
# Network definition | |
class MLP(chainer.Chain): | |
def __init__(self, n_units, n_out): | |
super(MLP, self).__init__( | |
# the size of the inputs to each layer will be inferred | |
l1=L.Linear(None, n_units), # n_in -> n_units | |
l2=L.Linear(None, n_units), # n_units -> n_units | |
l3=L.Linear(None, n_out), # n_units -> n_out | |
) | |
def __call__(self, x): | |
h1 = F.relu(self.l1(x)) | |
h2 = F.relu(self.l2(h1)) | |
return self.l3(h2) | |
class CommonNet(chainer.Chain): | |
def __init__(self, _model1, _model2): | |
super(CommonNet, self).__init__( | |
model1 = _model1, | |
model2 = _model2, | |
) | |
def __call__(self, x, y): | |
h1 = self.model1(x) | |
h2 = self.model2(y) | |
self.loss = F.mean_squared_error(h1, h2) | |
reporter.report({'loss': self.loss}, self) | |
return self.loss | |
enc1 = MLP(10,10) | |
enc2 = MLP(10,10) | |
model = CommonNet(enc1, enc2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment