ch4.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:diagnose-heart 作者: woshialex 项目源码 文件源码
def process_data():
    all_data = []
    img_size = 256
    contour_path= os.path.join(c.data_manual, 'manual_contours_ch4', 'contours')
    image_path = os.path.join(c.data_manual, 'manual_contours_ch4', 'images')
    for fn in [f for f in os.listdir(contour_path) if 'jpg' in f]:
        if not os.path.exists(os.path.join(image_path, fn)):
            continue
        img = cv2.imread(os.path.join(image_path, fn), 0)
        img = cv2.resize(img, (img_size,img_size)).reshape(1,1,img_size,img_size)
        label = cv2.imread(os.path.join(contour_path, fn), 0)
        label = cv2.resize(label, (img_size,img_size))
        _,label = cv2.threshold(label, 127,255,cv2.THRESH_BINARY_INV)
        label = label.reshape(1,1,img_size,img_size)/255
        all_data.append([img,label])
    np.random.shuffle(all_data)
    all_imgs = np.concatenate([a[0] for a in all_data], axis=0)
    all_labels = np.concatenate([a[1] for a in all_data], axis=0)
    n = all_imgs.shape[0]
    destpath = os.path.join(c.data_intermediate, 'ch4_{}.hdf5'.format(img_size))
    if os.path.exists(destpath):
        os.remove(destpath)
    u.save_hd5py({'images': all_imgs, 'labels': all_labels}, destpath, 5)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号