深度学数据预处理的一些脚本

# 生成训练数据的路径文本
# 注意:1.生成训练还是测试数据的路径; 2.txt往后追加路径; 3.共4个形状,需要改动shape1,2,3,4
def generate_path():
    data_path = '.\\Dataset\shape4\\train_data\\Output_rgb'
    txt_path = '.\\Dataset\\train_path.txt'
    file = open(txt_path, mode='a') # 向txt文件中追加

    for (path, dirnames, filenames) in os.walk(data_path):
        for filename in filenames:
            if filename.endswith('png'):
                rgb_path = path + '\\' + filename
                # print('当前路径 %s' % rgb_path)
                example = int(rgb_path.split('\\')[5][3:]) #当前example
                if  example <= 49:
                    print(example)
                    #print(rgb_path)
                    depth_path = rgb_path.replace('rgb', 'depth')
                    #print(depth_path)
                    line = rgb_path + ' ' + depth_path + '\n'
                    file.write(line)
    #file.write('test\n')
    file.close()

生成的文本格式 

def copy_img():
    input_dir = 'E:\\m_DORN\DataSet\\shape1\\test_data\\Output_rgb'
    output_dir = 'E:\\m_DORN\\DataSet\\test_data\\rgb'
    # 新建输出文件夹
    if not os.path.exists(output_dir):
        os.mkdir(output_dir)
    for (path, dirnames, filenames) in os.walk(input_dir):
        for filename in filenames:
            if filename.endswith('png'):
                img_path = path + '/' + filename
                print('Being process img %s' % filename)
                shutil.copy(img_path, output_dir)

猜你喜欢

转载自blog.csdn.net/Gentlemanman/article/details/86316079