将BPR数据集改成Bike-person reid命名规则

下面展示一些 内联代码片

// 处理跨镜头下的人骑车图片
import os
from shutil import copyfile
import random

download_path = '../veri'
save_path = download_path + '/pytorch_4_5test/'    # save position
if not os.path.isdir(save_path):
    os.mkdir(save_path)
query_path = download_path + '/cam_4_5'         # file position
query = save_path + 'query/'
gallery = save_path + 'gallery/'

if not os.path.isdir(query):
    os.mkdir(query)
if not os.path.isdir(gallery):
    os.mkdir(gallery)

i = 141                                          # modify id
for root, dirs, files in os.walk(query_path, topdown=True):
    k = 0
    random.shuffle(files)
    for name in files:
        k += 1
        tmp = []
        if not name[-3:] == 'jpg':
            continue
        ID = str(i).zfill(6)
        tmp.append(ID)
        file_name = name.split('_')
        cs = ''
        if file_name[0] == 'cam4':         # modify camera
            cs = 'c4s3'                    # camera and scene
        if file_name[0] == 'cam5':         # modify camera
            cs = 'c5s2'                    # camera and scene
        tmp.append(cs)
        number = random.randint(10000, 190000)
        number = str(number).zfill(4)
        tmp.append(number)
        frames = file_name[-1].split('.')[0]
        tmp.append(frames)
        string = '_'
        new_path = '_'.join(map(str, tmp))
        jpg = '.jpg'
        new_path = ''.join([new_path, jpg])
        oldir = os.path.join(root, name)
        oldir = oldir.split('\\')
        oldir = '/'.join(map(str, oldir))
        print(oldir)
        print(save_path)

        # train environment

        # newdir = save_path + new_path
        # copyfile(oldir, newdir)

        # test environment
        if k <= 10:
            newdir = query + new_path
            copyfile(oldir, newdir)
        else:
            newdir = gallery + new_path
            copyfile(oldir, newdir)

    i += 1




// 处理单镜头下的人骑车图片
import os
from shutil import copyfile
import random

download_path = '../veri'
save_path = download_path + '/Distractors_train/'    # save position
if not os.path.isdir(save_path):
    os.mkdir(save_path)
query_path = download_path + '/Distractors'         # file position


i = 2322                                          # modify id
for root, dirs, files in os.walk(query_path, topdown=True):
    k = 0
    random.shuffle(files)
    for name in files:
        k += 1
        tmp = []
        if not name[-3:] == 'jpg':
            continue
        ID = str(i).zfill(6)
        tmp.append(ID)
        file_name = name.split('_')
        cs = ''
        if file_name[0] == 'cam1':         # modify camera
            cs = 'c1s2'                    # camera and scene
        if file_name[0] == 'cam2':         # modify camera
            cs = 'c2s1'                    # camera and scene
        if file_name[0] == 'cam3':         # modify camera
            cs = 'c3s3'                    # camera and scene
        if file_name[0] == 'cam4':         # modify camera
            cs = 'c4s2'                    # camera and scene
        if file_name[0] == 'cam5':         # modify camera
            cs = 'c5s3'                    # camera and scene
        if file_name[0] == 'cam6':         # modify camera
            cs = 'c6s1'                    # camera and scene
        tmp.append(cs)
        number = random.randint(10000, 190000)
        number = str(number).zfill(4)
        tmp.append(number)
        frames = file_name[-1].split('.')[0]
        tmp.append(frames)
        string = '_'
        new_path = '_'.join(map(str, tmp))
        jpg = '.jpg'
        new_path = ''.join([new_path, jpg])
        oldir = os.path.join(root, name)
        oldir = oldir.split('\\')
        oldir = '/'.join(map(str, oldir))
        print(oldir)
        print(save_path)
        # print(root)
        # print(files)


        newdir = save_path + new_path
        copyfile(oldir, newdir)


    i += 1

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值