回传数据解析,兼容v5和v10
This commit is contained in:
53
contrast/feat_infer.py
Normal file
53
contrast/feat_infer.py
Normal file
@ -0,0 +1,53 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
Created on Fri Feb 28 16:27:17 2025
|
||||
|
||||
@author: ym
|
||||
"""
|
||||
|
||||
import os
|
||||
import time
|
||||
import pickle
|
||||
import numpy as np
|
||||
from PIL import Image
|
||||
from scipy.spatial.distance import cdist
|
||||
from feat_extract.config import config as conf
|
||||
from feat_extract.inference import FeatsInterface #, inference_image
|
||||
|
||||
Encoder = FeatsInterface(conf)
|
||||
|
||||
def main():
|
||||
imgpaths = r"D:\全实时\202502\result\Yolos_Tracking\20250228-160049-188_6921168558018_6921168558018\a"
|
||||
featDict = {}
|
||||
imgs, imgfiles = [], []
|
||||
for filename in os.listdir(imgpaths):
|
||||
file, ext = os.path.splitext(filename)
|
||||
|
||||
imgpath = os.path.join(imgpaths, filename)
|
||||
img = Image.open(imgpath)
|
||||
|
||||
imgs.append(img)
|
||||
imgfiles.append(filename)
|
||||
|
||||
feature = Encoder.inference([img])
|
||||
feature /= np.linalg.norm(feature, axis=1)[:, None]
|
||||
feature_ft32 = feature.astype(np.float32)
|
||||
|
||||
|
||||
|
||||
featDict[file] = feature_ft32
|
||||
|
||||
feature = Encoder.inference(imgs)
|
||||
feature /= np.linalg.norm(feature, axis=1)[:, None]
|
||||
feature_ft32 = feature.astype(np.float32)
|
||||
|
||||
|
||||
matrix = 1 - cdist(feature, feature, 'cosine')
|
||||
|
||||
print("do")
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
Reference in New Issue
Block a user