diff --git a/custom_apps/FEATURE_VECTOR_SIMILARITY_FAISS/faiss_functions.py b/custom_apps/FEATURE_VECTOR_SIMILARITY_FAISS/faiss_functions.py index f29f906..6b36568 100644 --- a/custom_apps/FEATURE_VECTOR_SIMILARITY_FAISS/faiss_functions.py +++ b/custom_apps/FEATURE_VECTOR_SIMILARITY_FAISS/faiss_functions.py @@ -128,6 +128,11 @@ def get_clip_info(model, query_image_path, item_info, top_k=4): # index_type=model.value[1].index_type) inference_times, result_img_paths, result_percents = vector_model.query_faiss(query_image_path, top_k=top_k) + + for i in range(len(result_percents)): + if float(result_percents[i]) < 0.0: + result_percents[i] = None + result_img_paths[i] = None report_info = ReportInfo( feature_extraction_model=ReportInfoConst.feature_extraction_model, diff --git a/custom_apps/FEATURE_VECTOR_SIMILARITY_FAISS/utils.py b/custom_apps/FEATURE_VECTOR_SIMILARITY_FAISS/utils.py index 6904d53..2301c9a 100644 --- a/custom_apps/FEATURE_VECTOR_SIMILARITY_FAISS/utils.py +++ b/custom_apps/FEATURE_VECTOR_SIMILARITY_FAISS/utils.py @@ -7,6 +7,14 @@ def search_glass_parts(image_path_list): result = [] for image_path in image_path_list: + + if image_path is None: + result.append(None) + continue + elif not os.path.exists(image_path): + result.append(None) + continue + parts_path = Path(os.path.join(os.path.dirname(os.path.dirname(image_path)),ImageDepths.parts)) parts_files_generator = parts_path.rglob('*.png') diff --git a/main_rest/app/models.py b/main_rest/app/models.py index e29d4e0..f2986a6 100644 --- a/main_rest/app/models.py +++ b/main_rest/app/models.py @@ -659,8 +659,8 @@ class VectorGlassesImageResult(BaseModel): class VectorPartsImageResult(BaseModel): image : str | None = Field("", description='이미지 데이터', example='') - percents: float = Field(0.0, description='percents 값', example='') - imageInfo : str = Field("", description='원본이미지 이름', example='') + percents: float | None = Field(0.0, description='percents 값', example='') + imageInfo : str | None = Field("", description='원본이미지 이름', example='') #=============================================================================== #=============================================================================== #=============================================================================== diff --git a/main_rest/app/routes/services.py b/main_rest/app/routes/services.py index d32c378..90e41a0 100644 --- a/main_rest/app/routes/services.py +++ b/main_rest/app/routes/services.py @@ -535,11 +535,19 @@ async def vactor_vit_input_glasses_img_data(request: Request, request_body_info: for img, percents, parts in zip(result_image_paths, result_percents, result_parts): b64_data = None - if os.path.exists(img): - b64_data = image_to_base64_string(img) - float_percent = float(percents) + float_percent = None + img_info = None - info = M.VectorGlassesImageResult(image=b64_data, percents=float_percent, imageInfo=os.path.split(img)[-1], parts=parts) + if img is not None: + if os.path.exists(img): + b64_data = image_to_base64_string(img) + img_info = os.path.split(img)[-1] + + if percents is not None: + if percents.isnumeric: + float_percent = float(percents) + + info = M.VectorGlassesImageResult(image=b64_data, percents=float_percent, imageInfo=img_info, parts=parts) vector_image_results.append(info) @@ -621,11 +629,19 @@ async def vactor_vit_input_parts_img_data(request: Request, request_body_info: M for img, percents in zip(result_image_paths, result_percents): b64_data = None - if os.path.exists(img): - b64_data = image_to_base64_string(img) - float_percent = float(percents) + float_percent = None + img_info = None - info = M.VectorPartsImageResult(image=b64_data, percents=float_percent, imageInfo=os.path.split(img)[-1]) + if img is not None: + if os.path.exists(img): + b64_data = image_to_base64_string(img) + img_info = os.path.split(img)[-1] + + if percents is not None: + if percents.isnumeric: + float_percent = float(percents) + + info = M.VectorPartsImageResult(image=b64_data, percents=float_percent, imageInfo=img_info) vector_image_results.append(info)