def get_split(self, layer,
deterministic=True, conv_all_patches=True, **kwargs):
# Get the patches and the outputs without the non-linearities.
if type(layer) is L.DenseLayer:
x, y = get_dense_xy(layer, deterministic)
elif type(layer) is L.Conv2DLayer:
if conv_all_patches is True:
x, y = get_conv_xy_all(layer, deterministic)
else:
x, y = get_conv_xy(layer, deterministic)
else:
raise ValueError("Unknown layer as input")
# Create an output dictionary
outputs = dict()
for name, fun in subtypes:
outputs[name] = dict()
mrk_y = 1.0* T.cast(fun(y), dtype=theano.config.floatX) # (N,O)
y_current = y*mrk_y # This has a binary mask
cnt_y = T.shape_padaxis(T.sum(mrk_y, axis=0), axis=0) # (1,O)
norm = T.maximum(cnt_y, 1.)
# Count how many datapoints are considered
outputs[name]['cnt'] = cnt_y
# The mean of the current batch
outputs[name]['m_y'] = T.shape_padaxis(y_current.sum(axis=0), axis=0) / norm # (1,O) mean output for batch
outputs[name]['m_x'] = T.dot(x.T, mrk_y) / norm # (D,O) mean input for batch
# The mean of the current batch
outputs[name]['yty'] = T.shape_padaxis(T.sum(y_current ** 2., axis=0), axis=0) / norm # (1,O)
outputs[name]['xty'] = T.dot(x.T, y_current) / norm # D,O
return dict_to_list(outputs)
评论列表
文章目录