Skip to content

Commit

Permalink
Apply changes from releases/v0.3.1-geti1.0.0 (#1337)
Browse files Browse the repository at this point in the history
* anomaly save_model bugfix (#1300)

* upgrade networkx module version (#1303)

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

* Valid POT configs for small HRNet models (#1317)

* [Release branch] Disable NNCF optimization for FP16 models  (#1319)

* [RELEASE] CVS-95549 - Hierarchical classification training failed without obvious reason (#1329)

* Fix h-label: per-group softmax (#1332)

* Fix dataset length bug in mpa task (#1338)

* Fix drop_last key issue for det/set (#1340)

* Hot-fix for OV inference for iseg output (#1345)

* Fix nncf model export bug (#1346)

Signed-off-by: Songki Choi <[email protected]>
Co-authored-by: Eunwoo Shin <[email protected]>
Co-authored-by: Yunchu Lee <[email protected]>
Co-authored-by: Eugene Liu <[email protected]>
Co-authored-by: Daniil Lyakhov <[email protected]>
Co-authored-by: Jihwan Eom <[email protected]>
Co-authored-by: Vladisalv Sovrasov <[email protected]>
Co-authored-by: Harim Kang <[email protected]>
Co-authored-by: Ashwin Vaidya <[email protected]>
Co-authored-by: Ashwin Vaidya <[email protected]>
  • Loading branch information
10 people authored Nov 11, 2022
1 parent 214401d commit 6b199b2
Show file tree
Hide file tree
Showing 12 changed files with 34 additions and 29 deletions.
15 changes: 9 additions & 6 deletions external/anomaly/tasks/inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def export(self, export_type: ExportType, output_model: ModelEntity) -> None:
output_model.set_data("label_schema.json", label_schema_to_bytes(self.task_environment.label_schema))
self._set_metadata(output_model)

def _model_info(self) -> Dict:
def model_info(self) -> Dict:
"""Return model info to save the model weights.
Returns:
Expand All @@ -282,7 +282,7 @@ def save_model(self, output_model: ModelEntity) -> None:
output_model (ModelEntity): Output model onto which the weights are saved.
"""
logger.info("Saving the model weights.")
model_info = self._model_info()
model_info = self.model_info()
buffer = io.BytesIO()
torch.save(model_info, buffer)
output_model.set_data("weights.pth", buffer.getvalue())
Expand All @@ -298,10 +298,13 @@ def save_model(self, output_model: ModelEntity) -> None:
output_model.optimization_methods = self.optimization_methods

def _set_metadata(self, output_model: ModelEntity):
output_model.set_data("image_threshold", self.model.image_threshold.value.cpu().numpy().tobytes())
output_model.set_data("pixel_threshold", self.model.pixel_threshold.value.cpu().numpy().tobytes())
output_model.set_data("min", self.model.normalization_metrics.state_dict()["min"].cpu().numpy().tobytes())
output_model.set_data("max", self.model.normalization_metrics.state_dict()["max"].cpu().numpy().tobytes())
if hasattr(self.model, "image_threshold"):
output_model.set_data("image_threshold", self.model.image_threshold.value.cpu().numpy().tobytes())
if hasattr(self.model, "pixel_threshold"):
output_model.set_data("pixel_threshold", self.model.pixel_threshold.value.cpu().numpy().tobytes())
if hasattr(self.model, "normalization_metrics"):
output_model.set_data("min", self.model.normalization_metrics.state_dict()["min"].cpu().numpy().tobytes())
output_model.set_data("max", self.model.normalization_metrics.state_dict()["max"].cpu().numpy().tobytes())

@staticmethod
def _is_docker() -> bool:
Expand Down
2 changes: 1 addition & 1 deletion external/anomaly/tasks/nncf.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def optimize(

logger.info("Training completed.")

def _model_info(self) -> Dict:
def model_info(self) -> Dict:
"""Return model info to save the model weights.
Returns:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,13 @@ def __getitem__(self, index):

@check_input_parameters_type({"ote_dataset": DatasetParamTypeCheck})
def __init__(
self,
ote_dataset: DatasetEntity,
labels: List[LabelEntity],
pipeline: Sequence[dict],
domain: Domain,
test_mode: bool = False,
self,
ote_dataset: DatasetEntity,
labels: List[LabelEntity],
pipeline: Sequence[dict],
domain: Domain,
test_mode: bool = False,
**kwargs,
):
self.ote_dataset = ote_dataset
self.labels = labels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ class _DataInfoProxy:
forwards data access operations to ote_dataset and converts the dataset items to the view
convenient for mmsegmentation.
"""
def __init__(self, ote_dataset, labels=None):
def __init__(
self,
ote_dataset,
labels=None,
**kwargs,
):
self.ote_dataset = ote_dataset
self.labels = labels
self.label_idx = {label.id: i for i, label in enumerate(labels)}
Expand Down
2 changes: 1 addition & 1 deletion external/mmsegmentation/submodule
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import torch
from mmcv.utils import ConfigDict
from mpa import MPAConstants
from mpa.stage import Stage
from mpa.utils.config_utils import MPAConfig
from mpa.utils.logger import get_logger
from mpa_tasks.apis import BaseTask, TrainType
Expand Down
3 changes: 3 additions & 0 deletions external/model-preparation-algorithm/mpa_tasks/apis/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def _run_task(self, stage_module, mode=None, dataset=None, parameters=None, **kw
self._model_cfg["model_classes"] = model_classes
if dataset is not None:
train_data_cfg = Stage.get_data_cfg(self._data_cfg, "train")
# if dataset size is smaller than batch size
if 0 < len(dataset) < self._recipe_cfg.data.get("samples_per_gpu", 2):
train_data_cfg.drop_last = False
train_data_cfg["data_classes"] = data_classes
new_classes = np.setdiff1d(data_classes, model_classes).tolist()
train_data_cfg["new_classes"] = new_classes
Expand Down
2 changes: 1 addition & 1 deletion external/model-preparation-algorithm/submodule
Submodule submodule updated 1 files
+1 −1 requirements.txt
7 changes: 1 addition & 6 deletions ote_cli/ote_cli/utils/hpo.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,12 +517,7 @@ def __init__(
if _is_anomaly_framework_task(task_type):
impl_class = get_impl_class(environment.model_template.entrypoints.base)
task = impl_class(task_environment=environment)
model = ModelEntity(
dataset,
environment.get_model_configuration(),
)
task.save_model(model)
save_model_data(model, self.work_dir)
torch.save(task.model_info(), osp.join(self.work_dir, "weights.pth"))
else:
save_model_data(environment.model, self.work_dir)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,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 = box.get_coords()
coords = np.array(box.get_coords(), dtype=float)
if (coords[2] - coords[0]) * (coords[3] - coords[1]) < 1.0:
continue
coords = np.array(box.get_coords(), dtype=float) / np.tile(image_size, 2)
coords /= np.tile(image_size, 2)
annotations.append(
Annotation(
Rectangle(coords[0], coords[1], coords[2], coords[3]),
Expand Down
5 changes: 2 additions & 3 deletions ote_sdk/ote_sdk/utils/vis_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ def get_actmap(
saliency_map: np.ndarray,
output_res: Union[tuple, list],
) -> np.ndarray:
"""
Get activation map (heatmap) from saliency map
"""Get activation map (heatmap) from saliency map
:param saliency_map: Saliency map with pixel values from 0-255 (np.ndarray)
:param saliency_map: Saliency map with pixel values from 0-255 (Union[np.ndarray, Iterable, int, float])
:param output_res: Output resolution (Union[tuple, list])
:return: activation map, heatmap (np.ndarray)
"""
Expand Down
2 changes: 1 addition & 1 deletion ote_sdk/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
numpy>=1.16.4
scikit-learn==0.24.*
Shapely>=1.7.1,<=1.8.0
networkx>=2.5,<2.8.1rc1
networkx>=2.6,<2.8.1rc1
opencv-python==4.5.*
pymongo==3.12.0
omegaconf==2.1.*
Expand Down

0 comments on commit 6b199b2

Please sign in to comment.