Switch to unified view

a b/BraTs18Challege/predict_Brats.py
1
import os
2
3
os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID"
4
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
5
from tensorflow.python.client import device_lib
6
7
print(device_lib.list_local_devices())
8
9
from Vnet.model_vnet3d import Vnet3dModule
10
from dataprocess.utils import calcu_dice
11
import numpy as np
12
import pandas as pd
13
14
15
def predict():
16
    '''
17
    Preprocessing for dataset
18
    '''
19
    # Read  data set (Train data from CSV file)
20
    csvdata = pd.read_csv('dataprocess\\data/test.csv')
21
    maskdata = csvdata.iloc[:, 1].values
22
    imagedata = csvdata.iloc[:, 0].values
23
24
    dice_values = []
25
    Vnet3d = Vnet3dModule(128, 128, 64, channels=4, numclass=3, costname=("dice coefficient",), inference=True,
26
                          model_path="log\segmeation\VNet\model\Vnet3d.pd")
27
    for index in range(imagedata.shape[0]):
28
        image_gt = np.load(imagedata[index])
29
        mask_pd = Vnet3d.prediction(image_gt)
30
        mask_gt = np.load(maskdata[index])
31
        mask_gt_255 = mask_gt.copy()
32
        mask_gt_255[mask_gt == 0] = 0
33
        mask_gt_255[mask_gt != 0] = 255
34
        dice_value = calcu_dice(mask_pd, mask_gt_255)
35
        print("index,dice:", (index, dice_value))
36
        dice_values.append(dice_value)
37
    average = sum(dice_values) / len(dice_values)
38
    print("average dice:", average)
39
40
41
predict()