Skip to content

Commit

Permalink
feat(embeddings): default to 2D plot
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Jan 21, 2025
1 parent 1b246fa commit 5dacaab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 19 deletions.
2 changes: 1 addition & 1 deletion src/nrtk_explorer/app/embeddings.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ def settings_widget(self):
with html.Div(trame_server=self.server, classes="col"):
with html.Div(classes="q-gutter-y-md"):
quasar.QBtnToggle(
v_model=("dimensionality", "3"),
v_model=("dimensionality", "2"),
toggler_color="primary",
flat=True,
spread=True,
Expand Down
37 changes: 20 additions & 17 deletions src/nrtk_explorer/library/multiprocess_predictor.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import uuid
from .predictor import Predictor

WORKER_RESPONSE_TIMEOUT = 40


def _child_worker(request_queue, result_queue, model_name, force_cpu):
signal.signal(signal.SIGINT, signal.SIG_IGN) # Ignore Ctrl+C in child
Expand All @@ -31,8 +33,7 @@ def _child_worker(request_queue, result_queue, model_name, force_cpu):
if command == "SET_MODEL":
try:
predictor = Predictor(
model_name=payload["model_name"],
force_cpu=payload["force_cpu"],
model_name=payload["model_name"], force_cpu=payload["force_cpu"]
)
result_queue.put((req_id, {"status": "OK"}))
except Exception as e:
Expand Down Expand Up @@ -90,6 +91,23 @@ def _start_process(self):
)
self._proc.start()

def _get_response(self, req_id, timeout=WORKER_RESPONSE_TIMEOUT):
while True:
try:
r_id, data = self._result_queue.get(timeout=timeout)
except queue.Empty:
raise TimeoutError("No response from worker.")
if r_id == req_id:
return data

def _wait_for_response(self, req_id):
return self._get_response(req_id, WORKER_RESPONSE_TIMEOUT)

async def _wait_for_response_async(self, req_id):
return await asyncio.get_event_loop().run_in_executor(
None, self._get_response, req_id, WORKER_RESPONSE_TIMEOUT
)

def set_model(self, model_name, force_cpu=False):
with self._lock:
self.model_name = model_name
Expand Down Expand Up @@ -118,21 +136,6 @@ async def infer(self, images):
resp = await self._wait_for_response_async(req_id)
return resp.get("result")

async def _wait_for_response_async(self, req_id):
return await asyncio.get_event_loop().run_in_executor(None, self._get_response, req_id, 40)

def _wait_for_response(self, req_id):
return self._get_response(req_id, 40)

def _get_response(self, req_id, timeout=40):
while True:
try:
r_id, data = self._result_queue.get(timeout=timeout)
except queue.Empty:
raise TimeoutError("No response from worker.")
if r_id == req_id:
return data

def reset(self):
with self._lock:
req_id = str(uuid.uuid4())
Expand Down
4 changes: 3 additions & 1 deletion vue-components/src/components/ScatterPlot.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ type Events = {
const emit = defineEmits<Events>()
const plotContainer = ref<HTMLDivElement>()
const selectMode = ref<boolean>(false)
const selectMode = ref<boolean>(true)
const colors = ref({ viridis, cividis, magma, inferno })
const colorMapName = ref<keyof typeof colors.value>('viridis')
const domain: Vector2<number> = [0, 1]
Expand Down Expand Up @@ -174,6 +174,8 @@ onMounted(() => {
// Without this there is an error upon browser refresh when sequences are defined.
scatterPlot.render(dataset.value)
// needs to be after render or pan mode and select are initially active at the same time
scatterPlot.setSelectMode()
})
function emitCameraPosition() {
Expand Down

0 comments on commit 5dacaab

Please sign in to comment.