Skip to content
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
82 changes: 64 additions & 18 deletions .github/workflows/build_test_wheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,88 @@ jobs:

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v3
- name: Cache conda packages
id: conda-cache
uses: actions/cache@v4
with:
python-version: '3.11'
- name: Add conda to system path
run: |
# $CONDA is an environment variable pointing to the root of the miniconda directory
echo $CONDA/bin >> $GITHUB_PATH
path: /home/runner/miniconda3/pkgs
key: ${{ runner.os }}-conda-${{ hashFiles('environment-ci.yml') }}
restore-keys: |
${{ runner.os }}-conda-
- name: Set up conda
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Miniforge3
miniforge-version: latest
environment-file: environment-ci.yml
activate-environment: autoforge
installation-dir: /home/runner/miniconda3
auto-activate-base: false
pkgs-dirs: /home/runner/miniconda3/pkgs
use-mamba: true
use-only-tar-bz2: true
- name: Install dependencies
run: |
#conda env update --file environment.yml --name base
pip install .
"${CONDA}/bin/conda" run -n autoforge python -m pip install .
verify-lint:
runs-on: ubuntu-latest
needs: build-package
steps:
- uses: actions/checkout@v4
- name: Cache conda packages
id: conda-cache
uses: actions/cache@v4
with:
path: /home/runner/miniconda3/pkgs
key: ${{ runner.os }}-conda-${{ hashFiles('environment-ci.yml') }}
restore-keys: |
${{ runner.os }}-conda-
- name: Set up conda
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Miniforge3
miniforge-version: latest
environment-file: environment-ci.yml
activate-environment: autoforge
installation-dir: /home/runner/miniconda3
auto-activate-base: false
pkgs-dirs: /home/runner/miniconda3/pkgs
use-mamba: true
use-only-tar-bz2: true
- name: Lint with flake8
run: |
conda install flake8
conda init
conda activate base
"${CONDA}/bin/conda" run -n autoforge python -m pip install flake8
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
"${CONDA}/bin/conda" run -n autoforge flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
"${CONDA}/bin/conda" run -n autoforge flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
test-package:
runs-on: ubuntu-latest
needs: build-package
steps:
- uses: actions/checkout@v4
- name: Cache conda packages
id: conda-cache
uses: actions/cache@v4
with:
path: /home/runner/miniconda3/pkgs
key: ${{ runner.os }}-conda-${{ hashFiles('environment-ci.yml') }}
restore-keys: |
${{ runner.os }}-conda-
- name: Set up conda
uses: conda-incubator/setup-miniconda@v3
with:
miniforge-variant: Miniforge3
miniforge-version: latest
environment-file: environment-ci.yml
activate-environment: autoforge
installation-dir: /home/runner/miniconda3
auto-activate-base: false
pkgs-dirs: /home/runner/miniconda3/pkgs
use-mamba: true
use-only-tar-bz2: true
- name: Test with pytest
run: |
conda install pytest
conda init
conda activate base
pytest # TODO add specifications of test
"${CONDA}/bin/conda" run -n autoforge python -m pytest # TODO add specifications of test


3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -170,3 +170,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.vscode/browse.vc.db
.vscode/browse.vc.db-shm
.vscode/browse.vc.db-wal
20 changes: 20 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"configurations": [
{
"browse": {
"databaseFilename": "${workspaceFolder}/.vscode/browse.vc.db",
"limitSymbolsToIncludedHeaders": false
},
"includePath": [
"/opt/ros/jazzy/include/**",
"/usr/include/**"
],
"name": "ros2",
"intelliSenseMode": "gcc-x64",
"compilerPath": "/usr/bin/gcc",
"cStandard": "gnu11",
"cppStandard": "c++17"
}
],
"version": 4
}
1 change: 1 addition & 0 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
- [ ] Review and unit test selection criteria implementation
- [ ] Extend augs-trainer integration to allow "discard" option in validation module
- [x] Implement tailoring of RandomAffine to make it border crossing aware
- [ ] Migrate documentation from Read The Docs to something more controllable and less restrictive

- [ ] v0.3.X
- [x] Implement custom adaptive pooling layers for ONNx static export
Expand Down
9 changes: 9 additions & 0 deletions environment-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: autoforge
channels:
- conda-forge
- defaults
dependencies:
- python=3.11
- pip
- setuptools
- wheel
1 change: 0 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ dependencies:
- pyasn1-modules==0.4.1
- pybind11==2.13.6
- pycparser==2.22
- pycuda==2025.1
- pydantic==2.10.6
- pydantic-core==2.27.2
- pygments==2.19.1
Expand Down
10 changes: 9 additions & 1 deletion pyTorchAutoForge.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,13 @@
"path": "../ml-based-centroiding"
}
],
"settings": {}
"settings": {
"ROS2.distro": "jazzy",
"python.autoComplete.extraPaths": [
"/opt/ros/jazzy/lib/python3.12/site-packages"
],
"python.analysis.extraPaths": [
"/opt/ros/jazzy/lib/python3.12/site-packages"
]
}
}
3 changes: 1 addition & 2 deletions pyTorchAutoForge/api/tensorrt/TRTengineExporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import torch
import numpy as np
import sys, os, shutil
import pycuda as cuda
import subprocess
from enum import Enum
from pyTorchAutoForge.api.onnx import ModelHandlerONNx
Expand Down Expand Up @@ -167,4 +166,4 @@ def build_engine_from_onnx(self, input_onnx_model: str | None = None, output_eng
print("Engine built successfully and saved to:", output_engine_path)

else:
raise ValueError("Invalid TRTengineExporterMode value. Please select TRTEXEC or PYTHON.")
raise ValueError("Invalid TRTengineExporterMode value. Please select TRTEXEC or PYTHON.")
10 changes: 8 additions & 2 deletions pyTorchAutoForge/datasets/LabelsClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class PTAF_Datakey(enum.Enum):
PHASE_ANGLE = 9 # Phase angle of the scene
CENTRE_OF_FIGURE = 10 # Centre of figure of the object
APPARENT_SIZE = 11 # Apparent size of the object in pixels
SUN_DIRECTION_ANGLE_FROM_X = 12 # Angle of the sun direction from the x-axis in radians


def get_lbl_vector_size(self):
# Define sizes for data keys
Expand All @@ -49,7 +51,8 @@ def get_lbl_vector_size(self):
PTAF_Datakey.REFERENCE_SIZE: 1,
PTAF_Datakey.PHASE_ANGLE: 1,
PTAF_Datakey.CENTRE_OF_FIGURE: 2, # x, y coordinates of the centre of figure
PTAF_Datakey.APPARENT_SIZE: 1 # Apparent size in pixels
PTAF_Datakey.APPARENT_SIZE: 1, # Apparent size in pixels
PTAF_Datakey.SUN_DIRECTION_ANGLE_FROM_X: 1 # Angle of the sun direction from the x-axis in radians
}

return sizes.get(self, None)
Expand Down Expand Up @@ -235,7 +238,7 @@ class AuxiliaryLabels(BaseLabelsContainer):
default=-1.0, metadata={'yaml': 'dPhaseAngleInDeg'})

light_direction_rad_angle_from_x: float = field(
default=0.0, metadata={'yaml': 'dLightDirectionRadAngleFromX'})
default=-1.0, metadata={'yaml': 'dLightDirectionRadAngleFromX'})

object_shape_matrix_cam_frame: list[list[float]] = field(
default_factory=list, metadata={'yaml': 'dObjectShapeMatrix_CamFrame'})
Expand Down Expand Up @@ -311,6 +314,9 @@ def __getattr__(self, item: str) -> Any:

elif item == PTAF_Datakey.APPARENT_SIZE:
return float(self.geometric.obj_apparent_size_in_pix)

elif item == PTAF_Datakey.SUN_DIRECTION_ANGLE_FROM_X:
return float(self.auxiliary.light_direction_rad_angle_from_x)

else:
# Raise AttributeError to maintain standard behavior
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class FeatureExtractorConfig(BaseConfigClass):
# Dimension of the final linear layer (if you want to add a linear layer)
output_size: int | None = None
remove_classifier: bool = True
remove_gap_layer: bool = False
device: torch.device | str | None = None
input_channels: int = 3 # Placeholder value

Expand Down
13 changes: 11 additions & 2 deletions pyTorchAutoForge/model_building/backbones/efficient_net.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import torch
import torch.nn.functional as F
import warnings
from pyTorchAutoForge.model_building.backbones.spatial_features_operators import SpatialKptFeatureSoftmaxLocator
from pyTorchAutoForge.model_building.poolingBlocks import CustomAdaptiveMaxPool2d

Expand All @@ -22,7 +23,13 @@ def __init__(self, cfg: EfficientNetConfig):

# Extract the “features” part all children except the final classifier/sequential
modules = list(model.children())[:-1]

if cfg.output_type == 'last':

if hasattr(cfg, 'remove_gap_layer'):
# Remove the final global average pooling layer (AdaptiveAvgPool2d) if specified in config
modules = modules[0] if isinstance(modules[-1], nn.AdaptiveAvgPool2d) and cfg.remove_gap_layer else modules

# Wrap as a single ModuleList so that forward is simple
self.feature_extractor = nn.ModuleList([nn.Sequential(*modules)])

Expand All @@ -35,8 +42,10 @@ def __init__(self, cfg: EfficientNetConfig):
self.feature_extractor = nn.ModuleList(
list(feature_extractor_modules.children()))

# Add last layer (global adaptive pooling) from modules
self.feature_extractor.append(modules[1])
# Add last layer (global adaptive pooling) from modules if not removed
if hasattr(cfg, 'remove_gap_layer'):
if isinstance(modules[-1], nn.AdaptiveAvgPool2d) and not(cfg.remove_gap_layer):
self.feature_extractor.append(modules[-1])

# Build average pooling layer
self.feature_spill_preprocessor = nn.ModuleDict()
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ classifiers=[
[project.optional-dependencies]
cuda_all = [
"pynvml; platform_machine == 'x86_64'",
"pycuda; platform_machine == 'x86_64'",
]

[tool.setuptools.packages.find]
Expand Down
Loading
Loading