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

Add logger, tests and refactor #62

Merged
merged 34 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e941255
fix: unet from config warning
sokovninn Sep 24, 2024
6481f04
feat: add logger
sokovninn Sep 24, 2024
8d47a8a
test: add utils tests
sokovninn Sep 24, 2024
32d16ad
style: utils tests formatting
sokovninn Sep 24, 2024
7a3e81e
fix: args extenstion in merge dataset function
sokovninn Sep 24, 2024
c5dea80
docs: docstrings and return types
sokovninn Sep 24, 2024
02c2d14
[Automated] Updated coverage badge
actions-user Sep 24, 2024
8625376
fix: remove axes in bbox visualization
sokovninn Sep 24, 2024
73686c0
tests: improve image generation tests
sokovninn Sep 24, 2024
41a1c6e
Merge branch 'refactor/tests-refactor' of https://github.com/luxonis/…
sokovninn Sep 24, 2024
4882a50
[Automated] Updated coverage badge
actions-user Sep 24, 2024
4efa316
docs: fix docstrings formatting
sokovninn Sep 25, 2024
9a70a97
fix: type hints
sokovninn Sep 25, 2024
46e944b
tests: replace default ubuntu runner with buildjet runner
sokovninn Sep 25, 2024
2639a9b
fix: type hint
sokovninn Sep 25, 2024
261e392
test: modify memory computation
sokovninn Sep 25, 2024
9e812e0
test: round up ram computation
sokovninn Sep 25, 2024
6a78e00
test: disable output capturing
sokovninn Sep 25, 2024
3de9306
test: decrease required ram for demanding tests
sokovninn Sep 25, 2024
a839a4a
test: 8vpcu buildjet runner
sokovninn Sep 25, 2024
6e43d3a
test: fix buildjet 8cpu runner
sokovninn Sep 25, 2024
005e3b8
test: fix 8vcpu buildjet
sokovninn Sep 25, 2024
9f3a538
test: divide tests into core and heavy
sokovninn Sep 27, 2024
153ac98
style: tests formatting
sokovninn Sep 27, 2024
280c954
test: rename core tests
sokovninn Sep 27, 2024
b2da07a
test: run core tests on pull to dev
sokovninn Sep 27, 2024
c4dae6e
test: fix config paths
sokovninn Sep 27, 2024
a256cbc
[Automated] Updated coverage badge
actions-user Sep 27, 2024
9504f93
test: update tests
sokovninn Sep 27, 2024
56cd741
Merge branch 'refactor/tests-refactor' of https://github.com/luxonis/…
sokovninn Sep 27, 2024
c16f5d7
[Automated] Updated coverage badge
actions-user Sep 27, 2024
ba9fb3b
test: run core tests on pr to main
sokovninn Sep 27, 2024
8de4fe9
test: rename heavy test scripts
sokovninn Sep 27, 2024
05b13be
Merge branch 'refactor/tests-refactor' of https://github.com/luxonis/…
sokovninn Sep 27, 2024
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
34 changes: 17 additions & 17 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,23 @@ name: Tests

on:
pull_request:
branches: [ dev, main ]
branches: [ main ]
paths:
- 'datadreamer/**/**.py'
- 'tests/**/**.py'
- 'tests/core_tests/**/**.py'
- .github/workflows/tests.yaml
workflow_dispatch:

jobs:
run_tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
os: [buildjet-8vcpu-ubuntu-2204, windows-latest, macOS-latest]
version: ['3.10', '3.11']
exclude:
- os: buildjet-8vcpu-ubuntu-2204
version: '3.11'

runs-on: ${{ matrix.os }}

Expand All @@ -31,56 +35,52 @@ jobs:
cache: pip

- name: Install dependencies [Ubuntu]
if: matrix.os == 'ubuntu-latest'
if: matrix.os == 'buildjet-8vcpu-ubuntu-2204'
run: |
sudo apt update
sudo apt install -y pandoc
pip install -e .[dev]
pip install coverage-badge>=1.1.0 pytest-cov>=4.1.0

- name: Install dependencies [Windows]
if: matrix.os == 'windows-latest'
run: |
pip install -e .[dev]
pip install coverage-badge>=1.1.0 pytest-cov>=4.1.0

- name: Install dependencies [macOS]
if: matrix.os == 'macOS-latest'
run: |
pip install -e .[dev]
pip install coverage-badge>=1.1.0 pytest-cov>=4.1.0

- name: Run tests with coverage [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10'
run: pytest tests --cov=datadreamer --cov-report xml --junit-xml pytest.xml
if: matrix.os == 'buildjet-8vcpu-ubuntu-2204' && matrix.version == '3.10'
run: pytest tests/core_tests --cov=datadreamer --cov-report xml --junit-xml pytest.xml

- name: Run tests [Windows, macOS]
if: matrix.os != 'ubuntu-latest' || matrix.version != '3.10'
run: pytest tests --junit-xml pytest.xml
if: matrix.os != 'buildjet-8vcpu-ubuntu-2204'
run: pytest tests/core_tests --junit-xml pytest.xml

- name: Generate coverage badge [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10'
if: matrix.os == 'buildjet-8vcpu-ubuntu-2204' && matrix.version == '3.10'
run: coverage-badge -o media/coverage_badge.svg -f

- name: Generate coverage report [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10'
if: matrix.os == 'buildjet-8vcpu-ubuntu-2204' && matrix.version == '3.10'
uses: orgoro/[email protected]
with:
coverageFile: coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}

- name: Commit coverage badge [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10'
if: matrix.os == 'buildjet-8vcpu-ubuntu-2204' && matrix.version == '3.10'
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git diff --quiet media/coverage_badge.svg || {
git add media/coverage_badge.svg
git commit -m "[Automated] Updated coverage badge"
}

- name: Push changes [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10'
if: matrix.os == 'buildjet-8vcpu-ubuntu-2204' && matrix.version == '3.10'
uses: ad-m/github-push-action@master
with:
branch: ${{ github.head_ref }}
Expand Down Expand Up @@ -117,4 +117,4 @@ jobs:
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: "artifacts/**/*.xml"
files: "artifacts/**/*.xml"
116 changes: 116 additions & 0 deletions .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
name: Unit tests

on:
pull_request:
branches: [ dev ]
paths:
- 'datadreamer/**/**.py'
- 'tests/core_tests/unittests/**.py'
- .github/workflows/unit-tests.yaml

jobs:
run_tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
version: ['3.10', '3.11']

runs-on: ${{ matrix.os }}

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.version }}
cache: pip

- name: Install dependencies [Ubuntu]
if: matrix.os == 'ubuntu-latest'
run: |
sudo apt update
sudo apt install -y pandoc
pip install -e .[dev]
pip install coverage-badge>=1.1.0 pytest-cov>=4.1.0
- name: Install dependencies [Windows]
if: matrix.os == 'windows-latest'
run: |
pip install -e .[dev]
pip install coverage-badge>=1.1.0 pytest-cov>=4.1.0
- name: Install dependencies [macOS]
if: matrix.os == 'macOS-latest'
run: |
pip install -e .[dev]
pip install coverage-badge>=1.1.0 pytest-cov>=4.1.0
- name: Run tests with coverage [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10'
run: pytest tests/core_tests/unittests --cov=datadreamer --cov-report xml --junit-xml pytest.xml

- name: Run tests [Windows, macOS]
if: matrix.os != 'ubuntu-latest' || matrix.version != '3.10'
run: pytest tests/core_tests/unittests --junit-xml pytest.xml

- name: Generate coverage badge [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10'
run: coverage-badge -o media/coverage_badge.svg -f

- name: Generate coverage report [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10'
uses: orgoro/[email protected]
with:
coverageFile: coverage.xml
token: ${{ secrets.GITHUB_TOKEN }}

- name: Commit coverage badge [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10'
run: |
git config --global user.name 'GitHub Actions'
git config --global user.email '[email protected]'
git diff --quiet media/coverage_badge.svg || {
git add media/coverage_badge.svg
git commit -m "[Automated] Updated coverage badge"
}
- name: Push changes [Ubuntu]
if: matrix.os == 'ubuntu-latest' && matrix.version == '3.10'
uses: ad-m/github-push-action@master
with:
branch: ${{ github.head_ref }}

- name: Upload Test Results
if: always()
uses: actions/upload-artifact@v4
with:
name: Test Results [${{ matrix.os }}] (Python ${{ matrix.version }})
path: pytest.xml
retention-days: 10
if-no-files-found: error

publish-test-results:
name: "Publish Tests Results"
needs: run_tests
runs-on: ubuntu-latest
permissions:
checks: write
pull-requests: write
if: always()

steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.head_ref }}

- name: Download Artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
with:
files: "artifacts/**/*.xml"
14 changes: 9 additions & 5 deletions datadreamer/dataset_annotation/clip_annotator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

from typing import List
import logging
from typing import Dict, List

import numpy as np
import PIL
Expand All @@ -10,6 +11,8 @@

from datadreamer.dataset_annotation.image_annotator import BaseAnnotator, TaskList

logger = logging.getLogger(__name__)


class CLIPAnnotator(BaseAnnotator):
"""A class for image annotation using the CLIP model, specializing in image
Expand Down Expand Up @@ -47,7 +50,7 @@ def __init__(
self.device = device
self.model.to(self.device)

def _init_processor(self):
def _init_processor(self) -> CLIPProcessor:
"""Initializes the CLIP processor.

Returns:
Expand All @@ -57,12 +60,13 @@ def _init_processor(self):
return CLIPProcessor.from_pretrained("openai/clip-vit-large-patch14")
return CLIPProcessor.from_pretrained("openai/clip-vit-base-patch32")

def _init_model(self):
def _init_model(self) -> CLIPModel:
"""Initializes the CLIP model.

Returns:
CLIPModel: The initialized CLIP model.
"""
logger.info(f"Initializing CLIP {self.size} model...")
if self.size == "large":
return CLIPModel.from_pretrained("openai/clip-vit-large-patch14")
return CLIPModel.from_pretrained("openai/clip-vit-base-patch32")
Expand All @@ -72,7 +76,7 @@ def annotate_batch(
images: List[PIL.Image.Image],
objects: List[str],
conf_threshold: float = 0.1,
synonym_dict: dict[str, List[str]] | None = None,
synonym_dict: Dict[str, List[str]] | None = None,
) -> List[np.ndarray]:
"""Annotates images using the OWLv2 model.

Expand All @@ -83,7 +87,7 @@ def annotate_batch(
synonym_dict (dict, optional): Dictionary for handling synonyms in labels. Defaults to None.

Returns:
List[List[int]]: A list of lists of labels for each image.
List[np.ndarray]: A list of the annotations for each image.
"""
if synonym_dict is not None:
objs_syn = set()
Expand Down
9 changes: 6 additions & 3 deletions datadreamer/dataset_annotation/image_annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
from abc import ABC, abstractmethod


# Enum for different labeling tasks
class TaskList(enum.Enum):
CLASSIFICATION = "classification"
OBJECT_DETECTION = "object_detection"
SEGMENTATION = "segmentation"
# Add more tasks as needed


# Abstract base class for data labeling
class BaseAnnotator(ABC):
"""Abstract base class for creating annotators.

Expand All @@ -24,6 +21,8 @@ class BaseAnnotator(ABC):
Methods:
annotate_batch(): Abstract method to be implemented by subclasses. It should contain
the logic for performing annotation based on the task definition.
release(): Abstract method to be implemented by subclasses. It should contain
the logic for releasing the resources used by the annotator.
"""

def __init__(
Expand All @@ -35,3 +34,7 @@ def __init__(
@abstractmethod
def annotate_batch(self):
pass

@abstractmethod
def release(self, empty_cuda_cache=False) -> None:
pass
Loading
Loading