segrails.result

Segrails result dataclasses.

Defines the structured output returned by the Segrails inference pipeline.

Classes

SegrailsError

Error descriptor returned when a pipeline step fails.

ModelInfo

Metadata about the model used during inference.

SegrailsPrediction

Detection results produced by the postprocessing step.

SegrailsResult

Top-level result returned by the Segrails pipeline.

Module Contents

class segrails.result.SegrailsError

Error descriptor returned when a pipeline step fails.

code

HTTP-style error code (e.g. 500 for an internal error).

message

Human-readable description of the error.

code: int
message: str
class segrails.result.ModelInfo

Metadata about the model used during inference.

name

Registered model name.

version

Registered model version.

model_path

Local path to the model checkpoint file.

name: str
version: str
model_path: str
class segrails.result.SegrailsPrediction

Detection results produced by the postprocessing step.

inference_time

Duration of the UNet inference in seconds.

n_tracks

Total number of track segments detected.

valid_tracks

Number of tracks classified as valid rail tracks.

crossings

Number of segments classified as rail crossings.

total_low_detections

Total count of detections with IoU below threshold.

total_missed_detections

Total count of track segments with no detection.

tracks

List of track dictionaries. Each entry contains id, classification, and a list of point dicts with coordinates, direction, IoU score and status.

inference_time: float = 0.0
n_tracks: int = 0
valid_tracks: int = 0
crossings: int = 0
total_low_detections: int = 0
total_missed_detections: int = 0
tracks: List[Dict[str, Any]] = []
class segrails.result.SegrailsResult

Top-level result returned by the Segrails pipeline.

status

Pipeline status. Either "success" or "failure".

timestamp

ISO 8601 UTC timestamp of when the pipeline ran.

model

Metadata about the model used. None if loading failed.

input

Optional dict describing the pipeline inputs (paths, center, …).

predictions

Detection results. None if inference or postprocessing failed.

error

Error descriptor. None when status is "success".

Example

>>> result = SegrailsResult(status="success", timestamp="2026-01-01T00:00:00Z")
>>> result.dump()
{'status': 'success', 'timestamp': '2026-01-01T00:00:00Z', ...}
status: Literal['success', 'failure']
timestamp: str
model: ModelInfo | None = None
input: Dict[str, Any] | None = None
predictions: SegrailsPrediction | None = None
error: SegrailsError | None = None
dump() Dict[str, Any]

Serialize the result to a plain dictionary.

Returns:

Fully serialized result, suitable for JSON export.

Return type:

Dict[str, Any]