def build(self, input_shape):
if input_shape[2] % self.shared_pool[0] != 0 or input_shape[3] % self.shared_pool[1] != 0:
raise Exception('Layer only works if input dimensions can be divided by shared pool dimensions')
nb_x_pools = int(input_shape[2]/self.shared_pool[0])
nb_y_pools = int(input_shape[3]/self.shared_pool[1])
output_shape = self.get_output_shape_for(input_shape)
if self.dim_ordering == 'th':
_, nb_filter, output_row, output_col = output_shape
input_filter = input_shape[1]
elif self.dim_ordering == 'tf':
_, output_row, output_col, nb_filter = output_shape
input_filter = input_shape[3]
else:
raise Exception('Invalid dim_ordering: ' + self.dim_ordering)
self.output_row = output_row
self.output_col = output_col
self.W_shape = (nb_filter,input_filter,nb_x_pools,nb_y_pools)#(output_row * output_col, self.nb_row * self.nb_col * input_filter, nb_filter)
self.W = self.init(self.W_shape, name='{}_W'.format(self.name))
if self.bias:
self.b = K.zeros((nb_filter,nb_x_pools, nb_y_pools), name='{}_b'.format(self.name))
self.trainable_weights = [self.W, self.b]
else:
self.trainable_weights = [self.W]
self.regularizers = []
if self.W_regularizer:
self.W_regularizer.set_param(self.W)
self.regularizers.append(self.W_regularizer)
if self.bias and self.b_regularizer:
self.b_regularizer.set_param(self.b)
self.regularizers.append(self.b_regularizer)
if self.activity_regularizer:
self.activity_regularizer.set_layer(self)
self.regularizers.append(self.activity_regularizer)
self.constraints = {}
if self.W_constraint:
self.constraints[self.W] = self.W_constraint
if self.bias and self.b_constraint:
self.constraints[self.b] = self.b_constraint
if self.initial_weights is not None:
self.set_weights(self.initial_weights)
del self.initial_weights
layers.py 文件源码
python
阅读 20
收藏 0
点赞 0
评论 0
评论列表
文章目录