def compare_seg_with_gt(max_n_images=10, epoch=0):
    data_gen_validation = SegmentationBatchGeneratorDavid(
        all_patients,
        BATCH_SIZE,
        validation_patients,
        PATCH_SIZE=INPUT_PATCH_SIZE,
        mode="test",
        ignore=[81, 10, 47],
        losses=None,
        num_batches=None,
        seed=10,
    )
    data_gen_validation = seg_channel_selection_generator(data_gen_validation, [2])
    data_gen_validation = center_crop_seg_generator(data_gen_validation, OUTPUT_PATCH_SIZE)
    data, seg, idx = data_gen_validation.next()
    seg = np.array(seg)
    seg_pred = get_segmentation(data)
    plt.figure(figsize=(6, 20))
    n_images = np.min((seg_pred.shape[0], max_n_images))
    for i in range(n_images):
        seg_pred[i][0, :6] = np.array([0, 1, 2, 3, 4, 5])
        seg[i, 0, 0, :6] = np.array([0, 1, 2, 3, 4, 5])
        plt.subplot(n_images, 2, 2 * i + 1)
        plt.imshow(seg[i, 0])
        plt.subplot(n_images, 2, 2 * i + 2)
        plt.imshow(seg_pred[i])
    plt.savefig(os.path.join(results_dir, "some_segmentations_ep_%d.png" % epoch))
def compare_seg_with_gt(max_n_images=10, epoch=0):
    data_gen_validation = SegmentationBatchGeneratorDavid(
        all_patients,
        BATCH_SIZE,
        validation_patients,
        PATCH_SIZE=OUTPUT_PATCH_SIZE,
        mode="test",
        ignore=[81],
        losses=None,
        num_batches=None,
        seed=10)
    data_gen_validation = seg_channel_selection_generator(
        data_gen_validation, [2])
    data_gen_validation = center_crop_seg_generator(data_gen_validation,
                                                    OUTPUT_PATCH_SIZE)
    data, seg, idx = data_gen_validation.next()
    seg = np.array(seg)
    seg_pred = get_segmentation(data)
    plt.figure(figsize=(6, 20))
    n_images = np.min((seg_pred.shape[0], max_n_images))
    for i in range(n_images):
        seg_pred[i][0, :6] = np.array([0, 1, 2, 3, 4, 5])
        seg[i, 0, 0, :6] = np.array([0, 1, 2, 3, 4, 5])
        plt.subplot(n_images, 2, 2 * i + 1)
        plt.imshow(seg[i, 0])
        plt.subplot(n_images, 2, 2 * i + 2)
        plt.imshow(seg_pred[i])
    plt.savefig(
        os.path.join(results_dir, "some_segmentations_ep_%d.png" % epoch))
class_frequencies2 *= len(class_frequencies)


'''d, s, l = data_gen_train.next()
plt.figure(figsize=(12, 5))
plt.subplot(1, 3, 1)
plt.imshow(d[0,0], cmap="gray")
plt.subplot(1, 3, 2)
d1=elastic_transform_2d(d[0,0], 550., 20.)
plt.imshow(d1, cmap="gray")
plt.subplot(1, 3, 3)
plt.imshow(d[0,0]-d1)
plt.show()
plt.close()'''

data_gen_validation = SegmentationBatchGeneratorDavid(all_patients, BATCH_SIZE, validation_patients, PATCH_SIZE=INPUT_PATCH_SIZE, mode="test", ignore=[81], losses=None, num_batches=None, seed=None)
data_gen_validation = seg_channel_selection_generator(data_gen_validation, [2])
data_gen_validation = center_crop_seg_generator(data_gen_validation, OUTPUT_PATCH_SIZE)
data_gen_validation = Multithreaded_Generator(data_gen_validation, 2, 10)
data_gen_validation._start()

net = build_UNet(25, BATCH_SIZE, num_output_classes=num_classes, base_n_filters=16, input_dim=INPUT_PATCH_SIZE, pad="valid")
output_layer_for_loss = net["output_flattened"]

n_batches_per_epoch = 300
# n_batches_per_epoch = np.floor(n_training_samples/float(BATCH_SIZE))
n_test_batches = 30
# n_test_batches = np.floor(n_val_samples/float(BATCH_SIZE))

x_sym = T.tensor4()
seg_sym = T.ivector()