数据集提取标签(LEVIR_CD)

文件目录如下
在这里插入图片描述
若无数据集可以先去下载,下载链接http://chenhao.in/LEVIR/
下面把python代码复制运行即可,记得改路径!!!

import os
import glob

def create_image_list_txt(folder_path, output_file):
    # 使用glob模块获取文件夹中的所有图片文件
    image_files = glob.glob(os.path.join(folder_path, 'train_*.png'))  # .png可自行修改为其他格式
    image_files += glob.glob(os.path.join(folder_path, 'test_*.png'))
    image_files += glob.glob(os.path.join(folder_path, 'val_*.png'))

    # 对图片文件进行自定义排序,按照文件名中的数字部分进行排序
    image_files.sort(key=lambda x: int(os.path.splitext(os.path.basename(x))[0].split('_')[1]))

    # 打开文本文件以写入模式,使用utf-8编码
    with open(output_file, 'w', encoding='utf-8') as file:
        # 将图片文件名称写入文本文件
        for image_file in image_files:
            file.write(os.path.basename(image_file) + '\n')

    print(output_file)

# 假设我们正在处理一个包含中文路径的环境
train_folder_path = r'/home/aistudio/BIT_CD-master/LEVIR_CD/A/train'
train_output_file = r'/home/aistudio/BIT_CD-master/LEVIR_CD/list/train.txt'

test_folder_path = r'/home/aistudio/BIT_CD-master/LEVIR_CD/A/test'
test_output_file = r'/home/aistudio/BIT_CD-master/LEVIR_CD/list/test.txt'

val_folder_path = r'/home/aistudio/BIT_CD-master/LEVIR_CD/A/val'
val_output_file = r'/home/aistudio/BIT_CD-master/LEVIR_CD/list/val.txt'

# 执行代码
create_image_list_txt(train_folder_path, train_output_file)
create_image_list_txt(test_folder_path, test_output_file)
create_image_list_txt(val_folder_path, val_output_file)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值