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

Unify prediction #338

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 18 additions & 8 deletions plantseg/core/zoo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Model Zoo Singleton"""

# pylint: disable=C0116,C0103

import json
import logging
from enum import Enum
Expand Down Expand Up @@ -392,15 +394,23 @@ def refresh_bioimageio_zoo_urls(self):
collection_path = Path(pooch.retrieve(BIOIMAGE_IO_COLLECTION_URL, known_hash=None))
with collection_path.open(encoding='utf-8') as f:
collection = json.load(f)

models = [entry for entry in collection["collection"] if entry["type"] == "model"]
max_nickname_length = max(len(entry["nickname"]) for entry in models)

def truncate_name(name, length=100):
return name[:length] + '...' if len(name) > length else name

def build_model_url_dict(filter_func=None):
filtered_models = filter(filter_func, models) if filter_func else models
return {
f"{entry['nickname']:<{max_nickname_length}}: {truncate_name(entry['name'])}": entry["rdf_source"]
for entry in filtered_models
}

self._bioimageio_zoo_collection = collection
self._bioimageio_zoo_all_model_url_dict = {
entry["nickname"]: entry["rdf_source"] for entry in collection["collection"] if entry["type"] == "model"
}
self._bioimageio_zoo_plantseg_model_url_dict = {
entry["nickname"]: entry["rdf_source"]
for entry in collection["collection"]
if entry["type"] == "model" and self._is_plantseg_model(entry)
}
self._bioimageio_zoo_all_model_url_dict = build_model_url_dict()
self._bioimageio_zoo_plantseg_model_url_dict = build_model_url_dict(self._is_plantseg_model)

def _is_plantseg_model(self, collection_entry: dict) -> bool:
"""Determines if the 'tags' field in a collection entry contains the keyword 'plantseg'."""
Expand Down
3 changes: 3 additions & 0 deletions plantseg/viewer_napari/containers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from magicgui.widgets import Container
from qtpy.QtGui import QFont

from plantseg.viewer_napari.widgets import (
widget_add_custom_model,
Expand Down Expand Up @@ -28,6 +29,7 @@
)

STYLE_SLIDER = "font-size: 9pt;"
MONOSPACE_FONT = QFont("Courier New", 9) # "Courier New" is a common monospaced font


def get_data_io_tab():
Expand Down Expand Up @@ -59,6 +61,7 @@ def get_preprocessing_tab():


def get_segmentation_tab():
widget_unet_prediction.model_id.native.setFont(MONOSPACE_FONT)
container = Container(
widgets=[
widget_unet_prediction,
Expand Down
3 changes: 2 additions & 1 deletion plantseg/viewer_napari/viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ def run_viewer():
(get_proofreading_tab(), 'Proofreading'),
(get_extras_tab(), 'Models'),
]:
viewer.window.add_dock_widget(_containers, name=name, tabify=True)
this_widget = viewer.window.add_dock_widget(_containers, name=name, tabify=True)
this_widget.setFixedWidth(666)

# Show data tab by default
viewer.window._dock_widgets['Input/Output'].show()
Expand Down
Loading