Last active
August 29, 2015 14:24
-
-
Save ktnyt/9a61e3d5b74722824309 to your computer and use it in GitHub Desktop.
FunctionSet model for Chainer based Convolutional Denoising Autoencoder
This file contains hidden or 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
class ConvolutionalAutoencoder(FunctionSet): | |
def __init__(self, n_in, n_out, ksize, stride=1, pad=0, wscale=1, bias=0, nobias=False): | |
super(ConvolutionalAutoencoder, self).__init__( | |
encode=F.Convolution2D(n_in, n_out, ksize, stride=stride, pad=pad, wscale=wscale, bias=bias, nobias=nobias), | |
decode=F.Convolution2D(n_out, n_in, ksize, stride=stride, pad=pad, wscale=wscale, bias=bias, nobias=nobias) | |
) | |
def forward(self, x_data, train=True): | |
x = Variable(x_data) | |
t = Variable(x_data) | |
if train: | |
x = F.dropout(x) | |
h = F.sigmoid(self.encode(x)) | |
y = F.sigmoid(self.decode(h)) | |
return F.mean_squared_error(y, t) | |
def encode(self, x_data): | |
x = Variable(x_data) | |
h = F.sigmoid(self.encode(x)) | |
return h.data | |
def decode(self, h_data): | |
h = Variable(h_data) | |
y = F.sigmoid(self.decode(h)) | |
return y |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment