def mrf_loss(source, combination, patch_size=3, patch_stride=1):
    # extract patches from feature maps
    combination_patches, combination_patches_norm = patches.make_patches(combination, patch_size, patch_stride)
    source_patches, source_patches_norm = patches.make_patches(source, patch_size, patch_stride)
    # find best patches and calculate loss
    patch_ids = patches.find_patch_matches(combination_patches, combination_patches_norm, source_patches / source_patches_norm)
    best_source_patches = K.reshape(source_patches[patch_ids], K.shape(combination_patches))
    loss = K.sum(K.square(best_source_patches - combination_patches)) / patch_size ** 2
    return loss
CNNMRF http://arxiv.org/pdf/1601.04589v1.pdf
dataset/ETHPy150Open awentzonline/image-analogies/image_analogy/losses/mrf.py/mrf_loss