Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward CVS-94422 size bug fix PR to release branch #1326

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 23 additions & 22 deletions data/car_tree_bug/annotations/hierarchical_default.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
{"images": [["Slide18.PNG", ["car"]],
["Slide19.PNG", ["tree"]],
["Slide16.PNG", ["car", "tree"]],
["Slide20.PNG", ["bug"]],
["Slide2.PNG", ["car", "tree"]],
["Slide15.PNG", ["bug", "car"]]
],
"hierarchy":
[
{
"parent": "self",
"group": "natural",
"labels": ["tree", "bug"],
"task_type": "single-label"
},
{
"parent": "self",
"group": "manmade",
"labels": ["car"],
"task_type": "multi-label"
}
]
{
"images": [
["Slide18.PNG", ["car"]],
["Slide19.PNG", ["tree"]],
["Slide16.PNG", ["car", "tree"]],
["Slide20.PNG", ["bug"]],
["Slide2.PNG", ["car", "tree"]],
["Slide15.PNG", ["bug", "car"]]
],
"hierarchy": [
{
"parent": "self",
"group": "natural",
"labels": ["tree", "bug"],
"task_type": "single-label"
},
{
"parent": "self",
"group": "manmade",
"labels": ["car"],
"task_type": "multi-label"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,13 @@ def _det_add_predictions_to_dataset(self, all_results, width, height, confidence
for i in range(detections.shape[0]):
probability = float(detections[i, 4])
coords = detections[i, :4].astype(float).copy()
coords /= np.array([width, height, width, height], dtype=float)
coords = np.clip(coords, 0, 1)

if probability < confidence_threshold:
if probability < confidence_threshold or (coords[2] - coords[0]) * (coords[3] - coords[1]) < 1.0:
continue

coords /= np.array([width, height, width, height], dtype=float)
coords = np.clip(coords, 0, 1)

assigned_label = [ScoredLabel(self._labels[label_idx],
probability=probability)]
if coords[3] - coords[1] <= 0 or coords[2] - coords[0] <= 0:
Expand All @@ -368,7 +369,7 @@ def _ins_seg_add_predictions_to_dataset(self, all_results, width, height, confid
for contour, hierarchy in zip(contours, hierarchies[0]):
if hierarchy[3] != -1:
continue
if len(contour) <= 2 or probability < confidence_threshold:
if len(contour) <= 2 or probability < confidence_threshold or cv2.contourArea(contour) < 1.0:
continue
if self._task_type == TaskType.INSTANCE_SEGMENTATION:
points = [Point(x=point[0][0] / width, y=point[0][1] / height) for point in contour]
Expand All @@ -377,8 +378,7 @@ def _ins_seg_add_predictions_to_dataset(self, all_results, width, height, confid
points = [Point(x=point[0] / width, y=point[1] / height) for point in box_points]
labels = [ScoredLabel(self._labels[label_idx], probability=probability)]
polygon = Polygon(points=points)
if cv2.contourArea(contour) > 0 and polygon.get_area() > 1e-12:
shapes.append(Annotation(polygon, labels=labels, id=ID(f"{label_idx:08}")))
shapes.append(Annotation(polygon, labels=labels, id=ID(f"{label_idx:08}")))
return shapes

@staticmethod
Expand Down
4 changes: 2 additions & 2 deletions ote_cli/ote_cli/utils/hpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ def run_hpo_trainer(
# need to set batch_size config from the instance of ConfigurableParameters
if hp_config["batch_size_param_name"] not in hp_config["params"].keys():
attr = hyper_parameters
for val in hp_config["batch_size_param_name"].split('.'):
for val in hp_config["batch_size_param_name"].split("."):
attr = getattr(attr, val)
hp_config["batch_size"] = attr
hp_config["batch_size"] = attr

# set hyper-parameters and print them
HpoManager.set_hyperparameter(hyper_parameters, hp_config["params"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def check_visualizer_attributes(
expected_delay: int,
expected_show_count: bool,
expected_is_one_label: bool,
expected_no_show: bool
expected_no_show: bool,
):
assert actual_visualizer.window_name == expected_name
assert actual_visualizer.delay == expected_delay
Expand Down Expand Up @@ -169,7 +169,6 @@ def test_visualizer_draw(self):
actual_image = Visualizer().draw(image=image, annotation=annotation_scene)
assert np.array_equal(actual_image, expected_image)


@pytest.mark.priority_medium
@pytest.mark.unit
@pytest.mark.reqids(Requirements.REQ_1)
Expand All @@ -189,4 +188,3 @@ def test_visualizer_no_show_mode(self):
visualizer = Visualizer(no_show=True)
visualizer.show(image)
visualizer.is_quit()

Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,10 @@ def convert_to_annotation(
image_size = metadata["original_shape"][1::-1]
for box in predictions:
scored_label = ScoredLabel(self.labels[int(box.id)], float(box.score))
coords = np.array(box.get_coords(), dtype=float) / np.tile(image_size, 2)
coords = np.array(box.get_coords(), dtype=float)
if (coords[2] - coords[0]) * (coords[3] - coords[1]) < 1.0:
continue
coords /= np.tile(image_size, 2)
annotations.append(
Annotation(
Rectangle(coords[0], coords[1], coords[2], coords[3]),
Expand Down Expand Up @@ -376,9 +379,9 @@ def convert_to_annotation(
for contour, hierarchy in zip(contours, hierarchies[0]):
if hierarchy[3] != -1:
continue
contour = list(contour)
if len(contour) <= 2:
if len(contour) <= 2 or cv2.contourArea(contour):
continue
contour = list(contour)
points = [
Point(
x=point[0][0] / metadata["original_shape"][1],
Expand All @@ -387,17 +390,14 @@ def convert_to_annotation(
for point in contour
]
polygon = Polygon(points=points)
if polygon.get_area() > 1e-12:
annotations.append(
Annotation(
polygon,
labels=[
ScoredLabel(
self.labels[int(class_idx) - 1], float(score)
)
],
)
annotations.append(
Annotation(
polygon,
labels=[
ScoredLabel(self.labels[int(class_idx) - 1], float(score))
],
)
)
annotation_scene = AnnotationSceneEntity(
kind=AnnotationSceneKind.PREDICTION,
annotations=annotations,
Expand Down Expand Up @@ -427,7 +427,7 @@ def convert_to_annotation(
for contour, hierarchy in zip(contours, hierarchies[0]):
if hierarchy[3] != -1:
continue
if len(contour) <= 2:
if len(contour) <= 2 or cv2.contourArea(contour):
continue
points = [
Point(
Expand All @@ -437,17 +437,14 @@ def convert_to_annotation(
for point in cv2.boxPoints(cv2.minAreaRect(contour))
]
polygon = Polygon(points=points)
if polygon.get_area() > 1e-12:
annotations.append(
Annotation(
polygon,
labels=[
ScoredLabel(
self.labels[int(class_idx) - 1], float(score)
)
],
)
annotations.append(
Annotation(
polygon,
labels=[
ScoredLabel(self.labels[int(class_idx) - 1], float(score))
],
)
)
annotation_scene = AnnotationSceneEntity(
kind=AnnotationSceneKind.PREDICTION,
annotations=annotations,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ def __init__(
cv2.WINDOW_NORMAL | cv2.WINDOW_KEEPRATIO | cv2.WINDOW_GUI_EXPANDED,
)
self.trackbar_name = "Opacity"
cv2.createTrackbar(self.trackbar_name, self.window_name,
0, 100, lambda x: x)
cv2.createTrackbar(
self.trackbar_name, self.window_name, 0, 100, lambda x: x
)

@staticmethod
def to_heat_mask(mask: np.ndarray) -> np.ndarray:
Expand Down
9 changes: 6 additions & 3 deletions ote_sdk/ote_sdk/utils/vis_utils.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
# Copyright (C) 2021-2022 Intel Corporation
# SPDX-License-Identifier: Apache-2.0

from typing import Union, Iterable
from typing import Iterable, Union

import cv2
import numpy as np


def get_actmap(saliency_map: Union[np.ndarray, Iterable, int, float], output_res: Union[tuple, list]) -> np.ndarray:
""" Get activation map (heatmap) from saliency map
def get_actmap(
saliency_map: Union[np.ndarray, Iterable, int, float],
output_res: Union[tuple, list],
) -> np.ndarray:
"""Get activation map (heatmap) from saliency map

Args:
saliency_map (Union[np.ndarray, Iterable, int, float]): Saliency map with pixel values from 0-255
Expand Down