diff --git a/.github/workflows/create_release.yaml b/.github/workflows/create_release.yaml index d1c8d85a..362f9efa 100644 --- a/.github/workflows/create_release.yaml +++ b/.github/workflows/create_release.yaml @@ -2,6 +2,9 @@ name: Create Release on: workflow_dispatch: + push: + branches: + - release jobs: release: @@ -45,3 +48,11 @@ jobs: with: github_token: ${{ secrets.GITHUB_TOKEN }} tag: ${{ steps.release.outputs.tag }} + + - name: Merge release -> main + uses: devmasx/merge-branch@master + with: + type: now + target_branch: main + message: Merge release into main + github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/sync_branches.yaml b/.github/workflows/sync_branches.yaml deleted file mode 100644 index a69121be..00000000 --- a/.github/workflows/sync_branches.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: Sync release branch to main - -on: - push: - branches: - - release - -jobs: - release: - runs-on: ubuntu-latest - permissions: - id-token: write - contents: write - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Merge release -> main - uses: devmasx/merge-branch@master - with: - type: now - target_branch: main - message: Merge release into main - github_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/pyproject.toml b/pyproject.toml index dbc3c30b..d102fc9a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -42,7 +42,7 @@ dependencies = [ "transformers", "datasets[vision]", "umap-learn", - "nrtk[headless]>=0.12.0", + "nrtk[headless]>=0.12.0,<=0.16.0", "trame-annotations>=0.4.0", ] diff --git a/src/nrtk_explorer/app/core.py b/src/nrtk_explorer/app/core.py index 8f13b3cc..da5fdb85 100644 --- a/src/nrtk_explorer/app/core.py +++ b/src/nrtk_explorer/app/core.py @@ -6,6 +6,8 @@ from nrtk_explorer.library.filtering import FilterProtocol from nrtk_explorer.library.dataset import get_dataset, expand_hugging_face_datasets from nrtk_explorer.library.debounce import debounce +from nrtk_explorer.library.app_config import process_config + from nrtk_explorer.app.images.images import Images from nrtk_explorer.app.embeddings import EmbeddingsApp @@ -38,28 +40,34 @@ # Engine class # --------------------------------------------------------- +config_options = { + "dataset": { + "flags": ["--dataset"], + "params": { + "nargs": "+", + "default": DEFAULT_DATASETS, + "help": "Path to the JSON file describing the image dataset", + }, + }, + "download": { + "flags": ["--download"], + "params": { + "action": "store_true", + "default": False, + "help": "Download Hugging Face Hub datasets instead of streaming them", + }, + }, +} + class Engine(Applet): - def __init__(self, server=None): + def __init__(self, server=None, **kwargs): super().__init__(server) - self.server.cli.add_argument( - "--dataset", - nargs="+", - default=DEFAULT_DATASETS, - help="Path to the JSON file describing the image dataset", - ) - - self.server.cli.add_argument( - "--download", - action="store_true", - default=False, - help="Download Hugging Face Hub datasets instead of streaming them", - ) + config = process_config(self.server.cli, config_options, **kwargs) - known_args, _ = self.server.cli.parse_known_args() dataset_identifiers = expand_hugging_face_datasets( - known_args.dataset, not known_args.download + config["dataset"], not config["download"] ) self.input_paths = dataset_identifiers self.state.current_dataset = self.input_paths[0] @@ -67,7 +75,7 @@ def __init__(self, server=None): images = Images(server=self.server) self._transforms_app = TransformsApp( - server=self.server.create_child_server(), images=images + server=self.server.create_child_server(), images=images, **kwargs ) self._embeddings_app = EmbeddingsApp( diff --git a/src/nrtk_explorer/app/transforms.py b/src/nrtk_explorer/app/transforms.py index e16633b3..e0aabd5b 100644 --- a/src/nrtk_explorer/app/transforms.py +++ b/src/nrtk_explorer/app/transforms.py @@ -11,14 +11,15 @@ import nrtk_explorer.library.nrtk_transforms as nrtk_trans import nrtk_explorer.library.yaml_transforms as nrtk_yaml from nrtk_explorer.library import object_detector -from nrtk_explorer.app.applet import Applet -from nrtk_explorer.app.parameters import ParametersApp -from nrtk_explorer.app.images.image_meta import update_image_meta, dataset_id_to_meta +from nrtk_explorer.library.app_config import process_config from nrtk_explorer.library.scoring import ( compute_score, ) -from nrtk_explorer.app.trame_utils import change_checker, delete_state +from nrtk_explorer.app.applet import Applet +from nrtk_explorer.app.parameters import ParametersApp +from nrtk_explorer.app.images.image_meta import update_image_meta, dataset_id_to_meta +from nrtk_explorer.app.trame_utils import change_checker, delete_state from nrtk_explorer.app.images.image_ids import ( dataset_id_to_image_id, dataset_id_to_transformed_image_id, @@ -86,6 +87,18 @@ def on_change_feature_enabled(self, **kwargs): self.enabled_callback() +config_options = { + "models": { + "flags": ["--models"], + "params": { + "nargs": "+", + "default": INFERENCE_MODELS_DEFAULT, + "help": "Space separated list of inference models", + }, + }, +} + + class TransformsApp(Applet): def __init__( self, @@ -94,18 +107,12 @@ def __init__( ground_truth_annotations=None, original_detection_annotations=None, transformed_detection_annotations=None, + **kwargs, ): super().__init__(server) - self.server.cli.add_argument( - "--models", - nargs="+", - default=INFERENCE_MODELS_DEFAULT, - help="Space separated list of inference models", - ) - - known_args, _ = self.server.cli.parse_known_args() - self.state.inference_models = known_args.models + config = process_config(self.server.cli, config_options, **kwargs) + self.state.inference_models = config["models"] self.state.inference_model = self.state.inference_models[0] self.state.setdefault("image_list_ids", []) self.state.setdefault("dataset_ids", []) diff --git a/src/nrtk_explorer/library/app_config.py b/src/nrtk_explorer/library/app_config.py new file mode 100644 index 00000000..5dcef776 --- /dev/null +++ b/src/nrtk_explorer/library/app_config.py @@ -0,0 +1,12 @@ +def process_config(cli, config_options, **kwargs): + for opt in config_options.values(): + cli.add_argument(*opt["flags"], **opt["params"]) + known_args, _ = cli.parse_known_args() + + config = {} + for name in config_options: + if name in kwargs: + config[name] = kwargs[name] + else: + config[name] = getattr(known_args, name) + return config diff --git a/src/nrtk_explorer/library/dataset.py b/src/nrtk_explorer/library/dataset.py index ebe81e7b..304f0fc8 100644 --- a/src/nrtk_explorer/library/dataset.py +++ b/src/nrtk_explorer/library/dataset.py @@ -73,7 +73,7 @@ def get_image(self, id: int): def is_coco_dataset(path: str): - if not os.path.exists(path): + if not os.path.exists(path) or os.path.isdir(path): return False required_keys = ['"images"', '"categories"', '"annotations"'] with open(path) as f: