def __init__(self, kernel_shape=list, input_variable=jen.Variable, name=str, stride=1, padding='SAME'): # kernel_shape = [ksize, ksize, input_channels, output_channels] for i in kernel_shape: if not isinstance(i, int): raise Exception( "Operator Conv2D name: %s kernel shape is not list of int" % self.name) if not isinstance(input_variable, jen.Variable): raise Exception( "Operator Conv2D name: %s's input_variable is not instance of Variable" % name) if len(input_variable.shape) != 4: raise Exception( "Operator Conv2D name: %s's input_variable's shape != 4d Variable!" % name) self.ksize = kernel_shape[0] self.stride = stride self.output_num = kernel_shape[-1] self.padding = padding self.col_image = [] self.weights = jen.Variable(kernel_shape, scope=name, name='weights', learnable=True) self.bias = jen.Variable([self.output_num], scope=name, name='bias', learnable=True) self.batch_size = input_variable.shape[0] if self.padding == 'SAME': _output_shape = [ self.batch_size, int(input_variable.shape[1] / stride), int(input_variable.shape[2] / stride), self.output_num ] if self.padding == 'VALID': _output_shape = [ self.batch_size, int((input_variable.shape[1] - self.ksize + 1) / stride), int((input_variable.shape[2] - self.ksize + 1) / stride), self.output_num ] self.output_variables = jen.Variable(_output_shape, name='out', scope=name) # .name self.input_variables = input_variable super(Conv2D, self).__init__(name, self.input_variables, self.output_variables)
def __init__(self, predict=jen.Variable, label=jen.Variable, name=str): self.batch_size = predict.shape[0] self.input_variables = [predict, label] self.loss = jen.Variable([1], name='loss', scope=name) self.prediction = jen.Variable(predict.shape, name='prediction', scope=name) self.softmax = np.zeros(self.prediction.shape) self.output_variables = [self.loss, self.prediction] super(SoftmaxLoss, self).__init__(name, self.input_variables, self.output_variables)
def __init__(self, input_variable=jen.Variable, name=str): self.input_variables = input_variable self.output_variables = jen.Variable(self.input_variables.shape, name='out', scope=name) super(Tanh, self).__init__(name, self.input_variables, self.output_variables)
def __init__(self, ksize=2, input_variable=jen.Variable, name=str, stride=2): if not isinstance(input_variable, jen.Variable): raise Exception( "Operator Conv2D name: %s's input_variable is not instance of Variable" % name) self.ksize = ksize self.stride = stride self.batch_size = input_variable.shape[0] self.output_channels = input_variable.shape[-1] self.index = np.zeros(input_variable.shape) self.input_variables = input_variable _output_shape = [ self.batch_size, int(input_variable.shape[2] / stride), int(input_variable.shape[2] / stride), self.output_channels ] self.output_variables = jen.Variable(_output_shape, name='out', scope=name) super(MaxPooling, self).__init__(name, self.input_variables, self.output_variables)
def __init__(self, input_variable=jen.Variable, name=str, alpha=0.1): self.input_variables = input_variable self.output_variables = jen.Variable(self.input_variables.shape, name='out', scope=name) self.alpha = alpha super(Elu, self).__init__(name, self.input_variables, self.output_variables)
def __init__(self, input_variable=jen.Variable, name=str, alpha=0.25): self.input_variables = input_variable self.output_variables = jen.Variable(self.input_variables.shape, name='out', scope=name) self.alpha = alpha self.momentum = 0.9 self.eta = 1e-4 super(Prelu, self).__init__(name, self.input_variables, self.output_variables)
def __init__(self, name, phase, input_variable=jen.Variable, prob=0.5): self.input_variables = input_variable self.output_variables = jen.Variable(shape=input_variable.shape, scope=name, name='out') self.prob = prob self.phase = phase self.index = np.ones(input_variable.shape) super(DropOut, self).__init__(name, self.input_variables, self.output_variables)
def __init__(self, output_num, input_variable=jen.Variable, name=str): if not isinstance(input_variable, jen.Variable): raise Exception( "Operator Conv2D name: %s's input_variable is not instance of Variable" % name) self.batch_size = input_variable.shape[0] input_len = ft.reduce(lambda x, y: x * y, input_variable.shape[1:]) self.output_num = output_num self.weights = jen.Variable([input_len, self.output_num], name='weights', scope=name, learnable=True) self.bias = jen.Variable([self.output_num], name='bias', scope=name, learnable=True) self.output_variables = jen.Variable( [self.batch_size, self.output_num], name='out', scope=name) self.input_variables = input_variable super(FullyConnect, self).__init__(name, self.input_variables, self.output_variables)