modified for site test

This commit is contained in:
王庆刚
2024-07-18 17:52:12 +08:00
parent f90ef72cbf
commit e986ec060b
39 changed files with 2279 additions and 375 deletions

View File

@ -104,25 +104,76 @@ def inference_image(image, detections):
return imgs, features
def test_dog():
def readimg():
imgpath = r"D:\datasets\ym\Img_ResnetData\result\0.png"
image = cv2.imread(imgpath)
img = cv2.resize(image, (224, 224))
cv2.imwrite('0_224x224.jpg', img)
def readdata(datapath):
datapath = r"D:\datasets\ym\Img_ResnetData\dog_224x224\dog_224x224.txt"
with open(datapath, 'r') as file:
lines = file.readlines()
dlist = lines[0].split(',')
dfloat = [float(d) for d in dlist]
afeat = np.array(dfloat).reshape(1, -1)
return afeat
def readrawimg(datapath):
with open(datapath, 'r') as file:
llines = file.readlines()
imgs = []
row = 224
for i in range(8):
lines = llines[i*224 : (i+1)*224]
imgpath = r"D:\datasets\ym\Img_ResnetData\dog_224x224\dog_224x224.jpg"
image = cv2.imread(imgpath)
img = np.empty((224, 224, 0), dtype=np.float32)
imgr = np.empty((0, 224), dtype=np.float32)
imgg = np.empty((0, 224), dtype=np.float32)
imgb = np.empty((0, 224), dtype=np.float32)
for line in lines:
dlist = line.split(' ')[0:224]
img_r = np.array([float(s.split(',')[0]) for s in dlist], dtype=np.float32).reshape(1, -1)
img_g = np.array([float(s.split(',')[1]) for s in dlist], dtype=np.float32).reshape(1, -1)
img_b = np.array([float(s.split(',')[2]) for s in dlist], dtype=np.float32).reshape(1, -1)
# img_r = [float(s.split(',')[0]) for s in dlist if len(s.split(',')[0].encode('utf-8')) == 4]
# img_g = [float(s.split(',')[1]) for s in dlist if len(s.split(',')[1].encode('utf-8')) == 4]
# img_b = [float(s.split(',')[2]) for s in dlist if len(s.split(',')[2].encode('utf-8')) == 4]
imgr = np.concatenate((imgr, img_r), axis=0)
imgg = np.concatenate((imgg, img_g), axis=0)
imgb = np.concatenate((imgb, img_b), axis=0)
imgr = imgr[:, :, None]
imgg = imgg[:, :, None]
imgb = imgb[:, :, None]
img = np.concatenate((imgb, imgg, imgr), axis=2).astype(np.uint8)
imgs.append(img)
return imgs
def inference(image):
patches = []
img = image[:, :, ::-1].copy() # the model expects RGB inputs
patch = ReIDEncoder.transform(img)
image = image[:, :, ::-1].copy() # the model expects RGB inputs
patch = ReIDEncoder.transform(image)
patch = patch.to(device=ReIDEncoder.device)
@ -132,29 +183,43 @@ def test_dog():
pred[torch.isinf(pred)] = 1.0
bfeat = pred.cpu().data.numpy()
return bfeat
def test_img_feat():
# datapath = r"D:\datasets\ym\Img_ResnetData\aa\aa.txt"
# afeat = readdata(datapath)
imgpath = r"D:\datasets\ym\Img_ResnetData\aa\aa.jpg"
img = cv2.imread(imgpath)
bfeat = inference(img)
datapath = r"D:\datasets\ym\Img_ResnetData\rawimg\7.txt"
afeat = readdata(datapath)
rawpath = r"D:\datasets\ym\Img_ResnetData\rawimg\28950640607_mat_rgb"
imgx = readrawimg(rawpath)
cv2.imwrite("rawimg.png", imgx[7])
bfeatx = inference(imgx[7])
cost_matrix = 1 - np.maximum(0.0, cdist(afeat, bfeatx, 'cosine'))
imgpath1 = r"D:\datasets\ym\Img_ResnetData\result\0_224x224.png"
img1 = cv2.imread(imgpath1)
bfeat1 = inference(img1)
aafeat = afeat / np.linalg.norm(afeat, ord=2, axis=1, keepdims=True)
bbfeat = bfeat / np.linalg.norm(bfeat, ord=2, axis=1, keepdims=True)
cost_matrix = 1 - np.maximum(0.0, cdist(aafeat, bbfeat, 'cosine'))
print("Done!!!")
print("Done!!!")
def main():
imgpath = r"D:\datasets\ym\Img_ResnetData\20240531-103547_0354b1cb-53fa-48de-86cd-ac3c5b127ada_6921168593576\3568800050000_0.jpeg"
datapath = r"D:\datasets\ym\Img_ResnetData\0_tracker_inout.data"
datapath = r"D:\datasets\ym\Img_ResnetData\20240531-103547_0354b1cb-53fa-48de-86cd-ac3c5b127ada_6921168593576\0_tracker_inout.data"
savepath = r"D:\datasets\ym\Img_ResnetData\result"
image = cv2.imread(imgpath)
@ -184,9 +249,11 @@ def main():
if __name__ == '__main__':
main()
# main()
# test_dog()
# readimg()
test_img_feat()