针对仅有图片与标签的数据集进行划分

数据集格式

data

  --------images

  ---------masks

划分结果

data

           ---train

           ---trainmask

          ---val 

          ---valmask

完整的code如下 可以做相应的调整

import os

print('hello')

import glob
from random import shuffle
import shutil

all_images = glob.glob('F:/Datasets/cvccdb/data/images/*.tif')
print(len(all_images))

shuffle(all_images)

mask_dir = 'F:/Datasets/cvccdb/data/masks/'

x_train_dir = 'F:/Datasets/cvccdb/data/train/'
y_train_dir = 'F:/Datasets/cvccdb/data/trainann/'
x_valid_dir = 'F:/Datasets/cvccdb/data/val/'
y_valid_dir = 'F:/Datasets/cvccdb/data/valann/'

l = int(len(all_images) * 0.8)
for i in range(len(all_images)):
    src_img = all_images[i]

    name = src_img.split('/')[-1]
    name =  os.path.split(name

你可能感兴趣的:(数据划分,python,numpy)