Skip to content

Commit

Permalink
Merge branch 'main' into otx-decoupling
Browse files Browse the repository at this point in the history
  • Loading branch information
igor-davidyuk committed Mar 11, 2024
2 parents e098b2d + c3bf051 commit 964b42b
Show file tree
Hide file tree
Showing 106 changed files with 748 additions and 181 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/build-package-internal-pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
release:
types: [published]

permissions:
contents: read

jobs:
build:
uses: ./.github/workflows/build-package.yaml
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-package-pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ name: Publish package [PyPI]
on:
workflow_dispatch:

permissions:
contents: read

jobs:
build:
uses: ./.github/workflows/build-package.yaml
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-package-test-pypi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
release:
types: [published]

permissions:
contents: read

jobs:
build:
uses: ./.github/workflows/build-package.yaml
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/build-package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ env:
PYPI_PORT: ${{ secrets.PYPI_PORT }}
ENABLE_DEV_DEPENDENCIES: ${{ inputs.enable_dev_dependencies }}

permissions:
contents: read

jobs:
build_sdk:
runs-on: [self-hosted, sdk-runner]
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/nightly-tests-geti-develop.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
schedule: # Execute tests at midnight every day
- cron: "0 0 * * *"

permissions:
contents: read

jobs:
build:
uses: ./.github/workflows/nightly-tests.yaml
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/nightly-tests-geti-latest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
schedule: # Execute tests at midnight every day
- cron: "0 0 * * *"

permissions:
contents: read

jobs:
build:
uses: ./.github/workflows/nightly-tests.yaml
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/nightly-tests-geti-mvp.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ on:
schedule: # Execute tests at midnight every day
- cron: "0 0 * * *"

permissions:
contents: read

jobs:
build:
uses: ./.github/workflows/nightly-tests.yaml
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/nightly-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ env:
CONDA_ENV: sc_sdk_nightly_test_environment
PYTHON_VERSION: 3.8

permissions:
contents: read

jobs:
nightly_tests:
runs-on: [self-hosted, sdk-runner]
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/pre-merge-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ env:
REPORT_DIRECTORY: reports
PYTHONUTF8: '1'

permissions:
contents: read
checks: write
actions: write

jobs:
pr_tests:
runs-on: ${{ matrix.os }}
Expand Down
72 changes: 72 additions & 0 deletions .github/workflows/scorecard.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# This workflow uses actions that are not certified by GitHub. They are provided
# by a third-party and are governed by separate terms of service, privacy
# policy, and support documentation.

name: Scorecard supply-chain security
on:
# For Branch-Protection check. Only the default branch is supported. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#branch-protection
branch_protection_rule:
# To guarantee Maintained check is occasionally updated. See
# https://github.com/ossf/scorecard/blob/main/docs/checks.md#maintained
schedule:
- cron: '18 5 * * 2'
push:
branches: [ "main" ]

# Declare default permissions as read only.
permissions: read-all

jobs:
analysis:
name: Scorecard analysis
runs-on: ubuntu-latest
permissions:
# Needed to upload the results to code-scanning dashboard.
security-events: write
# Needed to publish results and get a badge (see publish_results below).
id-token: write
# Uncomment the permissions below if installing in a private repository.
# contents: read
# actions: read

steps:
- name: "Checkout code"
uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 # v3.1.0
with:
persist-credentials: false

- name: "Run analysis"
uses: ossf/scorecard-action@e38b1902ae4f44df626f11ba0734b14fb91f8f86 # v2.1.2
with:
results_file: results.sarif
results_format: sarif
# (Optional) "write" PAT token. Uncomment the `repo_token` line below if:
# - you want to enable the Branch-Protection check on a *public* repository, or
# - you are installing Scorecard on a *private* repository
# To create the PAT, follow the steps in https://github.com/ossf/scorecard-action#authentication-with-pat.
# repo_token: ${{ secrets.SCORECARD_TOKEN }}

# Public repositories:
# - Publish results to OpenSSF REST API for easy access by consumers
# - Allows the repository to include the Scorecard badge.
# - See https://github.com/ossf/scorecard-action#publishing-results.
# For private repositories:
# - `publish_results` will always be set to `false`, regardless
# of the value entered here.
publish_results: true

# Upload the results as artifacts (optional). Commenting out will disable uploads of run results in SARIF
# format to the repository Actions tab.
- name: "Upload artifact"
uses: actions/upload-artifact@3cea5372237819ed00197afe530f5a7ea3e805c8 # v3.1.0
with:
name: SARIF file
path: results.sarif
retention-days: 5

# Upload the results to GitHub's code scanning dashboard.
- name: "Upload to code-scanning"
uses: github/codeql-action/upload-sarif@17573ee1cc1b9d061760f3a006fc4aac4f944fd5 # v2.2.4
with:
sarif_file: results.sarif
3 changes: 3 additions & 0 deletions .github/workflows/security-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
REPORT_DIRECTORY: reports

permissions:
contents: read

jobs:
security:
runs-on: [self-hosted, sdk-runner]
Expand Down
22 changes: 20 additions & 2 deletions geti_sdk/deployment/legacy_converters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@
versions of the Intel® Geti™ platform, i.e. v1.8 and below.
"""

from .legacy_anomaly_converter import AnomalyClassificationToAnnotationConverter
from .legacy_anomaly_converter import (
AnomalyClassificationToAnnotationConverter,
AnomalyDetectionToAnnotationConverter,
AnomalySegmentationToAnnotationConverter,
)
from .legacy_classification_converter import ClassificationToAnnotationConverter
from .legacy_detection_converter import RotatedRectToAnnotationConverter
from .legacy_segmentation_converter import (
MaskToAnnotationConverter,
SegmentationToAnnotationConverter,
)

__all__ = ["AnomalyClassificationToAnnotationConverter"]
__all__ = [
"AnomalyClassificationToAnnotationConverter",
"AnomalyDetectionToAnnotationConverter",
"AnomalySegmentationToAnnotationConverter",
"ClassificationToAnnotationConverter",
"SegmentationToAnnotationConverter",
"MaskToAnnotationConverter",
"RotatedRectToAnnotationConverter",
]
101 changes: 101 additions & 0 deletions geti_sdk/deployment/legacy_converters/legacy_anomaly_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from typing import Any, Dict

import numpy as np
from openvino.model_api.models.utils import AnomalyResult
from otx.api.entities.annotation import (
Annotation,
AnnotationSceneEntity,
Expand All @@ -25,6 +26,7 @@
from otx.api.usecases.exportable_code.prediction_to_annotation_converter import (
IPredictionToAnnotationConverter,
)
from otx.api.utils.segmentation_utils import create_annotation_from_segmentation_map


class AnomalyClassificationToAnnotationConverter(IPredictionToAnnotationConverter):
Expand Down Expand Up @@ -63,3 +65,102 @@ def convert_to_annotation(
return AnnotationSceneEntity(
kind=AnnotationSceneKind.PREDICTION, annotations=annotations
)


class AnomalySegmentationToAnnotationConverter(IPredictionToAnnotationConverter):
"""
Convert AnomalySegmentation Predictions ModelAPI to Annotations.
:param labels: Label Schema containing the label info of the task
"""

def __init__(self, label_schema: LabelSchemaEntity):
labels = label_schema.get_labels(include_empty=False)
self.normal_label = [label for label in labels if not label.is_anomalous][0]
self.anomalous_label = [label for label in labels if label.is_anomalous][0]
self.label_map = {0: self.normal_label, 1: self.anomalous_label}

def convert_to_annotation(
self, predictions: AnomalyResult, metadata: Dict[str, Any]
) -> AnnotationSceneEntity:
"""
Convert predictions to OTX Annotation Scene using the metadata.
:param predictions: Raw predictions from the model.
:param metadata: Variable containing metadata information.
:return: OTX annotation scene entity object.
"""
assert predictions.pred_mask is not None
assert predictions.anomaly_map is not None
annotations = create_annotation_from_segmentation_map(
predictions.pred_mask, predictions.anomaly_map / 255.0, self.label_map
)
if len(annotations) == 0:
# TODO: add confidence to this label
annotations = [
Annotation(
Rectangle.generate_full_box(),
labels=[ScoredLabel(label=self.normal_label, probability=1.0)],
)
]
return AnnotationSceneEntity(
kind=AnnotationSceneKind.PREDICTION, annotations=annotations
)


class AnomalyDetectionToAnnotationConverter(IPredictionToAnnotationConverter):
"""
Convert Anomaly Detection Predictions ModelAPI to Annotations.
:param labels: Label Schema containing the label info of the task
"""

def __init__(self, label_schema: LabelSchemaEntity):
labels = label_schema.get_labels(include_empty=False)
self.normal_label = [label for label in labels if not label.is_anomalous][0]
self.anomalous_label = [label for label in labels if label.is_anomalous][0]
self.label_map = {0: self.normal_label, 1: self.anomalous_label}

def convert_to_annotation(
self, predictions: AnomalyResult, metadata: Dict[str, Any]
) -> AnnotationSceneEntity:
"""
Convert predictions to OTX Annotation Scene using the metadata.
:param predictions: Raw predictions from the model.
:param metadata: Variable containing metadata information.
:return: OTX annotation scene entity object.
"""
assert predictions.pred_boxes is not None
assert predictions.pred_score is not None
assert predictions.pred_mask is not None
annotations = []
image_h, image_w = predictions.pred_mask.shape
for box in predictions.pred_boxes:
annotations.append(
Annotation(
Rectangle(
box[0] / image_w,
box[1] / image_h,
box[2] / image_w,
box[3] / image_h,
),
labels=[
ScoredLabel(
label=self.anomalous_label,
probability=predictions.pred_score,
)
],
)
)
if len(annotations) == 0:
# TODO: add confidence to this label
annotations = [
Annotation(
Rectangle.generate_full_box(),
labels=[ScoredLabel(label=self.normal_label, probability=1.0)],
)
]
return AnnotationSceneEntity(
kind=AnnotationSceneKind.PREDICTION, annotations=annotations
)

0 comments on commit 964b42b

Please sign in to comment.