def design_for_residual_blocks(num_channel_input=1):
''''''
model = Sequential() # it's a CONTAINER, not MODEL
# set numbers
num_big_blocks = 3
image_patch_sizes = [[3,3]]*num_big_blocks
pool_sizes = [(2,2)]*num_big_blocks
n_features = [128, 256, 512, 512, 1024]
n_features_next = [256, 512, 512, 512, 1024]
height_input = 32
width_input = 32
for conv_idx in range(num_big_blocks):
n_feat_here = n_features[conv_idx]
# residual block 0
model.add(residual_blocks.building_residual_block( (num_channel_input, height_input, width_input),
n_feat_here,
kernel_sizes=image_patch_sizes[conv_idx]
))
# residual block 1 (you can add it as you want (and your resources allow..))
if False:
model.add(residual_blocks.building_residual_block( (n_feat_here, height_input, width_input),
n_feat_here,
kernel_sizes=image_patch_sizes[conv_idx]
))
# the last residual block N-1
# the last one : pad zeros, subsamples, and increase #channels
pad_height = compute_padding_length(height_input, pool_sizes[conv_idx][0], image_patch_sizes[conv_idx][0])
pad_width = compute_padding_length(width_input, pool_sizes[conv_idx][1], image_patch_sizes[conv_idx][1])
model.add(ZeroPadding2D(padding=(pad_height,pad_width)))
height_input += 2*pad_height
width_input += 2*pad_width
n_feat_next = n_features_next[conv_idx]
model.add(residual_blocks.building_residual_block( (n_feat_here, height_input, width_input),
n_feat_next,
kernel_sizes=image_patch_sizes[conv_idx],
is_subsample=True,
subsample=pool_sizes[conv_idx]
))
height_input, width_input = model.output_shape[2:]
# width_input = int(width_input/pool_sizes[conv_idx][1])
num_channel_input = n_feat_next
# Add average pooling at the end:
print('Average pooling, from (%d,%d) to (1,1)' % (height_input, width_input))
model.add(AveragePooling2D(pool_size=(height_input, width_input)))
return model
评论列表
文章目录