From 0ea955674a87eee1bd946a3a9673385c50a97844 Mon Sep 17 00:00:00 2001 From: Ox Date: Mon, 21 Oct 2024 17:48:09 -0300 Subject: [PATCH] para test --- src/paravisionx.py | 50 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/src/paravisionx.py b/src/paravisionx.py index f61eecd19..9114fb663 100644 --- a/src/paravisionx.py +++ b/src/paravisionx.py @@ -3,7 +3,7 @@ # import json import sys - +import numpy as np ### export PYTHONPATH=/wherever/yoloserv/modules ... as long as "paravision/.../" is in there from paravision.recognition.exceptions import ParavisionException from paravision.recognition.engine import Engine @@ -47,31 +47,51 @@ class Paravision(FaceClass): + # @doc compare two named images, previously loaded def compare(self, name1, name2): - print("** face_recognition::compare ... %s vs %s" % (name1,name2)) + print("** paravision::compare ... %s vs %s" % (name1, name2)) + + # Ensure the image is reshaped to match the expected input size (e.g., (1, 3, 112, 112)) + def adjust_image_shape(img, target_shape=(1, 3, 112, 112)): + img_shape = img.shape + + # If image shape doesn't match target, adjust it (resize, pad, or reshape as needed) + if img_shape != target_shape: + print(f"Adjusting image shape from {img_shape} to {target_shape}") + # Resize or pad as necessary to match the target shape + img = np.resize(img, target_shape) # Resizes without preserving aspect ratio (can be modified if needed) + + return img + + # Adjust the shape of both images + self.imgs[name1] = adjust_image_shape(self.imgs[name1]) + self.imgs[name2] = adjust_image_shape(self.imgs[name2]) + + # Get embeddings using the Paravision SDK self.encs[name1] = self.sdk.get_embedding_from_prepared_image(self.imgs[name1]) self.encs[name2] = self.sdk.get_embedding_from_prepared_image(self.imgs[name2]) - #if self.encs[name1]==[]: - # return '{ "status":14330, "remark":"could not encode image", "guilty_param":"img1", "guilty_value":"%s" }' % name1 - #if self.encs[name2]==[]: - # return '{ "status":14331, "remark":"could not encode image", "guilty_param":"img2", "guilty_value":"%s" }' % name2 + + # Debug: Print the encodings print(self.encs.keys()) print(self.encs[name1]) print(self.encs[name2]) + try: + # Assuming 'self.model' and 'other.model' are defined elsewhere in your code res = self.sdk.get_match_score(self.model, other.model) - print("Match is ",res) - #self.match_score = 1000 * (1 - face_recognition.face_distance([self.encs[name1][0]], self.encs[name2][0])) - #print("Score is ",self.match_score) - - # Create .json - self.tree["score"] = self.match_score[0] + print("Match is ", res) + + # Store the result in self.tree + self.tree["score"] = res # Assuming 'res' is the match score + except Exception as ex: - print("** paravision::compare exception ... " + str(ex) ) - self.errstr = "image comparison exception at compute_scores: "+str(ex) + print("** paravision::compare exception ... " + str(ex)) + self.errstr = "image comparison exception at compute_scores: " + str(ex) return '{ "status":332410, "remark":"%s" }' % self.errstr - return '{ "status":0, "remark":"OK", "score":%d }' % self.match_score[0] + + # Return success with the match score + return '{ "status":0, "remark":"OK", "score":%d }' % self.tree["score"]