본문으로 건너뛰기

Data Types

DataType defines semantic types for data flow between actions. When connecting actions in a pipeline, type compatibility is validated to prevent invalid data flows at construction time.

Overview

At a Glance

CategoryPurposeExamples
DatasetTraining and inference dataYOLODataset, COCODataset, DMv2Dataset
ModelModels and weightsModelWeights, ONNXModel, TensorRTModel
ResultExecution resultsTestResults, InferenceResults

Good to know: All types can be imported from synapse_sdk.plugins.types.

DataType Base Class

DataType is the base class for all semantic types. It provides type compatibility checking and metadata definitions.

class DataType:
"""Base class for action input/output type declarations."""

name: ClassVar[str] = 'data'
format: ClassVar[str | None] = None
description: ClassVar[str] = ''

@classmethod
def is_compatible_with(cls, other: type[DataType]) -> bool:
"""Check if this type is compatible with another type."""
return issubclass(cls, other) or issubclass(other, cls)

Class Attributes

AttributeTypeDescription
namestrUnique identifier for the type
formatstr | NoneData format (e.g., 'yolo', 'coco')
descriptionstrHuman-readable description

Dataset Types

Dataset types define data formats used for training and inference.

TypeNameFormatDescription
Datasetdataset-Generic dataset base type
DMDatasetdm_datasetdmDatamaker format dataset
DMv1Datasetdm_v1_datasetdm_v1Datamaker v1 format
DMv2Datasetdm_v2_datasetdm_v2Datamaker v2 format
YOLODatasetyolo_datasetyoloYOLO format with dataset.yaml
COCODatasetcoco_datasetcocoCOCO format
PascalVOCDatasetpascal_voc_datasetpascalPascal VOC format
from synapse_sdk.plugins.types import (
Dataset,
DMDataset,
DMv1Dataset,
DMv2Dataset,
YOLODataset,
COCODataset,
PascalVOCDataset,
)

Model Types

Model types define trained models and converted model formats.

TypeNameFormatDescription
Modelmodel-Generic model base type
ModelWeightsmodel_weightsweightsTrained model weights
ONNXModelonnx_modelonnxONNX format model
TensorRTModeltensorrt_modeltensorrtTensorRT format model
from synapse_sdk.plugins.types import (
Model,
ModelWeights,
ONNXModel,
TensorRTModel,
)

Result Types

Result types define categories of action execution results.

TypeNameFormatDescription
Resultresult-Generic result base type
TestResultstest_resultsmetricsTest/evaluation results with metrics
InferenceResultsinference_resultspredictionsInference predictions
from synapse_sdk.plugins.types import (
Result,
TestResults,
InferenceResults,
)

Type Compatibility

Type compatibility is checked using the is_compatible_with() method. Two types are compatible if they share an inheritance relationship.

Compatibility Rules

RuleDescriptionExample
Same classIdentical types are compatibleYOLODataset ↔ YOLODataset
SubclassSubtypes are compatible with parent typesYOLODataset ↔ Dataset
SiblingSibling types are incompatibleYOLODataset ✗ COCODataset
from synapse_sdk.plugins.types import Dataset, YOLODataset, COCODataset

# Same class - compatible
YOLODataset.is_compatible_with(YOLODataset) # True

# Subclass relationship - compatible
YOLODataset.is_compatible_with(Dataset) # True
Dataset.is_compatible_with(YOLODataset) # True

# Sibling classes - incompatible
YOLODataset.is_compatible_with(COCODataset) # False

Pipeline Validation

ActionPipeline automatically validates type compatibility between connected actions. The output_type of the previous action must be compatible with the input_type of the next action.

from synapse_sdk.plugins.pipelines import ActionPipeline

# Type validation occurs during pipeline creation
pipeline = ActionPipeline(
[DownloadAction, ConvertAction, TrainAction],
validate_schemas=True, # Enable schema validation
strict=True, # Raise error on incompatibility
)

Good to know: Set strict=False to emit warnings instead of errors on type mismatch.

Using Types in Actions

Declare input_type and output_type in action classes to specify what data types the action processes.

from synapse_sdk.plugins.action import BaseAction
from synapse_sdk.plugins.types import YOLODataset, ModelWeights
from pydantic import BaseModel


class TrainParams(BaseModel):
epochs: int = 10
batch_size: int = 32


class TrainResult(BaseModel):
weights_path: str
final_loss: float


class TrainAction(BaseAction[TrainParams]):
"""Training action with type declarations."""

input_type = YOLODataset # Expects YOLO format dataset
output_type = ModelWeights # Produces trained model weights
result_model = TrainResult

def execute(self) -> TrainResult:
# Training logic here
return TrainResult(
weights_path='/path/to/model.pt',
final_loss=0.05
)

Action with No Input Type

Actions that don't receive external input, like dataset downloads, set input_type = None.

from synapse_sdk.plugins.action import BaseAction
from synapse_sdk.plugins.types import YOLODataset


class DatasetAction(BaseAction[DatasetParams]):
"""Dataset download action."""

input_type = None # No input required
output_type = YOLODataset # Produces YOLO dataset

def execute(self) -> DatasetResult:
# Download and convert dataset
...

Type Hierarchy

Creating Custom Types

Define project-specific custom types by subclassing DataType or existing types.

from synapse_sdk.plugins.types import Dataset


class ImageDataset(Dataset):
"""Custom image dataset type."""

name = 'image_dataset'
format = 'images'
description = 'Raw image files in a directory'


class SegmentationDataset(ImageDataset):
"""Segmentation dataset with masks."""

name = 'segmentation_dataset'
format = 'segmentation'
description = 'Image dataset with segmentation masks'

Tip: Custom types that inherit from existing types are automatically compatible with their parent types.

Best Practices

  • Use specific types: Prefer YOLODataset over Dataset when the format is known
  • Enable pipeline validation: Set validate_schemas=True when using ActionPipeline
  • Inherit for custom types: Subclass existing types to maintain compatibility
  • Use the format field: Distinguish different formats within the same category using the format field