个人记录:划分

原始数据展示

每五个大图移动一次所有的大图名称的小图片。

读取指定图片格式的图片名称,内置函数map执行,文件移动

图片01-17[:27]

图片17-70要改27为25

import os
import shutil
# source = 'dataset/sat_train/'
source_path ="/mnt/sdb1/fenghaixia/dsm/dataset/train/"
test_path ="./dataset/tmp/"

IMAGES_FORMAT = ['.tif']  # 图片格式
 

sat_names = [name for name in os.listdir(source_path) for item in IMAGES_FORMAT if
            os.path.splitext(name)[1] == item]


# mask_names = filter(lambda x: x.find('mask')!=-1, os.listdir(source_path))
sat_names_big = list(map(lambda x: x[:27], sat_names))
# sorted(sat_names,key=str.lower)
sat_names_big=list(set(sat_names_big))
sat_names_big.sort(key=lambda x: int(x[-2:]))
order=1
for f in sat_names_big:      
    if order%5==0:
        print(order)
        print(f)
        imagelist = list(filter(lambda x: x.find(f)!=-1, sat_names))
        for name in imagelist:   
            old_sat_path=source_path+name
            old_mask_path=source_path+name[:-8]+'_mask.png'
            new_sat_path=test_path+name
            new_mask_path=test_path+name[:-8]+'_mask.png'
            shutil.move(old_sat_path,new_sat_path)
            shutil.move(old_mask_path,new_mask_path)
    order+=1

print('finish')

这样跑的iou91

二、感觉不太合理

 选蓝色为测试,剩余为训练,代码如下


import os
import shutil
# source = 'dataset/sat_train/'
source_path ="/mnt/sdb1/fenghaixia/dsm2/dataset/train/"
test_path ="./dataset/tmp/"

IMAGES_FORMAT = ['.tif']  # 图片格式
 

sat_names = [name for name in os.listdir(source_path) for item in IMAGES_FORMAT if
            os.path.splitext(name)[1] == item]


# mask_names = filter(lambda x: x.find('mask')!=-1, os.listdir(source_path))
sat_names_big = list(map(lambda x: x[:27], sat_names))
# sorted(sat_names,key=str.lower)
sat_names_big=list(set(sat_names_big))
sat_names_big.sort(key=lambda x: int(x[-2:]))
order=1
sat_names_big_0=sat_names_big[0]
for f in sat_names_big:
    # print(f[-2:])
    # print(sat_names_big_0[-2:])
    if f[-2:]!=sat_names_big_0[-2:]:
        sat_names_big_0=f
        order+=1
    if order in [15,16,30,31,45,46,60,61]:
        print(order)
        print(f)
        imagelist = list(filter(lambda x: x.find(f)!=-1, sat_names))
        for name in imagelist:   
            old_sat_path=source_path+name
            old_mask_path=source_path+name[:-8]+'_mask.png'
            new_sat_path=test_path+name
            new_mask_path=test_path+name[:-8]+'_mask.png'
            shutil.move(old_sat_path,new_sat_path)
            shutil.move(old_mask_path,new_mask_path)
print('finish')




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值