class FCLayer (Layer): def __init__ (self, *args, **kwargs): super (FCLayer, self).__init__ (*args, **kwargs) self.weights = None self.bias = None # initialize variables. can't happen in __init__ because request_vars might need to happen first def init_variables (self): w_shape = [self.input_shape [1], self.output_shape [1]] b_shape = [1, self.output_shape [1]] self.weights = Variable (self.vm.pop_indices (), w_shape, self.vm) self.bias = Variable (self.vm.pop_indices (), b_shape, self.vm) # input_ * weights + bias def eval (self, input_): return np.dot (input_, self.weights.get ()) + self.bias.get () # [input, output], [output] def request_vars (self): self.vm.request_vars (self.input_shape [1] * self.output_shape [1]) self.vm.request_vars (self.output_shape [1])