Exemplo n.º 1
0
def main():
    parser = argparse.ArgumentParser()
    parser.add_argument('--out_path', type=str)
    parser = DataModule.add_data_model_specific_args(parser)
    args = parser.parse_args()

    train(args)
Exemplo n.º 2
0
def extract_match(
        data_match, j, register_out,
        id):  #,match_feature): #,average_match,count_match,register_out):
    tic = timeit.default_timer()
    print("output card:", id)
    #print("count----------", count)
    #CUDA_VISIBLE_DEVICES = id
    extractor = pfextractor('PED_EXT_001.pkl', id)
    toc = timeit.default_timer()
    print('all time: %.2f' % ((toc - tic) * 1000))
    print("process are ", j)
    match_feature = {}
    for i in range(0, len(data_match)):  #len(data_match)):
        fea = extractor.extract(data_match[i])
        one_feature = {}
        one_feature['camera_id'] = data_match[i]
        one_feature['time_stamp'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        one_feature['feature'] = [fea]
        match_feature[i] = one_feature
        del one_feature
    print("------------------", len(match_feature))

    dm = DataModule(cache_dir)
    mm = MatchingModule(MM_CONFIG, dm)
    tic = timeit.default_timer()
    matching_out = mm.match(match_feature, register=False, rank=5)
    toc = timeit.default_timer()
    print('match------- time: %.2f' % ((toc - tic) * 1000))
    print("per----------time:%.2f" % ((toc - tic) * 1000 / len(matching_out)))
    mm.free()
    del match_feature
    print('result is----------------', len(matching_out))
    #calculate precisoin
    candidate_path_ids = []
    for i in range(len(cam1_image_list)):  #len(cam1_image_list)):
        # print(i)
        id = cam1_image_list[i].split('/')[-2]
        candidate_path_id = candidate_path + id
        #print("mkdir is ",candidate_path_id)
        if not os.path.exists(str(candidate_path_id)):
            os.system('mkdir ' + candidate_path_id)
        candidate_path_ids.append(candidate_path_id)
    for mkey in matching_out:
        mobject_id = matching_out[mkey]['object_id'][0]
        mcamera_id = matching_out[mkey]['camera_id']
        file_name = mcamera_id.split('/')[2]
        allName = candidate_path + str(file_name) + "/"
        #print('file location is:',allName)
        for rkey in register_out.keys():
            robject_id = register_out[rkey]['object_id'][0]
            rcamera_id = register_out[rkey]['camera_id']
            if robject_id == mobject_id:
                print("----------------find--------------")
                os.system('cp ' + rcamera_id + ' ' + allName)
Exemplo n.º 3
0
def train(args):
    model = RNN()
    data_module = DataModule(args)

    callbacks_list = None
    if args.val_path:
        callbacks_list = []
        callbacks_list.append(callbacks.EarlyStopping(monitor='val_acc', patience=PATIENCE))
        callbacks_list.append(callbacks.ModelCheckpoint(filepath=args.out_path, monitor='val_acc', prefix='rnn'))

    gpus = N_GPU if torch.cuda.is_available() else None
    trainer = pl.Trainer(gpus=gpus, max_epochs=MAX_EPOCHS, callbacks=callbacks_list)

    trainer.fit(model, datamodule=data_module)
Exemplo n.º 4
0
def main():
    num = 0
    for dirpath, dirnames, filenames in os.walk(cam2_path):
        for f in filenames:
            if num == 100:
                break
            print(f)
            if '.jpg' in f:
                cam2_image_list.append(join(dirpath, f))
                num += 1
    print("cam2 images num:")
    print(len(cam2_image_list))
    average_register = len(cam2_image_list) // 4

    # calculate precisoin
    for i in range(4):
        if i == 3:
            multiprocessing_register.append(cam2_image_list[i *
                                                            average_register:])
        else:
            multiprocessing_register.append(
                cam2_image_list[i * average_register:(i + 1) *
                                average_register])

    num = 0
    for dirpath, dirnames, filenames in os.walk(cam1_path):
        for f in filenames:
            if num == 50:
                break
            print(f)
            if '.jpg' in f:
                cam1_image_list.append(join(dirpath, f))
                num += 1
    print("cam1 images num:")
    print(len(cam1_image_list))
    #num_match=len(cam1_image_list)//4
    num_match = len(cam1_image_list) // 4
    print(num_match)
    for i in range(num_match):
        if i == 3:
            multiprocessing_match.append(cam1_image_list[i * num_match:])
        else:
            multiprocessing_match.append(
                cam1_image_list[i * num_match:(i + 1) * num_match])
    register_feature = multiprocessing.Manager().dict()
    tic = timeit.default_timer()
    plist_register = []
    for count in range(4):
        length = count * average_register
        p = multiprocessing.Process(
            target=extract_register,
            args=(multiprocessing_register[count], count, length,
                  register_feature,
                  count))  #,average_register,register_feature,count_register))
        p.start()
        plist_register.append(p)

    for p_register in plist_register:
        p_register.join()
    print("--------------------", len(register_feature))

    dm = DataModule(cache_dir)
    mm = MatchingModule(MM_CONFIG, dm)
    register_out = mm.register(register_feature)
    print(len(register_out))
    #save_obj(register_out,"register_out1")
    mm.free()
    toc = timeit.default_timer()
    print('register time: %.2f' % ((toc - tic) * 1000))

    #register_out=load_obj("register_out2")
    print("1111111111111111111111")
    tic = timeit.default_timer()

    print(num_match)
    # for j in range(0,num_match,4):
    # 	plist_match = []
    # 	process=num_match-j if (j+3)>num_match else 4
    # 	for count in range(process):
    # 		print(j+count)
    # 		p = multiprocessing.Process(target=extract_match,args=(multiprocessing_match[j+count],lock,count,register_out,count%3+1)) #,match_feature)) #,average_match,count_match,register_out))
    # 		p.start()
    # 		plist_match.append(p)
    #
    # 	for p_match in plist_match:
    # 		p_match.join()
    # 	del plist_match
    plist_match = []
    for j in range(4):
        p = multiprocessing.Process(
            target=extract_match,
            args=(multiprocessing_match[j], j, register_out, j)
        )  #,match_feature)) #,average_match,count_match,register_out))
        p.start()
        plist_match.append(p)
    for p_match in plist_match:
        p_match.join()
    del plist_match
    toc = timeit.default_timer()
    print('match time: %.2f' % ((toc - tic) * 1000))
Exemplo n.º 5
0
def extract_match(
        data_match, lock, j, length, register_out,
        id):  #,match_feature): #,average_match,count_match,register_out):
    #lock.acquire()
    #global count_match
    #lock.acquire()
    tic = timeit.default_timer()
    print("output card:", id)
    #print(torch.cuda.current_device())
    CUDA_VISIBLE_DEVICES = id
    #torch.cuda.set_device(id)
    extractor = pfextractor('PED_EXT_001.pkl', id)
    toc = timeit.default_timer()
    print('all time: %.2f' % ((toc - tic) * 1000))
    print("process are ", j)
    #lock.release()
    match_feature = {}
    for i in range(0, len(data_match)):  #len(data_match)):
        # s = getsize(data_match[i])
        #try:
        fea = extractor.extract(data_match[i])
        one_feature = {}
        one_feature['camera_id'] = data_match[i]
        one_feature['time_stamp'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        one_feature['feature'] = [fea]
        #match_feature[i+count_match.value] = one_feature
        match_feature[i] = one_feature
        del one_feature
    #print("process is ",j)
    # print("finished ext cam1 images features")
    # print("finished ext cam1 images features")
    # for ii in range(len(match_feature)):
    # 	print(j,len(match_feature), match_feature[ii])

    # matching
    print("------------------", len(match_feature))

    dm = DataModule(cache_dir)
    mm = MatchingModule(MM_CONFIG, dm)
    matching_out = mm.match(match_feature, register=False, rank=5)
    mm.free()
    del match_feature
    print('result is----------------', len(matching_out))
    #calculate precisoin
    candidate_path_ids = []
    for i in range(len(cam1_image_list)):  #len(cam1_image_list)):
        # print(i)
        id = cam1_image_list[i].split('/')[-2]
        candidate_path_id = candidate_path + id
        print("mkdir is ", candidate_path_id)
        if not os.path.exists(str(candidate_path_id)):
            os.system('mkdir ' + candidate_path_id)
        candidate_path_ids.append(candidate_path_id)
    # print candidate_path_ids
    # print("wenjian list is",len(candidate_path_ids))
    # print( "------------------------------------------")
    for mkey in matching_out:
        # try:
        mobject_id = matching_out[mkey]['object_id'][0]
        mcamera_id = matching_out[mkey]['camera_id']
        file_name = mcamera_id.split('/')[2]
        allName = ''
        allName = candidate_path + str(file_name) + "/"
        print('file location is:', allName)
        # print(len(register_out))
        for rkey in register_out.keys():
            robject_id = register_out[rkey]['object_id'][0]
            rcamera_id = register_out[rkey]['camera_id']

            print(robject_id)
            print(rcamera_id)
            if robject_id == mobject_id:
                print("find-------------")
                print mobject_id
                print
                #print('cp ' + rcamera_id + ' ' + allName)
                os.system('cp ' + rcamera_id + ' ' + allName)
Exemplo n.º 6
0
def main():
    num = 0
    for dirpath, dirnames, filenames in os.walk(cam2_path):
        for f in filenames:
            if num == 100:
                break
            print(f)
            if '.jpg' in f:
                cam2_image_list.append(join(dirpath, f))
                num += 1
    print("cam2 images num:")
    print(len(cam2_image_list))
    average_register = len(cam2_image_list) // 4

    # calculate precisoin
    for i in range(4):
        if i == 3:
            multiprocessing_register.append(cam2_image_list[i *
                                                            average_register:])
        else:
            multiprocessing_register.append(
                cam2_image_list[i * average_register:(i + 1) *
                                average_register])

    num = 0
    for dirpath, dirnames, filenames in os.walk(cam1_path):
        for f in filenames:
            if num == 50:
                break
            print(f)
            if '.jpg' in f:
                cam1_image_list.append(join(dirpath, f))
                num += 1
    print("cam1 images num:")
    print(len(cam1_image_list))
    average_match = len(cam1_image_list) // 4

    for i in range(4):
        if i == 3:
            multiprocessing_match.append(cam1_image_list[i * average_match:])
        else:
            multiprocessing_match.append(
                cam1_image_list[i * average_match:(i + 1) * average_match])

    plist_register = []
    tic = timeit.default_timer()

    register_feature = multiprocessing.Manager().dict()
    # average_register = multiprocessing.Value("d", average_register)
    # count_register=multiprocessing.Value("d", 0)

    for count in range(4):
        length = count * average_register

        p = multiprocessing.Process(
            target=extract_register,
            args=(multiprocessing_register[count], lock, count, length,
                  register_feature,
                  count))  #,average_register,register_feature,count_register))
        p.start()
        plist_register.append(p)

    for p_register in plist_register:
        p_register.join()

    print("--------------------", len(register_feature))

    dm = DataModule(cache_dir)
    mm = MatchingModule(MM_CONFIG, dm)
    register_out = mm.register(register_feature)
    mm.free()
    toc = timeit.default_timer()
    print('register time: %.2f' % ((toc - tic) * 1000))

    tic = timeit.default_timer()
    plist_match = []

    for j in range(4):
        length = j * average_match
        p = multiprocessing.Process(
            target=extract_match,
            args=(multiprocessing_match[j], lock, j, length, register_out, j)
        )  #,match_feature)) #,average_match,count_match,register_out))
        p.start()
        plist_match.append(p)

    for p_match in plist_match:
        p_match.join()

    toc = timeit.default_timer()
    print('match time: %.2f' % ((toc - tic) * 1000))
Exemplo n.º 7
0
def extract_match():
    for i in range(0, len(cam1_image_list)):
        s = getsize(cam1_image_list[i])
        #try:
        fea = extractor.extract(cam1_image_list[i])
        one_feature = {}
        one_feature['camera_id'] = cam1_image_list[i]
        one_feature['time_stamp'] = datetime.datetime.now().strftime(
            '%Y-%m-%d %H:%M:%S')
        one_feature['feature'] = [fea]
        match_feature[i] = one_feature
        print i
        #except:
        #continue
    print "finished ext cam1 images features"
    # parse matching feature

    # register
    dm = DataModule(cache_dir)
    mm = MatchingModule(MM_CONFIG, dm)
    register_out = mm.register(register_feature)
    mm.free()
    # matching
    dm = DataModule(cache_dir)
    mm = MatchingModule(MM_CONFIG, dm)
    tic = timeit.default_timer()
    matching_out = mm.match(match_feature, register=False, rank=5)
    toc = timeit.default_timer()
    print('match time: %.2f' % ((toc - tic) * 1000))
    print('match time: %.2f' % ((toc - tic) * 1000 / len(matching_out)))
    # with open('register_out.json', 'w') as file:
    #     json.dump(register_out, file, indent=4)
    # json.encoder.FLOAT_REPR = lambda x: format(x, '.2f')
    # with open('matching_out.json', 'w') as file:
    #     json.dump(matching_out, file, indent=4)

    # calculate precisoin
    candidate_path_ids = []
    for i in range(0, len(cam1_image_list)):
        print i
        id = cam1_image_list[i].split('/')[-2]
        candidate_path_id = candidate_path + id
        if not os.path.exists(str(candidate_path_id)):
            os.system('mkdir ' + candidate_path_id)
        candidate_path_ids.append(candidate_path_id)
    # precision = 0
    # feature_num = 0
    print "------------------------------------------"
    print candidate_path_ids
    for mkey in matching_out.keys():
        try:
            mobject_id = matching_out[mkey]['object_id'][0]
            mcamera_id = matching_out[mkey]['camera_id']
            file_name = mcamera_id.split('/')[2]
            allName = ''
            allName = candidate_path + str(file_name) + "/"
            print('file location is:', allName)
            print mobject_id
            print mcamera_id
            for rkey in register_out.keys():
                robject_id = register_out[rkey]['object_id'][0]
                rcamera_id = register_out[rkey]['camera_id']
                print robject_id
                print rcamera_id
                if robject_id == mobject_id:
                    print "find-------------"
                    os.system('cp ' + rcamera_id + ' ' + allName)
                    break
        except:
            continue
# print 'rank=', len(matching_out[mkey]['object_id']), len(matching_out[mkey]['score'])

#print 'matched_id=', mobject_id, ', register_id=', robject_id, ',score=', matching_out[mkey]['score'][0]
# precision += 1 if mobject_id == robject_id else 0
# feature_num += 1

#print 'precision =', precision * 100.0 / feature_num, '%'
    mm.free()