原始数据展示
每五个大图移动一次所有的大图名称的小图片。
读取指定图片格式的图片名称,内置函数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')