-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Copy layer, add templates support (#50)
- Loading branch information
Showing
8 changed files
with
161 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# coding: utf-8 | ||
|
||
from typing import List, Tuple | ||
from src.compute.dtl_utils.item_descriptor import ImageDescriptor | ||
from src.compute.Layer import Layer | ||
from supervisely import Annotation | ||
|
||
|
||
class CopyLayer(Layer): | ||
action = "copy" | ||
|
||
layer_settings = {"required": ["settings"], "properties": {"settings": {}}} | ||
|
||
def __init__(self, config, net): | ||
Layer.__init__(self, config, net=net) | ||
|
||
def modifies_data(self): | ||
return False | ||
|
||
def process(self, data_el): | ||
yield data_el | ||
|
||
def process_batch(self, data_els: List[Tuple[ImageDescriptor, Annotation]]): | ||
yield data_els | ||
|
||
def has_batch_processing(self) -> bool: | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from src.ui.tabs.presets import apply_json | ||
import src.globals as g | ||
from supervisely import ProjectInfo, DatasetInfo | ||
|
||
|
||
project_info = None | ||
project_name = None | ||
src = None | ||
if g.PROJECT_ID is not None: | ||
ds_name = "*" | ||
if g.DATASET_ID: | ||
ds: DatasetInfo = g.api.dataset.get_info_by_id(g.DATASET_ID) | ||
ds_name = ds.name | ||
pr: ProjectInfo = g.api.project.get_info_by_id(g.PROJECT_ID) | ||
src = [f"{pr.name}/{ds_name}"] | ||
|
||
move = [ | ||
{ | ||
"action": "filtered_project", | ||
"src": src, | ||
"dst": "$filtered_project_1", | ||
"settings": { | ||
"project_id": g.PROJECT_ID, | ||
"filtered_entities_ids": g.FILTERED_ENTITIES, | ||
"classes_mapping": "default", | ||
"tags_mapping": "default", | ||
}, | ||
}, | ||
{ | ||
"action": "move", | ||
"src": ["$filtered_project_1"], | ||
"dst": "$move_2", | ||
"settings": {"move_confirmation": False}, | ||
}, | ||
] | ||
|
||
copy = [ | ||
{ | ||
"action": "filtered_project", | ||
"src": src, | ||
"dst": "$filtered_project_1", | ||
"settings": { | ||
"project_id": g.PROJECT_ID, | ||
"filtered_entities_ids": g.FILTERED_ENTITIES, | ||
"classes_mapping": "default", | ||
"tags_mapping": "default", | ||
}, | ||
}, | ||
{ | ||
"action": "copy", | ||
"src": ["$filtered_project_1"], | ||
"dst": "$copy_2", | ||
"settings": {}, | ||
}, | ||
] | ||
|
||
|
||
def load_template(template): | ||
apply_json(template) | ||
|
||
|
||
templates = { | ||
"images": { | ||
"move": move, | ||
"copy": copy, | ||
}, | ||
"videos": {}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Copy | ||
|
||
`Copy` layer copies the input data to the selected destination. | ||
|
||
### Settings | ||
|
||
<details> | ||
<summary>JSON view</summary> | ||
<pre> | ||
{ | ||
"action": "copy", | ||
"src": ["$images_project_1"], | ||
"dst": "$copy_2", | ||
"settings": {} | ||
} | ||
</pre> | ||
</details> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from typing import Optional | ||
from os.path import realpath, dirname | ||
|
||
from src.ui.dtl import OtherAction | ||
from src.ui.dtl.Layer import Layer | ||
from src.ui.dtl.utils import get_layer_docs | ||
|
||
|
||
class CopyAction(OtherAction): | ||
name = "copy" | ||
title = "Copy" | ||
docs_url = "" | ||
description = "Copies the input data to the selected destination." | ||
md_description = get_layer_docs(dirname(realpath(__file__))) | ||
|
||
@classmethod | ||
def create_new_layer(cls, layer_id: Optional[str] = None): | ||
def get_settings(options_json: dict) -> dict: | ||
return {} | ||
|
||
def create_options(src: list, dst: list, settings: dict) -> dict: | ||
return { | ||
"src": [], | ||
"dst": [], | ||
"settings": [], | ||
} | ||
|
||
return Layer( | ||
action=cls, | ||
id=layer_id, | ||
create_options=create_options, | ||
get_settings=get_settings, | ||
need_preview=False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters