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

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyphasesml-0.21.5.tar.gz (36.9 kB view details)

Uploaded Source

File details

Details for the file pyphasesml-0.21.5.tar.gz.

File metadata

  • Download URL: pyphasesml-0.21.5.tar.gz
  • Upload date:
  • Size: 36.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.14

File hashes

Hashes for pyphasesml-0.21.5.tar.gz
Algorithm Hash digest
SHA256 68c6f1150079086dcaf8d44099db6cbadda3b3ac7ee74507489771dccc7969f9
MD5 45cd31039fe296677bbd781f90d048b1
BLAKE2b-256 2d57111d243e081bd448b686c695e4004566edd33a0be22821055ee215e5f73a

See more details on using hashes here.

Release history Release notifications | RSS feed

0.22.1

1 file

0.21.6

1 file

This release

0.21.5 This release

1 file

0.21.4

1 file

0.21.3

1 file

0.21.2

1 file

0.21.1

1 file

0.21.0

1 file

0.20.1

1 file

0.19.0

1 file

0.18.4

1 file

0.18.3

1 file

0.18.2

1 file

0.18.1

1 file

0.17.0

1 file

0.16.1

1 file

0.15.3

1 file

0.15.2

1 file

0.15.1

1 file

0.15.0

1 file

0.14.0

1 file

0.13.1

1 file

0.12.1

1 file

0.12.0

1 file

0.11.0

1 file

0.9.0

1 file

0.8.6

1 file

0.8.5

1 file

0.8.4

1 file

0.8.3

1 file

0.8.2

1 file

0.8.1

1 file

0.8.0

1 file

0.7.18

1 file

0.7.16

1 file

0.7.15

1 file

0.7.14

1 file

0.7.12

1 file

0.7.11

1 file

0.7.10

1 file

0.7.9

1 file

0.7.8

1 file

0.7.7

1 file

0.7.6

1 file

0.7.5

1 file

0.7.4

1 file

0.7.3

1 file

0.7.2

1 file

0.7.1

1 file

0.7.0

1 file

0.6.2

1 file

0.6.1

1 file

0.6.0

1 file

0.5.2

1 file

0.5.1

1 file

0.5.0

1 file

0.4.13

1 file

0.4.10

1 file

0.4.9

1 file

0.4.8

1 file

0.4.7

1 file

0.4.6

1 file

0.4.5

1 file

0.4.4

1 file

0.4.3

1 file

0.4.2

1 file

0.4.1

1 file

0.4.0

1 file

0.3.15

1 file

0.3.14

1 file

0.3.13

1 file

0.3.12

1 file

0.3.11

1 file

0.3.10

1 file

0.3.9

1 file

0.3.8

1 file

0.3.7

1 file

0.3.6

1 file

0.3.5

1 file

0.3.4

1 file

0.3.3

1 file

0.3.2

1 file

0.3.1

1 file

0.3.0

1 file

0.2.8

1 file

0.2.7

1 file

0.2.6

1 file

0.2.5

1 file

0.2.2

1 file

0.2.1

1 file

0.2.0

1 file

0.1.8

1 file

0.1.7

1 file

0.1.6

1 file

0.1.5

1 file

0.1.4

1 file

0.1.3

1 file

0.1.2

1 file

0.1.1

1 file

0.0.12

1 file

0.0.11

1 file

0.0.10

1 file

0.0.9

1 file

0.0.8

1 file

0.0.7

1 file

0.0.6

1 file

0.0.5

1 file

0.0.1

1 file

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