Skip to content

Commit

Permalink
Merge pull request #3 from supervisely-ecosystem/tag-assigning
Browse files Browse the repository at this point in the history
Fixied typos, less logs
  • Loading branch information
max-unfinity authored Feb 8, 2023
2 parents 0128bfa + f0250a3 commit 75e4e38
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
16 changes: 8 additions & 8 deletions src/calculate_embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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...<br>'
info_widget.description += f'downloading the model "{model_name}". This may take some time...<br>'
print(f"Running model on {device}")
model, cfg, format_input = infer_utils.create_model(model_name)
model.to(device)
Expand All @@ -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}"...<br>'
info_widget.description += f'Inferring dataset on "{device}"...<br>'
return model, cfg, format_input, input_size_hw, resize_interpolation

def infer_one(image, labels, instance_mode):
Expand Down Expand Up @@ -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):
Expand Down
7 changes: 4 additions & 3 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -353,7 +352,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...<br>"
info_run.description += (
f"the count of embeddings is {len(embeddings)}, it is too small to project with UMAP, trying PCA...<br>"
)
projection_method = "PCA"
projections = run_utils.calculate_projections(embeddings, all_info_list, projection_method, metric=metric)
print("uploading projections to team_files...")
Expand Down

0 comments on commit 75e4e38

Please sign in to comment.