Safemotion Lib
Loading...
Searching...
No Matches
reid_demo.py
Go to the documentation of this file.
1import sys
2
3sys_path = ['/workspace/sm_action', '/workspace', '/workspace/smreid']
4for path in sys_path:
5 if path not in sys.path:
6 sys.path.append(path)
7
8import os
9import cv2
10import numpy as np
11from tqdm import tqdm
12import time
13import torch
14
15from reid_api import *
16
17
18from fastreid.engine import DefaultPredictor
19from smutils.utils_os import search_file
20
21if __name__ == "__main__":
22
23 #모델 설정 값
24 device = 'cuda:1'
25 cfg_path = '/workspace/configs/reid/mgn/config.yaml'
26 checkpoint_path = '/workspace/checkpoints/reid/mgn/market_mgn_R50-ibn.pth'
27 crop_image_folder = '/workspace/a_track_result_crop' # 테스트할 crop 이미지들이 있는 폴더
28
29 #모델 빌드
30 model = build_reid_model(cfg_path, checkpoint_path, device)
31
32 #이미지 폴더에 있는 이미지 리스트
33 file_list, file_path = search_file(crop_image_folder, '.jpg')
34
35 #1000개 이하로 선택
36 file_path = file_path[0:min(len(file_path), 1000)]
37
38 feats = get_reid_feats(model, file_path) #특징 생성
39 distmat = get_reid_matrix(feats) #유사도 매트릭스 생성
40
41 #1번 인덱스의 특징과 비교했을때 유사도 0.9 이상인 특징 찾기
42 s_sim, keep_index = get_reid_image_index(distmat, select_id= 1, threshold=0.9)
43 sorted_keep_index = index_sort(keep_index, s_sim) #내림 차순 정렬
44
45 #출력
46 for idx, sim in sorted_keep_index:
47 print(f'{file_list[idx]}, {sim}')
48
get_reid_matrix(q_feats, g_feats=None)
Definition reid_api.py:94
get_reid_feats(model, crop_images)
Definition reid_api.py:62
build_reid_model(args)
Definition reid_api.py:30
get_reid_image_index(simmat, select_id=1, threshold=0.8)
Definition reid_api.py:121
index_sort(keep_index, s_sim)
Definition reid_api.py:143