Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolaiPetukhov committed Sep 28, 2023
1 parent ea5864c commit d9335da
Show file tree
Hide file tree
Showing 79 changed files with 5,986 additions and 3,119 deletions.
57 changes: 57 additions & 0 deletions edges.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"id": "169143702805114",
"output": {
"node": "data_1",
"interface": "destination"
},
"input": {
"node": "if_3",
"interface": "source"
}
},
{
"id": "169143703364517",
"output": {
"node": "if_3",
"interface": "destination_true"
},
"input": {
"node": "approx_vector_2",
"interface": "source"
}
},
{
"id": "169143703561020",
"output": {
"node": "if_3",
"interface": "destination_false"
},
"input": {
"node": "duplicate_objects_4",
"interface": "source"
}
},
{
"id": "169143704716225",
"output": {
"node": "approx_vector_2",
"interface": "destination"
},
"input": {
"node": "save_5",
"interface": "source"
}
},
{
"id": "169143704898828",
"output": {
"node": "duplicate_objects_4",
"interface": "destination"
},
"input": {
"node": "save_5",
"interface": "source"
}
}
]
50 changes: 50 additions & 0 deletions graph.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
[
{
"action": "data",
"src": [
"Lemons for exam PRED/*"
],
"dst": "$data_1",
"settings": {
"classes_mapping": "default"
}
},
{
"action": "if",
"src": [
"$data_1"
],
"dst": [
"$if_2_true",
"$if_2_false"
],
"settings": {
"condition": {
"probability": 0.66
}
}
},
{
"action": "drop_obj_by_class",
"src": [
"$if_2_true"
],
"dst": "$drop_obj_by_class_3",
"settings": {
"classes": [
"kiwi"
]
}
},
{
"action": "save",
"src": [
"$if_2_false",
"$drop_obj_by_class_3"
],
"dst": "lemons_transformed",
"settings": {
"visualize": true
}
}
]
431 changes: 431 additions & 0 deletions nodes.json

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions nodes_state.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"data_1": {
"Info": null,
"source_text": "Source",
"src": "src1",
"classes_mapping_text": "Classes Mapping",
"classes_mapping": "\"default\""
},
"data_2": {
"Info": null,
"source_text": "Source",
"src": "src2",
"classes_mapping_text": "Classes Mapping",
"classes_mapping": "{\"cls2\":\"cls2_copy\"}"
},
"if_3": {
"Info": null,
"condition_text": "Condition",
"condition": "probability",
"condition_value_text": "Condition Value",
"condition_value": "0.8"
},
"approx_vector_4": {
"Info": null,
"classes_text": "Classes",
"classes": "cls1",
"epsilon_text": "Epsilon",
"epsilon": 3
},
"bitmap2lines_5": {
"Info": null,
"min_points_cnt_text": "Min Points Count",
"min_points_cnt": 2,
"classes_mapping_text": "Classes Mapping",
"classes_mapping": "{\"cls1\": \"cls1_line\"}"
},
"find_contours_6": {
"Info": null,
"classes_mapping_text": "Classes Mapping",
"classes_mapping": "{\"cls2_copy\":\"cls2_copy_cont\"}"
},
"supervisely_7": {
"Info": null,
"destination_text": "Destination",
"dst": "result"
}
}
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
32 changes: 18 additions & 14 deletions src/compute/Net.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
class Net:
def __init__(self, graph_desc, output_folder):
self.layers = []
self.preview_mode = False

if type(graph_desc) is str:
graph_path = graph_desc

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 +204,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, skip_save_layers=False):
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
17 changes: 13 additions & 4 deletions src/compute/layers/processing/RotateLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ def expand_image_with_rect(img: np.ndarray, req_rect: Rectangle):
def process(self, data_el: Tuple[ImageDescriptor, Annotation]):
img_desc, ann = data_el

aug.rotate(mode=aug.RotationModes.KEEP)

angle_dct = self.settings["rotate_angles"]
min_degrees, max_degrees = angle_dct["min_degrees"], angle_dct["max_degrees"]
rotate_degrees = np.random.uniform(min_degrees, max_degrees)
Expand All @@ -103,9 +101,20 @@ def process(self, data_el: Tuple[ImageDescriptor, Annotation]):
if black_reg_mode == "preserve_size":
rect_to_crop = Rectangle.from_array(img)
new_img, (delta_x, delta_y) = self.expand_image_with_rect(new_img, rect_to_crop)
new_ann.img_size = new_img.shape[:2]

new_ann = apply_to_labels(ann, lambda x: x.translate(delta_x, delta_y))
top_pad = max((new_img.shape[0] - ann.img_size[0]) // 2, 0)
lefet_pad = max((new_img.shape[1] - ann.img_size[1]) // 2, 0)
new_img, new_ann = aug.crop(
new_img,
new_ann,
top_pad=top_pad,
bottom_pad=new_img.shape[0] - top_pad - ann.img_size[0],
left_pad=lefet_pad,
right_pad=new_img.shape[1] - lefet_pad - ann.img_size[1],
)
new_ann.clone(img_size=new_img.shape[:2])

new_ann = apply_to_labels(new_ann, lambda x: [x.translate(delta_x, delta_y)])

if new_img is None:
return # no yield
Expand Down
Loading

0 comments on commit d9335da

Please sign in to comment.