码迷,mamicode.com
首页 > 其他好文 > 详细

分割数据预处理

时间:2021-06-13 10:35:43      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:close   观察   大于   ima   resize   npm   技术   print   情况   

日常报错(累~):

  小编最近用yolact对BraTS数据集做预测,验证结果如下:

技术图片

   发现ET对于Dice和PPV太小了,根据公式,我一开始以为是模型预测的区域过多导致的。

后面生成图片观察:

技术图片

   忽然之间,意识到,是自己的target生成错了。笔者对这个三个区域,首先是采用边缘提取,获取边缘的坐标,之后进行一次判断,只保留点数大于20的区域,所以就可能出现上述图片的情况。我们真是target是由ET区域(黄色区域),但我最后生成的target是没有ET区域的。

  所以再模型预测的阶段,也不会预测出ET,造成的PPV值偏小,进而Dice偏小。

如下是我生成边缘坐标(改进后,每个if价格else:continue)的部分代码:

f=open(F:/DATA/train_mask4.txt,w)

for r in tqdm(range(len(image_traintest_paths))):
# for r in tqdm(range(4)):
    # 获取路径
    a=0
    b=0
    c=0
#     fold_path=mask_train_paths[r]
    fold_path=mask_traintest_paths[r]
    npmask=np.load(fold_path)
    #print(npmask.shape)
    txt_line = ‘‘
    vertices_list_WT=[]
    vertices_list_ET=[]
    vertices_list_TC=[]
    # 获取边缘
    WT_Label = npmask.copy()
    WT_Label[npmask == 1] = 1.
    WT_Label[npmask == 2] = 1.
    WT_Label[npmask == 4] = 1.
    WT_Label=WT_Label.astype(np.uint8)
    WT_Label=WT_Label*255
    TC_Label = npmask.copy()
    TC_Label[npmask == 1] = 1.
    TC_Label[npmask == 2] = 0.
    TC_Label[npmask == 4] = 1.
    TC_Label=TC_Label.astype(np.uint8)
    TC_Label=TC_Label*255
    ET_Label = npmask.copy()
    ET_Label[npmask == 1] = 0.
    ET_Label[npmask == 2] = 0.
    ET_Label[npmask == 4] = 1
    ET_Label=ET_Label.astype(np.uint8)
    ET_Label=ET_Label*255
    # 写入到text line
    path_forward=fold_path.split(\\)[-1]
    txt_line=txt_line+path_forward+" "
    # 获取WT边缘坐标
    detected_edges = cv2.Canny(WT_Label, lowThreshold, lowThreshold+10 * ratio, apertureSize=kernel_size)
#     print(detected_edges.shape)
    if SumNum(detected_edges)>20:
        a=1
        for i in range(detected_edges.shape[0]):
            for j in range(detected_edges.shape[1]):
                if detected_edges[i,j] !=0:
                    vertices_list_WT.append([j,i])
        vertices_list_WT=np.array(vertices_list_WT)
        # 获取WTbounding box
        max_x_WT=np.max(vertices_list_WT[:,0])
        max_y_WT=np.max(vertices_list_WT[:,1])
        min_x_WT=np.min(vertices_list_WT[:,0])
        min_y_WT=np.min(vertices_list_WT[:,1])
        # 添加WT bounding box , vertices
        txt_line=txt_line+ str(min_x_WT)+,+str(min_y_WT)+,+str(max_x_WT)+,+str(max_y_WT)+,+1+,
        for i in range(len(vertices_list_WT)):
            txt_line=txt_line+str(vertices_list_WT[i][0])+,
            txt_line=txt_line+str(vertices_list_WT[i][1])+,
        txt_line=txt_line[:-1]+" "
    else:continue
    # 获取TC边缘坐标
    detected_edges = cv2.Canny(TC_Label, lowThreshold, lowThreshold+10 * ratio, apertureSize=kernel_size)
    if SumNum(detected_edges)>20:
        b=1
        for i in range(detected_edges.shape[0]):
            for j in range(detected_edges.shape[1]):
                if detected_edges[i,j] !=0:
                    vertices_list_TC.append([j,i])
        vertices_list_TC=np.array(vertices_list_TC)
        max_x_TC=np.max(vertices_list_TC[:,0])
        max_y_TC=np.max(vertices_list_TC[:,1])
        min_x_TC=np.min(vertices_list_TC[:,0])
        min_y_TC=np.min(vertices_list_TC[:,1])
        # 添加TC bounding box, vertices
        txt_line=txt_line+ str(min_x_TC)+,+str(min_y_TC)+,+str(max_x_TC)+,+str(max_y_TC)+,+2+,
        for i in range(len(vertices_list_TC)):
            txt_line=txt_line+str(vertices_list_TC[i][0])+,
            txt_line=txt_line+str(vertices_list_TC[i][1])+,
        txt_line=txt_line[:-1]+" "
    else:continue
    # 获取ET边缘坐标
    detected_edges = cv2.Canny(ET_Label, lowThreshold, lowThreshold+10 * ratio, apertureSize=kernel_size)
    if SumNum(detected_edges)>20:
        c=1
        for i in range(detected_edges.shape[0]):
            for j in range(detected_edges.shape[1]):
                if detected_edges[i,j] !=0:
                    vertices_list_ET.append([j,i])
        vertices_list_ET=np.array(vertices_list_ET)
        max_x_ET=np.max(vertices_list_ET[:,0])
        max_y_ET=np.max(vertices_list_ET[:,1])
        min_x_ET=np.min(vertices_list_ET[:,0])
        min_y_ET=np.min(vertices_list_ET[:,1])
        # 添加ET bounding box, vertices
        txt_line=txt_line+ str(min_x_ET)+,+str(min_y_ET)+,+str(max_x_ET)+,+str(max_y_ET)+,+3+,
        for i in range(len(vertices_list_ET)):
            txt_line=txt_line+str(vertices_list_ET[i][0])+,
            txt_line=txt_line+str(vertices_list_ET[i][1])+,
    else:continue
    
    txt_line=txt_line[:-1]+\n
    if (a==b==c==0):
        continue

    f.write(txt_line)

f.close()

  不知再次训练结果会怎样。。。

分割数据预处理

标签:close   观察   大于   ima   resize   npm   技术   print   情况   

原文地址:https://www.cnblogs.com/a-runner/p/14878741.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!