问题描述
背景
我使用预训练的 U-net 模型进行语义分割。它适用于一个堆栈 tiff 文件(具有多个切片的 CT 图像)。到目前为止我所做的:
##load pre-trained U-Net Model :
model.load_weights('/content/drive/MyDrive/Models saved/segmentation_cancer4.hdf5')
##import and preprocess new files:
large_test_stack = tiff.imread('/content/drive/MyDrive/datasets/test/Test0.tif')
SIZE=256
all_img_patches = []
for img in range(large_test_stack.shape[0]):
#print(img) #just stop here to see all file names printed
large_image = large_test_stack[img]
patches_img = patchify(large_image,(SIZE,SIZE),step=SIZE) #Step=256 for 256 patches means no overlap
for i in range(patches_img.shape[0]):
for j in range(patches_img.shape[1]):
single_patch_img = patches_img[i,j,:,:]
single_patch_img = (single_patch_img.astype('float32')) / 255.
all_img_patches.append(single_patch_img)
images = np.expand_dims(normalize(np.array(all_img_patches),axis=1),3)
##apply model segmentation:
prediction_other = (model.predict(images) > 0.9).astype(np.uint16)
##save it as segmented volume.
from tifffile import imsave
imsave('/content/drive/MyDrive/datasets/results/Resultat24.tif',prediction_other)
问题
现在我想处理代表一百名患者的堆栈 tiff 文件列表,但我正在努力寻找一种简单的方法。我需要读取多个堆栈 tiff 文件,应用模型预测,然后将每个堆栈 tiff 预测保存在单独的文件夹中。
我怎么能做到这一点?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)