def get_number(str):
#str格式:../Market/pytorch/gallery/0554/0554_L2_2_Unripe_721_3725frame.jpg
#0554即ID,3725为帧号
num1 = int(str.split('/')[4])
num2 = str.split('/')[5]
num2 = num2.split('_')[5]
num2 = int(num2[0:4])
return num1, num2
store_path = []
image_datasets = {x: datasets.ImageFolder(os.path.join('../Market/pytorch', x)) for x in ['gallery']}
#print(len(image_datasets['gallery'].imgs))
for n in range(0, 6918):
path, _ = image_datasets['gallery'].imgs[n]
store_path.append(path)
sorted_path = sorted(store_path, key=get_number) # 先按照ID排序,ID相同再按照frame排序
在python中对列表自定义排序
最新推荐文章于 2024-08-26 18:56:03 发布