def __init__(self, id, input, pooling_shape, pooling_type, stride=None): ErrorHandler.is_type_generic(pooling_shape, tuple) ErrorHandler.is_type_generic(pooling_type, PoolingType) super().__init__(id, [input]) self.pooling_shape = pooling_shape self.pooling_type = pooling_type self.stride = stride
def fill_data(self, new_data): copied_data = new_data if isinstance(copied_data, list): copied_data = np.asarray(new_data, dtype=float) else: ErrorHandler.is_type_generic(copied_data, np.ndarray) ErrorHandler.is_equal(self.shape, copied_data.shape) self.__data = copied_data
def calc_output_shape(self, input_shape): ErrorHandler.is_type_generic(input_shape, tuple) nout = input_shape[0] cout = input_shape[1] hout = int((input_shape[2] - (self.pooling_shape[0] - 1) - 1) / self.stride[0] + 1) wout = int((input_shape[3] - (self.pooling_shape[1] - 1) - 1) / self.stride[1] + 1) return (nout, cout, hout, wout)
def __init__(self, id, inputs, axis=0): ErrorHandler.is_list(inputs) ErrorHandler.is_type_generic(axis, int) super().__init__(id, inputs) self.axis = axis
def __init__(self, id, input, new_shape): ErrorHandler.is_type_generic(new_shape, tuple) super().__init__(id, [input]) self.new_shape = new_shape
def __init__(self, id, memory): ErrorHandler.is_type_generic(memory, Memory) super().__init__(id, []) self.memory = memory
def add_node(self, node): ErrorHandler.is_type_generic(node, Node) if node.id in self.nodes_map: ErrorHandler.raise_error(node.id + "is already in nodes_map!!!") self.nodes_map[node.id] = node
def __init__(self, id, input, activation_function): ErrorHandler.is_type_generic(activation_function, ActivationFunctions) super().__init__(id, [input]) self.activation = activation_function
def __init__(self, shape): ErrorHandler.is_type_generic(shape, tuple) self.shape = shape self.__data = np.empty(shape)