Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaiPetukhov committed Sep 27, 2023
1 parent ea5864c commit 77e0cce
Show file tree
Hide file tree
Showing 66 changed files with 4,448 additions and 2,832 deletions.
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ git+https://github.com/supervisely/supervisely.git@NikolaiPetukhov
jsonschema
networkx
scikit-image>=0.17.1, <1.0.0
cacheout
cacheout
markdown
json2html
31 changes: 17 additions & 14 deletions src/compute/Net.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ def __init__(self, graph_desc, output_folder):
if not os.path.exists(graph_path):
raise RuntimeError('No such config file "%s"' % graph_path)
else:
graph = json.load(open(graph_path, "r"))
self.graph = json.load(open(graph_path, "r"))
else:
graph = graph_desc
self.graph = graph_desc

for layer_config in graph:
for layer_config in self.graph:
if "action" not in layer_config:
raise RuntimeError('No "action" field in layer "{}".'.format(layer_config))
action = layer_config["action"]
Expand Down Expand Up @@ -203,20 +203,23 @@ def start(self, data_el):
for output in output_generator:
yield output

def start_iterate(self, data_el):
def start_iterate(self, data_el, layer_idx: int = None):
img_pr_name = data_el[0].get_pr_name()
img_ds_name = data_el[0].get_ds_name()

start_layer_indxs = set()
for idx, layer in enumerate(self.layers):
if layer.type != "data":
continue
if layer.project_name == img_pr_name and (
"*" in layer.dataset_names or img_ds_name in layer.dataset_names
):
start_layer_indxs.add(idx)
if len(start_layer_indxs) == 0:
raise RuntimeError("Can not find data layer for the image: {}".format(data_el))
if layer_idx is not None:
start_layer_indxs = [layer_idx]
else:
start_layer_indxs = set()
for idx, layer in enumerate(self.layers):
if layer.type != "data":
continue
if layer.project_name == img_pr_name and (
"*" in layer.dataset_names or img_ds_name in layer.dataset_names
):
start_layer_indxs.add(idx)
if len(start_layer_indxs) == 0:
raise RuntimeError("Can not find data layer for the image: {}".format(data_el))

for start_layer_indx in start_layer_indxs:
output_generator = self.process_iterate(start_layer_indx, data_el)
Expand Down
58 changes: 24 additions & 34 deletions src/compute/layers/processing/BlurLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@


class BlurLayer(Layer):

action = 'blur'
action = "blur"

layer_settings = {
"required": ["settings"],
Expand All @@ -22,62 +21,53 @@ class BlurLayer(Layer):
"oneOf": [
{
"type": "object",
"required": [
"name",
"sigma"
],
"required": ["name", "sigma"],
"properties": {
"name": {
"type": "string",
"enum": [
"gaussian",
]
],
},
"sigma": {
"type": "object",
"required": ["min", "max"],
"properties": {
"min": {"type": "number", "minimum": 0.01},
"max": {"type": "number", "minimum": 0.01},
}
}
}
},
},
},
},
{
"type": "object",
"required": [
"name",
"kernel"
],
"required": ["name", "kernel"],
"properties": {
"name": {
"type": "string",
"enum": [
"median",
]
],
},
"kernel": {
"type": "integer",
"minimum": 3
}
}
}
]
"kernel": {"type": "integer", "minimum": 3},
},
},
],
}
}
},
}

def __init__(self, config):
Layer.__init__(self, config)
if (self.settings['name'] == 'median') and (self.settings['kernel'] % 2 == 0):
raise RuntimeError('Kernel for median blur must be odd.')
if (self.settings["name"] == "median") and (self.settings["kernel"] % 2 == 0):
raise RuntimeError("Kernel for median blur must be odd.")

def check_min_max(dictionary, text):
if dictionary['min'] > dictionary['max']:
if dictionary["min"] > dictionary["max"]:
raise RuntimeError('"min" should be <= than "max" for "{}".'.format(text))

if self.settings['name'] == 'gaussian':
check_min_max(self.settings['sigma'], 'sigma')
if self.settings["name"] == "gaussian":
check_min_max(self.settings["sigma"], "sigma")

def requires_image(self):
return True
Expand All @@ -86,13 +76,13 @@ def process(self, data_el: Tuple[ImageDescriptor, Annotation]):
img_desc, ann = data_el

img = img_desc.read_image()
img = img.astype(np.float32)
if self.settings['name'] == 'gaussian':
sigma_b = self.settings['sigma']
sigma_value = np.random.uniform(sigma_b['min'], sigma_b['max'])
img = img.astype(np.uint8)
if self.settings["name"] == "gaussian":
sigma_b = self.settings["sigma"]
sigma_value = np.random.uniform(sigma_b["min"], sigma_b["max"])
res_img = cv2.GaussianBlur(img, ksize=(0, 0), sigmaX=sigma_value)
elif self.settings['name'] == 'median':
res_img = cv2.medianBlur(img, ksize=self.settings['kernel'])
elif self.settings["name"] == "median":
res_img = cv2.medianBlur(img, ksize=self.settings["kernel"])
else:
raise NotImplementedError()

Expand Down
12 changes: 12 additions & 0 deletions src/globals.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import queue
from dotenv import load_dotenv

import supervisely as sly
Expand Down Expand Up @@ -29,3 +30,14 @@

layers_count = 0
layers = {}


update_queue = queue.Queue()


def updater(update: str):
global update_queue
update_queue.put(update)


context_menu_position = None
34 changes: 34 additions & 0 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,44 @@
import shutil
import os
import threading
import time
from supervisely import Application

from src.ui.ui import layout
from src.ui.tabs.configure import update_metas, update_nodes
from src.ui.tabs.json_preview import load_json
import src.globals as g

shutil.rmtree(g.STATIC_DIR, ignore_errors=True)
os.mkdir(g.STATIC_DIR)
app = Application(layout=layout, static_dir=g.STATIC_DIR)


def _update_f():
while True:
updates = []
while not g.update_queue.empty():
updates.append(g.update_queue.get())
if len(updates) == 0:
time.sleep(0.1)
continue
try:
if "load_json" in updates:
load_json()
elif "nodes" in updates:
update_nodes()
else:
update_metas()
finally:
for _ in range(len(updates)):
g.update_queue.task_done()
time.sleep(0.1)


update_loop = threading.Thread(
target=_update_f,
name="App update loop",
daemon=True,
)

update_loop.start()
49 changes: 38 additions & 11 deletions src/ui/dtl/Action.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,66 @@
from typing import Optional

from supervisely.app.widgets import NodesFlow, Container, Text
import src.globals as g


class Action:
name = None
title = None
docs_url = None
description = None
md_description = ""
width = 340
# when setting options from settings json, values from _settings_mapping will be mapped to options.
# If there is no option mapped directly to setting, set this option mapping to None and set the option value
# in set_settings_from_json function. If option name is different from setting name - set mapping in
# _settings_mapping below. If option name is the same as setting name - no need to set mapping.
_settings_mapping = {}
header_color = None
header_text_color = None

@classmethod
def create_new_layer(cls, layer_id: Optional[str] = None):
raise NotImplementedError

@classmethod
def create_inputs(cls):
return [NodesFlow.Node.Input("source", "Source")]
return [NodesFlow.Node.Input("source", "Input", color="#000000")]

@classmethod
def create_outputs(cls):
return [NodesFlow.Node.Output("destination", "Destination")]
return [NodesFlow.Node.Output("destination", "Output", color="#000000")]

@classmethod
def create_info_widget(cls):
return Container(
widgets=[
Text(f"<h3>{cls.title}</h3>", color="white"),
Text(f'<a href="{cls.docs_url}" target="_blank" style="color: white;">Docs</a>'),
Text(f"<p>{cls.description}</p>", color="white"),
Text(f"<h3>{cls.title}</h3>"),
Text(f'<a href="{cls.docs_url}" target="_blank">Docs</a>'),
Text(f"<p>{cls.description}</p>"),
]
)


class SourceAction(Action):
header_color = "#13ce66"
header_text_color = "#000000"


class PixelLevelAction(Action):
header_color = "#c9a5fa"
header_text_color = "#000000"


class SpatialLevelAction(Action):
header_color = "#fcd068"
header_text_color = "#000000"


class AnnotationAction(Action):
header_color = "#90ddf5"
header_text_color = "#000000"


class OtherAction(Action):
header_color = "#cfcfcf"
header_text_color = "#000000"


class OutputAction(Action):
header_color = "#ff5e90"
header_text_color = "#000000"
Loading

0 comments on commit 77e0cce

Please sign in to comment.