Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade SDK version to v6.73.258. Added Bokeh widget #9

Merged
merged 16 commits into from
Dec 18, 2024
Merged
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "Explore data with embeddings",
"description": "Calculate and visualize embeddings",
"entrypoint": "python -m uvicorn src.main:app --host 0.0.0.0 --port 8000",
"docker_image": "supervisely/embeddings_app:1.0.2",
"docker_image": "supervisely/embeddings_app:1.0.3",
"port": 8000,
"icon": "https://user-images.githubusercontent.com/115161827/211832834-eef9325d-9e00-4499-ae42-2e7ee3d97f1a.png",
"icon_cover": true,
Expand All @@ -26,7 +26,7 @@
"target": ["images_project", "images_dataset"],
"context_category": "Metric Learning"
},
"instance_version": "6.11.10",
"instance_version": "6.12.12",
"need_gpu": false,
"gpu": "preferred",
"community_agent": false
Expand Down
4 changes: 3 additions & 1 deletion dev_requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
supervisely==6.72.170
supervisely==6.73.258
transformers==4.33.2
timm==0.9.5
torch
scikit-learn==1.3.1
umap-learn==0.5.4
fastapi==0.109.0
bokeh==3.1.1
6 changes: 4 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ RUN pip3 install transformers==4.33.2 timm==0.9.5 scikit-learn==1.3.1 umap-learn
# Download metaclip base model
RUN python -c 'import transformers; transformers.AutoModel.from_pretrained("facebook/metaclip-b16-fullcc2.5b")'

RUN pip3 install supervisely==6.73.170
LABEL python_sdk_version=6.73.170
RUN pip3 install supervisely==6.73.258
RUN pip3 install fastapi==0.109.0 bokeh==3.1.1

LABEL python_sdk_version=6.73.258
51 changes: 30 additions & 21 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
Field,
Progress,
SelectDataset,
IFrame,
Bokeh,
SelectDatasetTree,
NotificationBox,
)
Expand Down Expand Up @@ -169,12 +171,9 @@ def update_globals(new_dataset_ids):


### Embeddings Chart
chart = ScatterChart(
title=f"None",
xaxis_type="numeric",
height=600,
)
card_chart = Card(content=chart)
bokeh = Bokeh(plots=[], x_axis_visible=True, y_axis_visible=True, grid_visible=True)
bokeh_iframe = IFrame()
card_chart = Card(content=bokeh_iframe)
labeled_image = LabeledImage()
text = Text("no object selected")
show_all_anns = False
Expand Down Expand Up @@ -209,18 +208,18 @@ def toggle_ann():
show_image(cur_info, project_meta)


@chart.click
def on_click(datapoint: ScatterChart.ClickedDataPoint):
@bokeh.value_changed
def on_click(selected_idxs):
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]
if tag_meta is not None:
tag = read_tag(info["image_id"], info["object_id"])
is_marked = bool(tag)
update_marked()
show_image(info, project_meta)
if btn_mark.is_hidden():
btn_mark.show()
if len(selected_idxs) >= 1:
info = all_info_list[selected_idxs[0]]
if tag_meta is not None:
tag = read_tag(info["image_id"], info["object_id"])
is_marked = bool(tag)
update_marked()
show_image(info, project_meta)
if btn_mark.is_hidden():
btn_mark.show()


def update_marked():
Expand Down Expand Up @@ -384,10 +383,20 @@ def run():
# 6. Show chart
obj_classes = list(set(all_info["object_cls"]))
print(f"n_classes = {len(obj_classes)}")
series, colors, global_idxs_mapping = run_utils.make_series(projections, all_info_list, project_meta)
chart.set_title(f"{model_name} {project_info.name} {projection_method} embeddings", send_changes=False)
chart.set_colors(colors, send_changes=False)
chart.set_series(series, send_changes=True)
series, pre_colors, global_idxs_mapping = run_utils.make_series(projections, all_info_list, project_meta)

series_len = len(series)
x_coordinates, y_coordinates, colors = [], [], []
for s, color in zip(series, pre_colors):
x_coordinates.extend([i["x"] for i in s["data"]])
y_coordinates.extend([i["y"] for i in s["data"]])
colors.extend([color] * len(s["data"]))

r = 0.15 if series_len > 1000 else 0.1
plot = Bokeh.Circle(x_coordinates, y_coordinates, radii=r, colors=colors)
bokeh.clear()
bokeh.add_plots([plot])
bokeh_iframe.set(bokeh.html_route_with_timestamp, height="650px", width="100%")
card_embeddings_chart.show()
update_table()
info_run.description += "Done!<br>"
Expand Down
Loading