nirs4all.controllers.models.tensorflow.data_prep module

TensorFlow Data Preparation

This module handles TensorFlow-specific data preparation and tensor formatting.

class nirs4all.controllers.models.tensorflow.data_prep.TensorFlowDataPreparation[source]

Bases: object

Handles TensorFlow-specific data preparation and reshaping.

static prepare_data(X: ndarray, y: ndarray | None, context: Any = None) Tuple[ndarray, ndarray | None][source]

Prepare both features and targets for TensorFlow.

Parameters:
  • X – Input features array.

  • y – Target values array (optional).

  • context – Execution context (currently unused but kept for interface compatibility).

Returns:

Tuple of (prepared_X, prepared_y).

static prepare_features(X: ndarray) ndarray[source]

Prepare features for TensorFlow (proper tensor formatting).

Handles conversion to float32 and proper shape formatting: - 2D: (samples, features) -> reshape to (samples, features, 1) for Conv1D - 3D: Only transpose if needed (channels < features), ensuring Conv1D gets (samples, timesteps, channels)

Parameters:

X – Input features array.

Returns:

Prepared features array in float32.

static prepare_targets(y: ndarray | None) ndarray | None[source]

Prepare targets for TensorFlow.

Converts to float32 and flattens if needed.

Parameters:

y – Target values array (optional).

Returns:

Prepared targets array in float32, or None if input was None.