def plot_prediction(stage='test',name_file='_VHR_60_fake',out_file='VHR',name_model='UNet11',fold_out=0,fold_in=0,epochs=40, count=30): # #HR •dist
    loss_file = open(("predictions/{}/pred_loss_{}{}_{}_foldout{}_foldin{}_{}epochs.txt").format(out_file,stage,name_file,name_model,fold_out,fold_in,epochs))
  
    filedata = loss_file.read()
    filedata = filedata.replace("bce",",bce")
    filedata = filedata.split(",")

    val_file = (("predictions/{}/inputs_{}{}_{}_foldout{}_foldin{}_{}epochs_{}.npy").format(out_file, stage, name_file,name_model,fold_out,fold_in,epochs, count))
    pred_file =(("predictions/{}/pred_{}{}_{}_foldout{}_foldin{}_{}epochs_{}.npy").format(out_file, stage, name_file,name_model,fold_out,fold_in,epochs, count))
    label_file = (("predictions/{}/labels_{}{}_{}_foldout{}_foldin{}_{}epochs_{}.npy").format(out_file, stage, name_file,name_model,fold_out,fold_in,epochs, count))

    val_images = np.load(val_file)
    pred_images = np.load(pred_file)
    val_label = np.load(label_file)
    print(val_images.shape,val_label.shape,pred_images.shape)
    input_images_rgb = [helper.reverse_transform(x,out_file) for x in val_images[:,0,:3,:,:]]   #new metrics 30 cantidad de imagenes to plot
    # Map each channel (i.e. class) to each color
    #target_masks_rgb = [helper.masks_to_colorimg(x) for x in val_label[:,0,:3,:,:]]
    #pred_rgb = [helper.masks_to_colorimg(x) for x in pred_images[:,0,:,:,:]]
    target_masks_rgb = [helper.masks_to_colorimg_3clases(x) for x in val_label[:30,0,:3,:,:]]
    pred_rgb = [helper.masks_to_colorimg_3clases(x) for x in pred_images[:30,0,:,:,:]]
    
    name_output=("{}{}_{}_foldout{}_foldin{}_{}epochs").format(stage, name_file,name_model,fold_out,fold_in,epochs)
  
   # stage + name_file + name_model+'_foldin' +str(fold_in)
    helper.plot_side_by_side([input_images_rgb, target_masks_rgb, pred_rgb],filedata, out_file, name_output, save=1)
Exemplo n.º 2
0
# Generate some random images
input_images, target_masks = simulation.generate_random_data(192, 192, count=3)

print(input_images.shape, target_masks.shape)

# Change channel-order and make 3 channels for matplot
input_images_rgb = [
    (x.swapaxes(0, 2).swapaxes(0, 1) * -255 + 255).astype(np.uint8)
    for x in input_images
]

# Map each channel (i.e. class) to each color
target_masks_rgb = [helper.masks_to_colorimg(x) for x in target_masks]

# Left: Input image, Right: Target mask
helper.plot_side_by_side([input_images_rgb, target_masks_rgb])

#%%
from torchvision import models

base_model = models.resnet18(pretrained=True)


def find_last_layer(layer):
    children = list(layer.children())
    if len(children) == 0:
        return layer
    else:
        return find_last_layer(children[-1])