Skip to main content

Machine Learning Extension for pyPhases

This Extension adds:

  • an Exporter for PyTorch and TensorFlow Models.
  • an Modelmanager that can handle PyTorch and TensorFlow Models

Documentation

📚 Complete Configuration Documentation - Comprehensive guide to all configuration options

🚀 Quick Reference Guide - Common patterns and minimal examples

📋 JSON Schema | YAML Schema - For validation and IDE support

🔧 Configuration Validator - Script to validate your configuration files

📖 Complete Example - Full configuration with all options

Setup

  • add pyPhasesML to your dependencies or run pip install -U pyPhasesML
  • add pyPhasesML to your plugins in the main project config f.e: in your project.yaml
name: bumpDetector
namespace: ibmt.tud

# load machine learning plugin
plugins:
  - pyPhasesML
  • you do not need to add the ModelExporter manually

Getting Started

Minimal Example

For a complete minimal example see, with loading data, training and evaluation see: https://gitlab.com/tud.ibmt.public/pyphases/pyphasesml-example-bumpdetector

Quick Start Configuration

Here's a minimal configuration to get started:

# Required configuration
modelPath: models/mymodels
modelName: MyCNN
inputShape: [16, 50]

classification:
  labelNames: [MyClassification]
  classNames:
    - [A, B]

trainingParameter:
  batchSize: 32

For more configuration options, see the complete example or documentation.

Configuration Validation

Validate your configuration files using the provided script:

# Validate a configuration file
python scripts/validate_config.py config.yaml

# Validate with verbose output
python scripts/validate_config.py --verbose config.yaml

# Use custom schema
python scripts/validate_config.py --schema custom-schema.json config.yaml

IDE Support

For better IDE support with autocompletion and validation:

  1. VS Code: Install the YAML extension and add this to your settings:
{
  "yaml.schemas": {
    "./schema/config-schema.json": ["**/config.yaml", "**/config.yml"]
  }
}
  1. PyCharm: Go to Settings → Languages & Frameworks → Schemas and DTDs → JSON Schema Mappings and add the schema file.

Configuration Examples

Basic Binary Classification

modelPath: models/binary
modelName: BinaryClassifier
inputShape: [32, 64]

classification:
  labelNames: [BinaryTask]
  classNames:
    - [Positive, Negative]

trainingParameter:
  batchSize: 64
  maxEpochs: 50
  learningRate: 0.001
  validationMetrics: ["acc", "auroc"]

Adding a PyTorch Model CNNPytorch

Create a class that is compatible with your modelPath and modelname. So in this example, we need a class CNNPytorch in the path models/mymodels/CNNPytorch.py relative to your root.

This class is required to:

  • inherit from ModelTorchAdapter:
  • populate the self.model with a valid PyTorch-Model, in the define method
  • return a valid loss function in the method getLossFunction
import torch.nn as nn

from pyPhasesML.adapter.ModelTorchAdapter import ModelTorchAdapter

class CNNPytorch(ModelTorchAdapter):
    def define(self):
        length, channelCount = self.inputShape
        numClasses = self.config.numClasses

        self.model = nn.Conv1d(
            in_channels=channelCount, 
            out_channels=self.config.numClasses,
            kernel_size=self.getOption("kernelSize"),
        )

    def getLossFunction(self):
        return torch.nn.MultiLabelSoftMarginLoss(reduction="mean", weight=self.weightTensors)

Load the model

In a phase you can simply use the ModelManager to get the Model and registerData to save the state. There is no dependency on pyTorch or TensorFlow in this example, so you swap your models dynamicly depending on your environment:

import numpy as np
from pathlib import Path

from pyPhases import Phase
from pyPhasesML import DatasetWrapXY, ModelManager, TrainingSet


class TestModel(Phase):
    def main(self):
        # loads the model depending on modelPath and modelName
        model = ModelManager.getModel()
        
        input = np.randn(20, 16, 50)        
        output = model(input)
        # save the model state
        self.project.registerData("modelState", model)

Configuration

  • test is assumed to be the first split (if not everything is set to manual splits)
  • combined splits: trainvaltest, trainval are possible
dataversion:
  split:
    test: 0:500
    validation: 500:1000
    training: 1000:1500

Metadata

Release files for pyPhasesML 0.22.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyPhasesML 0.22.1
File Size Uploaded Provenance Actions
pyphasesml-0.22.1.tar.gz 44.1 kB Without provenance Details for pyphasesml-0.22.1.tar.gz

Release files / pyphasesml-0.22.1.tar.gz

Download URL pyphasesml-0.22.1.tar.gz
Size 44.1 kB
Tags Source
SHA-256 checksum
How to use checksums
08239ada502f18b342b98de302db849f624d04a80c32820f946641bd26e2492d
BLAKE2b-256 checksum
How to use checksums
baea5dab3d25a49aec0de8c38b575fbb1d9f268464bf5fc5997f28618e860238
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for pyPhasesML 0.22.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.22.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page