def test_vgg_score(): if K.image_data_format() == 'channels_first': x1 = K.variable(np.random.random((1, 3, 224, 224))) x2 = K.variable(np.random.random((1, 21, 312, 312))) y_shape = (1, 21, 224, 224) else: x1 = K.variable(np.random.random((1, 224, 224, 3))) x2 = K.variable(np.random.random((1, 312, 312, 21))) y_shape = (1, 224, 224, 21) score = vgg_score(crop_offset='centered')(x1, x2) assert K.int_shape(score) == y_shape
def VGGDecoder(pyramid, scales, classes): """(Deprecated) A Functional decoder for the VGG Nets. :param: pyramid: A list of features in pyramid, scaling from large receptive field to small receptive field. The bottom of the pyramid is the input image. :param: scales: A list of weights for each of the feature map in the pyramid, sorted in the same order as the pyramid. :param: classes: Integer, number of classes. """ if len(scales) != len(pyramid) - 1: raise ValueError('`scales` needs to match the length of' '`pyramid` - 1.') blocks = [] features = pyramid[:-1] for i in range(len(features)): block_name = 'feat{}'.format(i + 1) if i < len(features) - 1: block = vgg_deconv(classes=classes, scale=scales[i], kernel_size=(4, 4), strides=(2, 2), crop_offset='centered', weight_decay=1e-3, block_name=block_name) else: block = vgg_deconv(classes=classes, scale=scales[i], kernel_size=(16, 16), strides=(8, 8), crop_offset='centered', weight_decay=1e-3, block_name=block_name) blocks.append(block) # Crop the decoded feature to match the image blocks.append(vgg_score(crop_offset='centered')) return Decoder(pyramid=pyramid, blocks=blocks)