def __init__(self, inputs, blocks, weights=None,
trainable=True, name='encoder'):
inverse_pyramid = []
# convolutional block
conv_blocks = blocks[:-1]
for i, block in enumerate(conv_blocks):
if i == 0:
x = block(inputs)
inverse_pyramid.append(x)
elif i < len(conv_blocks) - 1:
x = block(x)
inverse_pyramid.append(x)
else:
x = block(x)
# fully convolutional block
fc_block = blocks[-1]
y = fc_block(x)
inverse_pyramid.append(y)
outputs = list(reversed(inverse_pyramid))
super(Encoder, self).__init__(
inputs=inputs, outputs=outputs)
# load pre-trained weights
if weights is not None:
weights_path = get_file(
'{}_weights_tf_dim_ordering_tf_kernels.h5'.format(name),
weights,
cache_subdir='models')
layer_names = load_weights(self, weights_path)
if K.image_data_format() == 'channels_first':
layer_utils.convert_all_kernels_in_model(self)
# Freezing basenet weights
if trainable is False:
for layer in self.layers:
if layer.name in layer_names:
layer.trainable = False
评论列表
文章目录