A Framework for creating a boilerplate template for ai projects that are ready for MLOps
Project description
Machine Learning Extension for pyPhases
This Extension adds:
- an Exporter for
PyTorchandTensorFlowModels. - an Modelmanager that can handle
PyTorchandTensorFlowModels
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
pyPhasesMLto your plugins in the main project config f.e: in yourproject.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:
- VS Code: Install the YAML extension and add this to your settings:
{
"yaml.schemas": {
"./schema/config-schema.json": ["**/config.yaml", "**/config.yml"]
}
}
- 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.modelwith a valid PyTorch-Model, in thedefinemethod - 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file pyphasesml-0.21.2.tar.gz.
File metadata
- Download URL: pyphasesml-0.21.2.tar.gz
- Upload date:
- Size: 36.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2504d15c57b2ebed0e4879b1020098cdb77be4ac481a5c2f159a1e2f51245551
|
|
| MD5 |
b787d3ab65404b523fca13cf85c7f87d
|
|
| BLAKE2b-256 |
673667ce6f9d0824ac2990ad0801bb87c72bdced3ecc058972d78a69f433df7d
|