Skip to content

Commit

Permalink
Merge branch 'liezl/ars-add-sessions-to-cache' of https://github.com/…
Browse files Browse the repository at this point in the history
…talmolab/sleap into liezl/asc-initial-update-instances-across-views
  • Loading branch information
roomrys committed Oct 19, 2023
2 parents 4706fb2 + 81be658 commit 4994f04
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 245 deletions.
6 changes: 3 additions & 3 deletions docs/guides/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ optional arguments:
-e [EXPORT_PATH], --export_path [EXPORT_PATH]
Path to output directory where the frozen model will be exported to.
Defaults to a folder named 'exported_model'.
-u, --unrag UNRAG
Convert ragged tensors into regular tensors with NaN padding.
Defaults to True.
-r, --ragged RAGGED
Keep tensors ragged if present. If ommited, convert
ragged tensors into regular tensors with NaN padding.
-n, --max_instances MAX_INSTANCES
Limit maximum number of instances in multi-instance models.
Not available for ID models. Defaults to None.
Expand Down
57 changes: 47 additions & 10 deletions sleap/gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
import platform
import random
import re
import traceback
from logging import getLogger
from pathlib import Path
from typing import Callable, List, Optional, Tuple

Expand Down Expand Up @@ -85,6 +87,9 @@
from sleap.util import parse_uri_path


logger = getLogger(__name__)


class MainWindow(QMainWindow):
"""The SLEAP GUI application.
Expand All @@ -101,6 +106,7 @@ class MainWindow(QMainWindow):
def __init__(
self,
labels_path: Optional[str] = None,
labels: Optional[Labels] = None,
reset: bool = False,
no_usage_data: bool = False,
*args,
Expand All @@ -118,7 +124,7 @@ def __init__(
self.setAcceptDrops(True)

self.state = GuiState()
self.labels = Labels()
self.labels = labels or Labels()

self.commands = CommandContext(
state=self.state, app=self, update_callback=self.on_data_update
Expand Down Expand Up @@ -175,8 +181,10 @@ def __init__(
print("Restoring GUI state...")
self.restoreState(prefs["window state"])

if labels_path:
if labels_path is not None:
self.commands.loadProjectFile(filename=labels_path)
elif labels is not None:
self.commands.loadLabelsObject(labels=labels)
else:
self.state["project_loaded"] = False

Expand Down Expand Up @@ -254,7 +262,6 @@ def dragEnterEvent(self, event):
event.acceptProposedAction()

def dropEvent(self, event):

# Parse filenames
filenames = event.mimeData().data("text/uri-list").data().decode()
filenames = [parse_uri_path(f.strip()) for f in filenames.strip().split("\n")]
Expand Down Expand Up @@ -1610,8 +1617,12 @@ def _show_keyboard_shortcuts_window(self):
ShortcutDialog().exec_()


def main(args: Optional[list] = None):
"""Starts new instance of app."""
def create_sleap_label_parser():
"""Creates parser for `sleap-label` command line arguments.
Returns:
argparse.ArgumentParser: The parser.
"""

import argparse

Expand Down Expand Up @@ -1651,6 +1662,23 @@ def main(args: Optional[list] = None):
default=False,
)

return parser


def create_app():
"""Creates Qt application."""

app = QApplication([])
app.setApplicationName(f"SLEAP v{sleap.version.__version__}")
app.setWindowIcon(QtGui.QIcon(sleap.util.get_package_file("gui/icon.png")))

return app


def main(args: Optional[list] = None, labels: Optional[Labels] = None):
"""Starts new instance of app."""

parser = create_sleap_label_parser()
args = parser.parse_args(args)

if args.nonnative:
Expand All @@ -1662,17 +1690,26 @@ def main(args: Optional[list] = None):
# https://stackoverflow.com/q/64818879
os.environ["QT_MAC_WANTS_LAYER"] = "1"

app = QApplication([])
app.setApplicationName(f"SLEAP v{sleap.version.__version__}")
app.setWindowIcon(QtGui.QIcon(sleap.util.get_package_file("gui/icon.png")))
app = create_app()

window = MainWindow(
labels_path=args.labels_path, reset=args.reset, no_usage_data=args.no_usage_data
labels_path=args.labels_path,
labels=labels,
reset=args.reset,
no_usage_data=args.no_usage_data,
)
window.showMaximized()

# Disable GPU in GUI process. This does not affect subprocesses.
sleap.use_cpu_only()
try:
sleap.use_cpu_only()
except RuntimeError: # Visible devices cannot be modified after being initialized
logger.warning(
"Running processes on the GPU. Restarting your GUI should allow switching "
"back to CPU-only mode.\n"
"Received the following error when trying to switch back to CPU-only mode:"
)
traceback.print_exc()

# Print versions.
print()
Expand Down
Loading

0 comments on commit 4994f04

Please sign in to comment.