pyhealth.processors.TensorProcessor#
Processor for tensor data.
- class pyhealth.processors.TensorProcessor(dtype=torch.float32, spatial_dims=None)[source]#
Bases:
FeatureProcessorFeature processor for converting numerical lists to tensors.
- Input:
List of numbers (int/float) or nested lists of numbers
- Processing:
Convert input directly to torch.Tensor using torch.tensor()
- Output:
torch.Tensor with appropriate shape and dtype
- process(value)[source]#
Process a numerical value or list into a torch.Tensor.
- Parameters:
value (
Any) – Input value (list of numbers or nested lists)- Returns:
Processed tensor
- Return type:
torch.Tensor
- size()[source]#
Get the feature size of the processor.
- Returns:
Size is not predetermined for tensor processor
- Return type:
None
- is_token()[source]#
Whether the output tensor represents discrete token indices, inferred from dtype.
- Return type:
- Returns:
True if dtype is integer (discrete tokens), False if floating point (continuous).
- schema()[source]#
Returns the schema of the processed feature. For a processor that emits a single tensor, this should just return [“value”]. For a processor that emits a tuple of tensors, this should return a tuple of the same length as the tuple, with the semantic name of each tensor, such as [“time”, “value”], [“value”, “mask”], etc.
- Typical semantic names include:
“value”: the main processed tensor output of the processor
“time”: the time tensor output of the processor (mostly for StageNet)
“mask”: the mask tensor output of the processor (if applicable)
- dim()[source]#
Number of dimensions for the output tensor.
- Return type:
- Returns:
(n_dim,)
- Raises:
NotImplementedError – If n_dim was not provided and fit() was not called.
- spatial()[source]#
Whether each dimension of the output tensor is spatial.
If spatial_dims was provided at init, returns that. Otherwise defaults to all False based on n_dim.
- load(path)#
Optional: Load processor state from disk.