From 1ccaf65d691b6a0f17f6a86153728ed9294e7705 Mon Sep 17 00:00:00 2001 From: unfinity Date: Thu, 9 Feb 2023 03:37:31 +0600 Subject: [PATCH 1/2] fixed typos and log messages --- src/calculate_embeddings.py | 16 ++++++++-------- src/main.py | 6 ++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/calculate_embeddings.py b/src/calculate_embeddings.py index f3f4f14..4643d0e 100644 --- a/src/calculate_embeddings.py +++ b/src/calculate_embeddings.py @@ -68,19 +68,19 @@ def extract_crops( result_yxyx.append([0, 0, img_np.shape[0], img_np.shape[1]]) result_obj_cls.append(None) if instance_mode in ["objects", "both"]: - yxyx_croods = [] + yxyx_coords = [] for label in labels: if not isinstance(label.geometry, accepted_geometry): continue if label.geometry.area < 9: continue rect = label.geometry.to_bbox() - yxyx_croods.append([rect.top, rect.left, rect.bottom, rect.right]) + yxyx_coords.append([rect.top, rect.left, rect.bottom, rect.right]) result_obj_cls.append(label.obj_class.name) result_labels.append(label) - crops = get_crops(img_np, yxyx_croods, hw_expand=hw_expand) + crops = get_crops(img_np, yxyx_coords, hw_expand=hw_expand) crops = [cv2.resize(crop, input_size_hw[::-1], interpolation=resize_interpolation) for crop in crops] - result_yxyx += yxyx_croods + result_yxyx += yxyx_coords result_crops += crops assert len(result_crops) == len(result_obj_cls) == len(result_yxyx) return result_crops, result_obj_cls, result_yxyx, result_labels @@ -119,7 +119,7 @@ def calculate_embeddings_if_needed( progress_widget=None, info_widget=None, ): - """Calculate embbeddings trying to recalculate only changed images""" + """Calculate embeddings trying to recalculate only changed images""" batch_size_api = 50 np_dtype = np.float32 @@ -139,7 +139,7 @@ def calculate_embeddings_if_needed( def init_model(model_name, device): if info_widget is not None: - info_widget.description += f'downloading the model "{model_name}", it may take a minutes...
' + info_widget.description += f'downloading the model "{model_name}". This may take some time...
' print(f"Running model on {device}") model, cfg, format_input = infer_utils.create_model(model_name) model.to(device) @@ -148,7 +148,7 @@ def init_model(model_name, device): cfg["expand_hw"] = expand_hw cfg["instance_mode"] = instance_mode if info_widget is not None: - info_widget.description += f'Infering dataset on "{device}"...
' + info_widget.description += f'Inferring dataset on "{device}"...
' return model, cfg, format_input, input_size_hw, resize_interpolation def infer_one(image, labels, instance_mode): @@ -214,7 +214,7 @@ def infer_one(image, labels, instance_mode): # Infer and collect info if progress_widget and len(to_infer_img_ids): progress_bar = progress_widget( - message=f"Infering dataset {dataset.name}...", + message=f"Inferring dataset {dataset.name}...", total=len(to_infer_img_ids), ) for image_ids in sly.batched(to_infer_img_ids, batch_size=batch_size_api): diff --git a/src/main.py b/src/main.py index ab71f88..86e46f6 100644 --- a/src/main.py +++ b/src/main.py @@ -135,7 +135,7 @@ def update_globals(new_dataset_ids): input_expand_wh_f = Field( input_expand_wh, "Expand crops (px)", - "Expand rectangles of the cropped objects by a few pixels on both XY sides. Used to give the model a little context on the boundary of the objects.", + "Expand rectangles of the cropped objects by a few pixels on both XY sides. Use it to give the model a little context on the boundary of objects.", ) content = Container([select_instance_mode_f, input_expand_wh_f]) card_preprocessing_settings = Card(title="Preprocessing settings", content=content, collapsable=True) @@ -353,7 +353,9 @@ def run(): try: projections = run_utils.calculate_projections(embeddings, all_info_list, projection_method, metric=metric) except RuntimeError: - info_run.description += f"the count of embeddings is {len(embeddings)}, it may too small to project with UMAP, trying PCA...
" + info_run.description += ( + f"the count of embeddings is {len(embeddings)}, it is too small to project with UMAP, trying PCA...
" + ) projection_method = "PCA" projections = run_utils.calculate_projections(embeddings, all_info_list, projection_method, metric=metric) print("uploading projections to team_files...") From f0250a385ab31c7cf2378fd4c355ba9b6a363059 Mon Sep 17 00:00:00 2001 From: unfinity Date: Thu, 9 Feb 2023 04:17:20 +0600 Subject: [PATCH 2/2] removed one print --- src/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main.py b/src/main.py index 86e46f6..cbf6eb4 100644 --- a/src/main.py +++ b/src/main.py @@ -211,7 +211,6 @@ def on_click(datapoint: ScatterChart.ClickedDataPoint): global global_idxs_mapping, all_info_list, project_meta, is_marked, tag_meta idx = global_idxs_mapping[datapoint.series_name][datapoint.data_index] info = all_info_list[idx] - print(datapoint.data_index, idx, info["image_id"], info["object_cls"], show_all_anns) if tag_meta is not None: tag = read_tag(info["image_id"], info["object_id"]) is_marked = bool(tag)