Closed cihan55555 closed 5 years ago
Here is my code: from model_vnet3d import Vnet3dModule from util import convertMetaModelToPbModel import numpy as np import pandas as pd import cv2 import os os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" os.environ["CUDA_VISIBLE_DEVICES"] = "0"
def train(): ''' Preprocessing for dataset '''
csvmaskdata = pd.read_csv('E:/LiTS---Liver/LiTS/dataprocess/trainY.csv') csvimagedata = pd.read_csv('E:/LiTS---Liver/LiTS/dataprocess/trainX.csv') maskdata = csvmaskdata.iloc[:, :].values imagedata = csvimagedata.iloc[:, :].values # shuffle imagedata and maskdata together perm = np.arange(len(csvimagedata)) np.random.shuffle(perm) imagedata = imagedata[perm] maskdata = maskdata[perm] Vnet3d = Vnet3dModule(128, 128, 16, channels=1, costname="dice coefficient") Vnet3d.train(imagedata, maskdata, "Vnet3dModule.pd", "E:/LiTS---Liver/LiTS/log2/diceVnet3d/model/", 0.001, 0.7, 100000, 1)
def predict0(): Vnet3d = Vnet3dModule(128, 128, 16, inference=True, model_path="E:\LiTS---Liver\LiTS\log2\diceVnet3d\model\Vnet3d.pd") for filenumber in range(30): batch_xs = np.zeros(shape=(16, 128, 128)) for index in range(16): imgs = cv2.imread( "E:\LiTS---Liver\LiTS\test\image\" + str(filenumber) + "\" + str(index) + ".bmp", 0) batch_xs[index, :, :] = imgs[128:384, 128:384]
predictvalue = Vnet3d.prediction(batch_xs) for index in range(16): result = np.zeros(shape=(512, 512), dtype=np.uint8) result[128:384, 128:384] = predictvalue[index] kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (5, 5)) result = cv2.morphologyEx(result, cv2.MORPH_CLOSE, kernel) cv2.imwrite( "E:\LiTS---Liver\LiTS\\test\image\\" + str(filenumber) + "\\" + str(index) + "mask.bmp", result)
def meta2pd(): convertMetaModelToPbModel(meta_model="E:\LiTS---Liver\LiTS\log2\diceVnet3d\model\Vnet3d.pd", pb_model="model")
predict0()
your code batch_xs is (16,128,128),but imgs[128:384, 128:384] is size(256,256),you can‘t assign imgs to batch-xs
Here is my code: from model_vnet3d import Vnet3dModule from util import convertMetaModelToPbModel import numpy as np import pandas as pd import cv2 import os os.environ["CUDA_DEVICE_ORDER"] = "PCI_BUS_ID" os.environ["CUDA_VISIBLE_DEVICES"] = "0"
def train(): ''' Preprocessing for dataset '''
Read data set (Train data from CSV file)
def predict0(): Vnet3d = Vnet3dModule(128, 128, 16, inference=True, model_path="E:\LiTS---Liver\LiTS\log2\diceVnet3d\model\Vnet3d.pd") for filenumber in range(30): batch_xs = np.zeros(shape=(16, 128, 128)) for index in range(16): imgs = cv2.imread( "E:\LiTS---Liver\LiTS\test\image\" + str(filenumber) + "\" + str(index) + ".bmp", 0) batch_xs[index, :, :] = imgs[128:384, 128:384]
def meta2pd(): convertMetaModelToPbModel(meta_model="E:\LiTS---Liver\LiTS\log2\diceVnet3d\model\Vnet3d.pd", pb_model="model")
train()
predict0()
meta2pd()