def extract_register(data_register, lock, average_register, register_feature, count_register): lock.acquire() #global extractor # global register_feature extractor = pfextractor('PED_EXT_001.pkl') for i in range(0, len(data_register)): s = getsize(data_register[i]) # try: fea = extractor.extract(data_register[i]) one_feature = {} one_feature['camera_id'] = data_register[i] one_feature['time_stamp'] = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') one_feature['feature'] = [fea] register_feature[i + count_register.value] = one_feature # register_feature[i] = one_feature # print(i) # print i+count_register print len(register_feature) count_register.value += average_register.value print count_register # except: # continue print("finished ext cam2 images features") # register lock.release()
def extract_register(data_register, lock, count, length, register_feature, id): #,average_register,register_feature,count_register): # lock.acquire() #global register_feature #register_feature = {} print("output card:", id) # id="cuda:"+str(id) # print("output card:", id) CUDA_VISIBLE_DEVICES = id extractor = pfextractor('PED_EXT_001.pkl', id) for i in range(0, len(data_register)): #len(data_register)): # s = getsize(data_register[i]) #try: fea = extractor.extract(data_register[i]) one_feature = {} one_feature['camera_id'] = data_register[i] one_feature['time_stamp'] = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') one_feature['feature'] = [fea] #lock.acquire() register_feature[i + length] = one_feature del one_feature print("count", count) #lock.release() # count_register.value+=average_register.value #print('-----------count',count, len(register_feature), register_feature[0], register_feature[1]) print("finished ext cam2 images features")
def extract_query(data_match, count, match_feature, id): print("output card:", id) #CUDA_VISIBLE_DEVICES = id extractor = pfextractor('PED_EXT_001.pkl', id) for i in range(0, len(data_match)): fea = extractor.extract(data_match[i]) match_feature[data_match[i]] = fea del fea print("count", count) print "finished ext cam1 images features"
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)
def extract_register(data_register, count, register_feature, id): #,average_register,register_feature,count_register): print("output card:", id) #CUDA_VISIBLE_DEVICES = id extractor = pfextractor('PED_EXT_001.pkl', id) for i in range(0, len(data_register)): #len(data_register)): fea = extractor.extract(data_register[i]) register_feature[data_register[i]] = fea del fea print("count", count) del extractor print "finished ext cam2 images features"
def extract_register(data_register,count,register_feature,id): #,average_register,register_feature,count_register): print("output card:",id) #CUDA_VISIBLE_DEVICES = id tic = timeit.default_timer() extractor = pfextractor('PED_EXT_001.pkl',id) toc = timeit.default_timer() print('read weight time: %.2f' % ((toc - tic) * 1000)) for i in range(0,len(data_register)): #len(data_register)): fea = extractor.extract(data_register[i]) register_feature[data_register[i]] = fea del fea print("count",count) del extractor gc.collect() print "finished ext cam2 images features"
def extract_register(data_register, count, length, register_feature, id): #,average_register,register_feature,count_register): print("output card:", id) #CUDA_VISIBLE_DEVICES = id extractor = pfextractor('PED_EXT_001.pkl', id) for i in range(0, len(data_register)): #len(data_register)): fea = extractor.extract(data_register[i]) one_feature = {} one_feature['camera_id'] = data_register[i] one_feature['time_stamp'] = datetime.datetime.now().strftime( '%Y-%m-%d %H:%M:%S') one_feature['feature'] = [fea] register_feature[i + length] = one_feature del one_feature print("count", count) print("finished ext cam2 images features")
import pickle def load_obj(name): with open('obj/' + name + '.pkl', 'rb') as f: return pickle.load(f) def save_obj(obj, name): with open('../candidate_2018_09_14_1/' + name + '.pkl', 'wb') as f: pickle.dump(obj, f, pickle.HIGHEST_PROTOCOL) if __name__ == '__main__': tic = timeit.default_timer() extractor = pfextractor('PED_EXT_001.pkl', 0) cam1_path = '../1_2018-09-15_test/' cam2_path = '../2_2018-09-15_test/' #candidate_path = '../candidate_2018-09-14/' candidate_path = '../candidate_2018_09_15_5/' cam2_dict = {} #num=0 cam1_image_list = [] cam2_image_list = [] num = 0 for dirpath, dirnames, filenames in os.walk(cam2_path): for f in filenames: # if num==1000: # break print f
def extract_match(data_match, lock, average_match, match_feature, count_match, register_out): # lock.acquire() # global count_match #global extractor extractor = pfextractor('PED_EXT_001.pkl') for i in range(0, 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 print(i) # print(average_match.value) # print i+count_match.value # count_match.value +=average_match.value print("2222222222222222222222222222222222222222222", len(match_feature)) # print count_match.value # except: # continue print("finished ext cam1 images features") # parse matching feature # matching mm = MatchingModule(MM_CONFIG) matching_out = mm.match(match_feature, register=False, rank=5) # 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: try: mobject_id = matching_out[mkey]['object_id'][0] mcamera_id = matching_out[mkey]['camera_id'] print(mobject_id) print(mcamera_id) 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("111111111111111111111111111111111") print(robject_id) print(rcamera_id) if robject_id == mobject_id: print("find-------------") os.system('cp ' + rcamera_id + ' ' + candidate_path_ids[mobject_id - 1] + '/') 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()
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)