def buildFCN_up(incoming_net, incoming_layer, unpool,
skip=False, unpool_type='standard',
n_classes=21, out_nonlin=linear,
additional_pool=0, ae_h=False, dropout=0., bn=0):
'''
Build fcn decontracting path
Parameters
----------
incoming_net: contracting path network
incoming_layer: string, name of last layer of the contracting path
unpool: int, number of unpooling/upsampling layers we need
skip: bool, whether to skip connections
unpool_type: string, unpooling type
n_classes: int, number of classes
out_nonlin: output nonlinearity
'''
# Upsampling path
net = {}
# net['score'] = ConvLayer(incoming_net[incoming_layer], n_classes, 1,
# pad='valid', flip_filters=True)
# for loop to add upsampling layers
for p in range(unpool, 0, -1):
# Unpool and Crop if unpool_type='standard' or Depool and Conv
if p == unpool-additional_pool+1 and ae_h:
layer_name = 'h_hat'
else:
layer_name = None
UnpoolNet(incoming_net, net, p, unpool, n_classes,
incoming_layer, skip, unpool_type=unpool_type,
layer_name=layer_name, dropout=dropout, bn=bn)
# final dimshuffle, reshape and softmax
net['final_dimshuffle'] = DimshuffleLayer(net['fused_up'+str(p) if
unpool > 0 else 'score'],
(0, 2, 3, 1))
laySize = lasagne.layers.get_output(net['final_dimshuffle']).shape
net['final_reshape'] = ReshapeLayer(net['final_dimshuffle'],
(T.prod(laySize[0:3]),
laySize[3]))
net['probs'] = NonlinearityLayer(net['final_reshape'],
nonlinearity=out_nonlin)
# go back to 4D
net['probs_reshape'] = ReshapeLayer(net['probs'], (laySize[0], laySize[1],
laySize[2], n_classes))
net['probs_dimshuffle'] = DimshuffleLayer(net['probs_reshape'],
(0, 3, 1, 2))
# print('Input to last layer: ', net['probs_dimshuffle'].input_shape)
print(net.keys())
return net
评论列表
文章目录