脑胶质瘤的测试代码

该代码实现了一种基于SOLOv2模型的多阶段医学图像分割流程。首先,对Flair、CET1和T2序列图像进行预处理和融合,然后使用四个不同阶段的模型进行预测,每个阶段的模型分别进行一次分割,生成不同类别的掩模。最后,将预测结果保存为.nii.gz文件,并根据预测结果生成CSV文件,记录每个病人的图像信息、掩模类别和路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

import pandas as pd
import time
import os
from collections import Counter
import numpy as np
import cv2
import SimpleITK
from tqdm import tqdm

def getFiles(path):
    Filelist = []
    for home, dirs, files in os.walk(path):
        for file in files:
            # 文件名列表,包含完整路径
            Filelist.append(os.path.join(home, file))
            #Filelist.append(file)
    return Filelist

root_path = '/home/tione/notebook/taop-2021/100003/'
#train_files = pd.read_csv('/home/tione/notebook/taop-2021/100003/test1_data_info.csv', usecols=['id_patient', 'id_series', 'id_area', 'mask_path', 'class(1:LBSA;2:EA;3:NA;4:CA)'])
train_files = pd.read_csv('/home/tione/notebook/taop-2021/100003/test2_data_info.csv')
#train_files = pd.read_csv('/home/tione/notebook/test3_data_info.csv')

from mmdet.apis import init_detector, inference_detector, show_result_pyplot, show_result_ins
import mmcv
import os
import numpy as np
import skimage.io
import cv2
from PIL import Image
import sys
from scipy import ndimage
import csv
import matplotlib.pyplot as plt 

config_file = '/home/tione/notebook/code/configs/solov2/solov2_r101_dcn_fpn_8gpu_3x.py'

# download the checkpoint from model zoo and put it in `checkpoints/`
checkpoint_file = '/home/tione/notebook/code/work_dirs/solov2_release_r101_dcn_fpn_8gpu_step1/epoch_25.pth'
# build the model from a config file and a checkpoint file
model = init_detector(config_file, checkpoint_file, device='cuda:0')

step2_1_config_file = '/home/tione/notebook/code/configs/solov2/solov2_r101_dcn_fpn_8gpu_3x1.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
step2_1_checkpoint_file = '/home/tione/notebook/code/work_dirs/solov2_release_r101_dcn_fpn_8gpu_step2_1/epoch_6.pth'
# build the model from a config file and a checkpoint file
step2_1_model = init_detector(step2_1_config_file, step2_1_checkpoint_file, device='cuda:0')

step2_2_config_file = '/home/tione/notebook/code/configs/solov2/solov2_r101_dcn_fpn_8gpu_3x2.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
step2_2_checkpoint_file = '/home/tione/notebook/code/work_dirs/solov2_release_r101_dcn_fpn_8gpu_step2_2/epoch_11.pth'
# build the model from a config file and a checkpoint file
step2_2_model = init_detector(step2_2_config_file, step2_2_checkpoint_file, device='cuda:0')

step2_3_config_file = '/home/tione/notebook/code/configs/solov2/solov2_r101_dcn_fpn_8gpu_3x3.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
step2_3_checkpoint_file = '/home/tione/notebook/code/work_dirs/solov2_release_r101_dcn_fpn_8gpu_step2_3/epoch_10.pth'
# build the model from a config file and a checkpoint file
step2_3_model = init_detector(step2_3_config_file, step2_3_checkpoint_file, device='cuda:0')

step2_4_config_file = '/home/tione/notebook/code/configs/solov2/solov2_r101_dcn_fpn_8gpu_3x4.py'
# download the checkpoint from model zoo and put it in `checkpoints/`
step2_4_checkpoint_file = '/home/tione/notebook/code/work_dirs/solov2_release_r101_dcn_fpn_8gpu_step2_4/epoch_10.pth'
# build the model from a config file and a checkpoint file
step2_4_model = init_detector(step2_4_config_file, step2_4_checkpoint_file, device='cuda:0')


c = Counter(train_files['id_patient'])
idx = 0

image_id = 1
segmentation_id = 1

csv_flag = False
#How many patient
#每个病人的t1,t2, flair 都是一样的,各20张。image总共就321x20=6420张,之后看要不要把一个病人的image合在一个大图中?
#mask可能有多个,所以mask导入可能会多些
for i in tqdm(c):
    idx_each_patient = idx
    
    #一个病人有几个mask
    nums_per_patient = int(c[i] / 3) 
    #Flair_path = '0001_Flair' CET1_path = '0001_CET1'  T2_path = '0001_T2'
    Flair_path = train_files.iloc[idx_each_patient]['id_series']
    Flair_path = Flair_path.split('_')[0] + '_' + Flair_path.split('_')[1].capitalize()
    #print(Flair_path.split('_')[0])
    CET1_path = train_files.iloc[idx_each_patient+nums_per_patient]['id_series']
    if CET1_path.split('_')[1] == 't1ce':
        CET1_path = CET1_path.split('_')[0] + '_CET1'

    T2_path = train_files.iloc[idx_each_patient+2*nums_per_patient]['id_series']
    T2_path = T2_path.split('_')[0] + '_' + T2_path.split('_')[1].upper()

    #获取dicom的路径
    dicoms_flair_path = root_path + Flair_path.split('_')[0] + '/' + Flair_path
    dicoms_cet1_path = root_path + Flair_path.split('_')[0] + '/' + CET1_path
    dicoms_t2_path = root_path + Flair_path.split('_')[0] + '/' + T2_path
    
    #taop-2021/100003/0001/0001_Flair taop-2021/100003/0001/0001_CET1 taop-2021/100003/0001/0001_T2
    #print(dicoms_flair_path, dicoms_cet1_path, dicoms_t2_path)
    
    #获取每个病人的flair下的20张dicom图像
    flair_dicoms = getFiles(dicoms_flair_path)
    
#     #创建mask 数组
#     pic_name = os.path.split(flair_dicoms[0])[1]
#     cet1_dicom = dicoms_cet1_path + '/' + pic_name
#     t2_dicom = dicoms_t2_path + '/' + pic_name

    flair_ds = SimpleITK.ReadImage(flair_dicoms[0])
    flair_ds = SimpleITK.GetArrayFromImage(flair_ds)

    h, w = flair_ds[0].shape

    mask_label0 = np.zeros((len(flair_dicoms), h, w))
    mask_label1 = np.zeros((len(flair_dicoms), h, w))
    mask_label2 = np.zeros((len(flair_dicoms), h, w))
    mask_label3 = np.zeros((len(flair_dicoms), h, w))
    
    mask_labelflag_0 = False
    mask_labelflag_1 = False
    mask_labelflag_2 = False
    mask_labelflag_3 = False

    for flair_dicom in flair_dicoms:
        #10.dcm
        pic_name = os.path.split(flair_dicom)[1]

        if pic_name == '0.dcm' or pic_name == '1.dcm':
            continue
        cet1_dicom = dicoms_cet1_path + '/' + pic_name
        t2_dicom = dicoms_t2_path + '/' + pic_name

        flair_ds = SimpleITK.ReadImage(flair_dicom)
        flair_ds = SimpleITK.GetArrayFromImage(flair_ds)
        
        cet1_ds = SimpleITK.ReadImage(cet1_dicom)
        cet1_ds = SimpleITK.GetArrayFromImage(cet1_ds)

        t2_ds = SimpleITK.ReadImage(t2_dicom)
        t2_ds = SimpleITK.GetArrayFromImage(t2_ds)

        flair_array = np.reshape(flair_ds, (flair_ds.shape[1], flair_ds.shape[2])) 
        cet1_array = np.reshape(cet1_ds, (cet1_ds.shape[1], cet1_ds.shape[2]))
        t2_array = np.reshape(t2_ds, (t2_ds.shape[1], t2_ds.shape[2]))

        flair_array = (flair_array - np.mean(flair_array)) / np.std(flair_array)
        cet1_array = (cet1_array - np.mean(cet1_array)) / np.std(cet1_array)
        t2_array = (t2_array - np.mean(t2_array)) / np.std(t2_array)
        
        flair_array = ((flair_array - flair_array.min())/(flair_array.max()-flair_array.min()))*255
        cet1_array = ((cet1_array - cet1_array.min())/(cet1_array.max()-cet1_array.min()))*255
        t2_array = ((t2_array - t2_array.min())/(t2_array.max()-t2_array.min()))*255
        
        flair_array = np.asarray(flair_array).astype(np.float32)
        cet1_array = np.asarray(cet1_array).astype(np.float32)
        t2_array = np.asarray(t2_array).astype(np.float32)
        stacked_img = np.stack((cet1_array, flair_array, t2_array), axis=-1)

#         stacked_img = np.stack((flair_array, cet1_array, t2_array), axis=-1)
#         stacked_img = np.asarray(stacked_img).astype(np.float32)
#         stacked_img = (stacked_img - stacked_img.min())/(stacked_img.max()-stacked_img.min())
#         stacked_img = stacked_img * 255

        # 把三个序列的图像转出三通道的一张图像
        image_path = '/home/tione/notebook/img-2021-test-step1/'

        if not os.path.exists(image_path):
            os.makedirs(image_path)
        image_name = pic_name.split('.')[0] + '.png'
        saved_imgpath = image_path + Flair_path.split('_')[0] + '_' + image_name
        cv2.imwrite(saved_imgpath, stacked_img)
#         stacked1_img = cv2.imread(saved_imgpath)

        result = inference_detector(model, stacked_img)
        
        if  result[0] != None:
            cur_result = result[0]
            seg_label = cur_result[0]
            seg_label = seg_label.cpu().numpy().astype(np.uint8)
            cate_label = cur_result[1]
            cate_label = cate_label.cpu().numpy()
            score = cur_result[2].cpu().numpy()
            
            score_thr = 0.3
            vis_inds = score > score_thr
            seg_label = seg_label[vis_inds]
            num_mask = seg_label.shape[0]
            cate_label = cate_label[vis_inds]
            cate_score = score[vis_inds]

            if num_mask == 0:
                continue

#             for j in range(num_mask):
#                 if cate_label[j] == 0:
#                     mask_label0[int(pic_name.split('.')[0]), :, :] = seg_label[j]
#                     mask_labelflag_0 = True
#                 elif cate_label[j] == 1:
#                     mask_label1[int(pic_name.split('.')[0]), :, :]= seg_label[j]
#                     mask_labelflag_1 = True
#                 elif cate_label[j] == 2:
#                     mask_label2[int(pic_name.split('.')[0]), :, :] = seg_label[j]
#                     mask_labelflag_2 = True
#                 elif cate_label[j] == 3:
#                     mask_label3[int(pic_name.split('.')[0]), :, :] = seg_label[j]
#                     mask_labelflag_3 = True
                 
            stacked_img[seg_label[0] == False] = 0#np.where(seg_label == True, stacked_img, 0)

            image_path = '/home/tione/notebook/img-2021-test-step2/'
            if not os.path.exists(image_path):
                os.makedirs(image_path)
            image_name = pic_name.split('.')[0] + '.png'
            cv2.imwrite(image_path + Flair_path.split('_')[0] + '_' + image_name, stacked_img)
            
            result_1 = inference_detector(step2_1_model, stacked_img)
            result_2 = inference_detector(step2_2_model, stacked_img)
            result_3 = inference_detector(step2_3_model, stacked_img)
            result_4 = inference_detector(step2_4_model, stacked_img)
            
            if  result_1[0] != None:
                cur_result = result_1[0]
                seg_label = cur_result[0]
                seg_label = seg_label.cpu().numpy().astype(np.uint8)
                cate_label = cur_result[1]
                cate_label = cate_label.cpu().numpy()
                score = cur_result[2].cpu().numpy()

                score_thr = 0.3
                vis_inds = score > score_thr
                seg_label = seg_label[vis_inds]
                num_mask = seg_label.shape[0]
                cate_label = cate_label[vis_inds]
                cate_score = score[vis_inds]

                if num_mask == 0:
                    continue
                mask_label0[int(pic_name.split('.')[0]), :, :] = seg_label
                mask_labelflag_0 = True
            if  result_2[0] != None:
                cur_result = result_2[0]
                seg_label = cur_result[0]
                seg_label = seg_label.cpu().numpy().astype(np.uint8)
                cate_label = cur_result[1]
                cate_label = cate_label.cpu().numpy()
                score = cur_result[2].cpu().numpy()

                score_thr = 0.3
                vis_inds = score > score_thr
                seg_label = seg_label[vis_inds]
                num_mask = seg_label.shape[0]
                cate_label = cate_label[vis_inds]
                cate_score = score[vis_inds]

                if num_mask == 0:
                    continue
                mask_label1[int(pic_name.split('.')[0]), :, :] = seg_label
                mask_labelflag_1 = True
            if  result_3[0] != None:
                cur_result = result_3[0]
                seg_label = cur_result[0]
                seg_label = seg_label.cpu().numpy().astype(np.uint8)
                cate_label = cur_result[1]
                cate_label = cate_label.cpu().numpy()
                score = cur_result[2].cpu().numpy()

                score_thr = 0.3
                vis_inds = score > score_thr
                seg_label = seg_label[vis_inds]
                num_mask = seg_label.shape[0]
                cate_label = cate_label[vis_inds]
                cate_score = score[vis_inds]

                if num_mask == 0:
                    continue
                mask_label2[int(pic_name.split('.')[0]), :, :] = seg_label
                mask_labelflag_2 = True
            if  result_4[0] != None:
                cur_result = result_4[0]
                seg_label = cur_result[0]
                seg_label = seg_label.cpu().numpy().astype(np.uint8)
                cate_label = cur_result[1]
                cate_label = cate_label.cpu().numpy()
                score = cur_result[2].cpu().numpy()

                score_thr = 0.3
                vis_inds = score > score_thr
                seg_label = seg_label[vis_inds]
                num_mask = seg_label.shape[0]
                cate_label = cate_label[vis_inds]
                cate_score = score[vis_inds]

                if num_mask == 0:
                    continue
                mask_label3[int(pic_name.split('.')[0]), :, :] = seg_label
                mask_labelflag_3 = True
    #            print(num_mask, saved_imgpath, seg_label.shape, cate_label, cate_score)
                #print(pic_name, num_mask, cate_label)
#                 for j in range(num_mask):
#                     if cate_label[j] == 0:
#                         mask_label0[int(pic_name.split('.')[0]), :, :] = seg_label[j]
#                         mask_labelflag_0 = True
#                     elif cate_label[j] == 1:
#                         mask_label1[int(pic_name.split('.')[0]), :, :]= seg_label[j]
#                         mask_labelflag_1 = True
#                     elif cate_label[j] == 2:
#                         mask_label2[int(pic_name.split('.')[0]), :, :] = seg_label[j]
#                         mask_labelflag_2 = True
#                     elif cate_label[j] == 3:
#                         mask_label3[int(pic_name.split('.')[0]), :, :] = seg_label[j]
#                         mask_labelflag_3 = True

    record_time = int(time.time())
    file_path = '/home/tione/notebook/03_predicts/' + Flair_path.split('_')[0] + '/mask/'
    if not os.path.exists(file_path):
        os.makedirs(file_path)
    nums_label = []    
    if mask_labelflag_0 == True:
        #mask_labelflag_0 = False
        out = SimpleITK.GetImageFromArray(mask_label0)
        SimpleITK.WriteImage(out, file_path + '1.nii.gz')
        nums_label.append(1)
        
    if mask_labelflag_1 == True:
        #mask_labelflag_1 = False
        out = SimpleITK.GetImageFromArray(mask_label1)
        SimpleITK.WriteImage(out, file_path + '2.nii.gz')
        nums_label.append(2)
        
    if mask_labelflag_2 == True:
        #mask_labelflag_2 = False
        out = SimpleITK.GetImageFromArray(mask_label2)
        SimpleITK.WriteImage(out, file_path + '3.nii.gz')
        nums_label.append(3)
        
    if mask_labelflag_3 == True:
        #mask_labelflag_3 = False
        out = SimpleITK.GetImageFromArray(mask_label3)
        SimpleITK.WriteImage(out, file_path + '4.nii.gz')
        nums_label.append(4)
    print('nums_label', len(nums_label), nums_label)    
    # 表头
    field_order = ['id_type', 'id_project', 'id_patient', 'id_exam', 'id_series', 'id_image', 'id_doctor', 'id_task', 'id_area', 'label_type', 'mask_path', 'class(1:LBSA;2:EA;3:NA;4:CA)']
    with open("03_predicts.csv", 'a+', encoding="utf-8", newline='') as csvfile:
        
        writer = csv.DictWriter(csvfile, field_order)

        if csv_flag == False:
            writer.writeheader()
            csv_flag = True
            
        id_type = train_files.iloc[idx_each_patient]['id_type']
        id_project = train_files.iloc[idx_each_patient]['id_project']
        id_patient = train_files.iloc[idx_each_patient]['id_patient']
        id_exam = train_files.iloc[idx_each_patient]['id_exam']
        #id_series = id_exam + '_'
        id_image = train_files.iloc[idx_each_patient]['id_image']
        id_doctor = train_files.iloc[idx_each_patient]['id_doctor']
        id_task = train_files.iloc[idx_each_patient]['id_task']
        label_type = train_files.iloc[idx_each_patient]['label_type']
        
#         mask_path = Flair_path.split('_')[0] + '/mask/'
#         mask_class = 
        if len(nums_label) == 0:
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_flair', id_image, id_doctor, id_task, 1, label_type, None, None])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t1ce', id_image, id_doctor, id_task, 1, label_type, None, None])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t2', id_image, id_doctor, id_task, 1, label_type, None, None])))
        elif len(nums_label) == 1:
            if mask_labelflag_0 == True:
                mask_path = Flair_path.split('_')[0] + '/mask/1.nii.gz'
                mask_class = 1
            elif mask_labelflag_1 == True:
                mask_path = Flair_path.split('_')[0] + '/mask/2.nii.gz'
                mask_class = 2
            elif mask_labelflag_2 == True:
                mask_path = Flair_path.split('_')[0] + '/mask/3.nii.gz'
                mask_class = 3
            elif mask_labelflag_3 == True:
                mask_path = Flair_path.split('_')[0] + '/mask/4.nii.gz'
                mask_class = 4
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_flair', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t1ce', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t2', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class]))) 
        elif len(nums_label) == 2:
            mask_class = nums_label[0]
            mask_path = Flair_path.split('_')[0] + '/mask/' + str(mask_class) + '.nii.gz'
            mask_class1 = nums_label[1]
            mask_path1 = Flair_path.split('_')[0] + '/mask/' + str(mask_class1) + '.nii.gz'
            
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_flair', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_flair', id_image, id_doctor, id_task, 2, label_type, mask_path1, mask_class1])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t1ce', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class]))) 
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t1ce', id_image, id_doctor, id_task, 2, label_type, mask_path1, mask_class1])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t2', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t2', id_image, id_doctor, id_task, 2, label_type, mask_path1, mask_class1])))             
        elif len(nums_label) == 3:
            mask_class = nums_label[0]
            mask_path = Flair_path.split('_')[0] + '/mask/' + str(mask_class) + '.nii.gz'
            mask_class1 = nums_label[1]
            mask_path1 = Flair_path.split('_')[0] + '/mask/' + str(mask_class1) + '.nii.gz'
            mask_class2 = nums_label[2]
            mask_path2 = Flair_path.split('_')[0] + '/mask/' + str(mask_class2) + '.nii.gz'  
            
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_flair', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_flair', id_image, id_doctor, id_task, 2, label_type, mask_path1, mask_class1])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_flair', id_image, id_doctor, id_task, 3, label_type, mask_path2, mask_class2])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t1ce', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class]))) 
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t1ce', id_image, id_doctor, id_task, 2, label_type, mask_path1, mask_class1])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t1ce', id_image, id_doctor, id_task, 3, label_type, mask_path2, mask_class2])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t2', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t2', id_image, id_doctor, id_task, 2, label_type, mask_path1, mask_class1])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t2', id_image, id_doctor, id_task, 3, label_type, mask_path2, mask_class2])))
            
        elif len(nums_label) == 4:
            mask_class = nums_label[0]
            mask_path = Flair_path.split('_')[0] + '/mask/' + str(mask_class) + '.nii.gz'
            mask_class1 = nums_label[1]
            mask_path1 = Flair_path.split('_')[0] + '/mask/' + str(mask_class1) + '.nii.gz'
            mask_class2 = nums_label[2]
            mask_path2 = Flair_path.split('_')[0] + '/mask/' + str(mask_class2) + '.nii.gz'  
            mask_class3 = nums_label[3]
            mask_path3 = Flair_path.split('_')[0] + '/mask/' + str(mask_class3) + '.nii.gz'  
            
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_flair', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_flair', id_image, id_doctor, id_task, 2, label_type, mask_path1, mask_class1])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_flair', id_image, id_doctor, id_task, 3, label_type, mask_path2, mask_class2])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_flair', id_image, id_doctor, id_task, 4, label_type, mask_path3, mask_class3])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t1ce', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class]))) 
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t1ce', id_image, id_doctor, id_task, 2, label_type, mask_path1, mask_class1])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t1ce', id_image, id_doctor, id_task, 3, label_type, mask_path2, mask_class2])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t1ce', id_image, id_doctor, id_task, 4, label_type, mask_path3, mask_class3])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t2', id_image, id_doctor, id_task, 1, label_type, mask_path, mask_class])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t2', id_image, id_doctor, id_task, 2, label_type, mask_path1, mask_class1])))
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t2', id_image, id_doctor, id_task, 3, label_type, mask_path2, mask_class2]))) 
            writer.writerow(dict(zip(field_order, [id_type, id_project, id_patient, id_exam, str(id_exam) + '_t2', id_image, id_doctor, id_task, 4, label_type, mask_path3, mask_class3])))  
            
        mask_labelflag_0 = False
        mask_labelflag_1 = False
        mask_labelflag_2 = False
        mask_labelflag_3 = False
    idx = idx + c[i]
                      
    
print('it is ok!')
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

骨子带刺

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值