Exemple #1
0
def metric_evaluation(dataTest,dataTestGT):
    careRes=[]
    resultImgs=[]
    inputImgs=[]
    model = UNet(1,depth=3)
    model.load_state_dict(torch.load(MODEL_DIR+'/model.pt'))
    model.eval()
    ## Testing on 5 images for demo purpose
    for index in range(5):
        im=dataTest[index]
        gt=dataTestGT[0] # The ground truth is the same for all images
        careResult = prediction.tiledPredict(im, model ,ps=256, overlap=48,device=device, noiseModel=None)
        inputImgs.append(im)
        rangePSNR=np.max(gt)-np.min(gt)
        carePrior=PSNR(gt, careResult, rangePSNR )
        careRes.append(carePrior) 
    print("Avg PSNR CARE:", np.mean(np.array(careRes) ), '+-(2SEM)',2*np.std(np.array(careRes) )/np.sqrt(float(len(careRes)) ) )
    #### Logging the metric using mlflow #######
    mlflow.log_metric("Avg_PSNR_CARE",np.mean(np.array(careRes)))
Exemple #2
0
    train_loader = torch.utils.data.DataLoader(dataset=isbi_dataset,
                                               batch_size=1,
                                               shuffle=True)
    criterion = nn.BCEWithLogitsLoss()
    # Select the device, if there is cuda use cuda, if not, use cpu
    device = torch.device('cpu' if torch.cuda.is_available() else 'cpu')
    # Load the network, the picture is single channel, classified as 1.
    net = UNet(n_channels=1, n_classes=9)
    # Copy the network to the deivce
    net.to(device=device)
    # Load model parameters
    net.load_state_dict(
        torch.load('/home/nonari/Descargas/best_model_v1.pth',
                   map_location=device))
    # Test mode
    net.eval()

    img = cv2.imread("/home/nonari/Documentos/tfgdata/tfgoct/img_9_20.png")
    lab = cv2.imread("/home/nonari/Documentos/tfgdata/tfgoct/seg_9_20.png")
    # Convert to grayscale
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    lab = cv2.cvtColor(lab, cv2.COLOR_BGR2GRAY)
    # Convert to batch as 1, channel as 1, size 512*512 array

    # Convert to tensor
    lab_tensor = im_to_tensor(lab)
    lab_tensor = torch.unsqueeze(lab_tensor, 0)
    img_tensor = im_trans(img)

    img_tensor = torch.unsqueeze(img_tensor, 0)
    # Copy tensor to device, only use cpu means copy to cpu, use cuda means copy to cuda.