mridc.core.neural_types package

Submodules

mridc.core.neural_types.axes module

class mridc.core.neural_types.axes.AxisKind(value)[source]

Bases: AxisKindAbstract

This Enum represents what does varying axis dimension mean. For example, does this dimension correspond to width, batch, time, etc. The “Dimension” and “Channel” kinds are the same and used to represent a general axis. “Any” axis will accept any axis kind fed to it.

Any = 5
Batch = 0
Channel = 2
Dimension = 2
FlowGroup = 7
Height = 4
Sequence = 6
Singleton = 8
Time = 1
Width = 3
__repr__()[source]

Returns short string representation of the AxisKind

__str__()[source]

Returns short string representation of the AxisKind

static from_str(label)[source]

Returns AxisKind instance based on short string representation

t_with_string(text)[source]

It checks if text is ‘t_<any string>’

class mridc.core.neural_types.axes.AxisKindAbstract(value)[source]

Bases: Enum

This is an abstract Enum to represents what does varying axis dimension mean. In practice, you will almost always use AxisKind Enum. This Enum should be inherited by your OWN Enum if you aren’t satisfied with AxisKind. Then your own Enum can be used instead of AxisKind.

class mridc.core.neural_types.axes.AxisType(kind: AxisKindAbstract, size: Optional[int] = None, is_list=False)[source]

Bases: object

This class represents axis semantics and (optionally) it’s dimensionality

Parameters
  • kind (what kind of axis it is? For example Batch, Height, etc.) – AxisKindAbstract

  • size (specify if the axis should have a fixed size. By default, it is set to None and you typically do not want to) –

  • Time. (set it for Batch and) – (int, optional)

  • is_list (whether this is a list or a tensor axis.) – (bool, default=False)

__repr__()[source]

Returns short string representation of the AxisType

mridc.core.neural_types.comparison module

class mridc.core.neural_types.comparison.NeuralTypeComparisonResult(value)[source]

Bases: Enum

The result of comparing two neural type objects for compatibility. When comparing A.compare_to(B).

CONTAINER_SIZE_MISMATCH = 5
DIM_INCOMPATIBLE = 3
GREATER = 2
INCOMPATIBLE = 6
LESS = 1
SAME = 0
SAME_TYPE_INCOMPATIBLE_PARAMS = 7
TRANSPOSE_SAME = 4
UNCHECKED = 8

mridc.core.neural_types.elements module

class mridc.core.neural_types.elements.CategoricalValuesType[source]

Bases: PredictionsType

Element type to represent labels for categorical classification task

class mridc.core.neural_types.elements.ChannelType[source]

Bases: ElementType

Element to represent convolutional input/output channel.

class mridc.core.neural_types.elements.ElementType[source]

Bases: ABC

Abstract class defining semantics of the tensor elements. We are relying on Python for inheritance checking

__repr__()[source]

Override this method to provide a human readable representation of the type

__str__()[source]

Override this method to provide a human readable representation of the type

compare(second) NeuralTypeComparisonResult[source]

Override this method to provide a comparison between two types.

property fields: Optional[Tuple]

This should be used to logically represent tuples/structures. For example, if you want to represent a bounding box (x, y, width, height) you can put a tuple with names (‘x’, y’, ‘w’, ‘h’) in here. Under the hood this should be converted to the last tensor dimension of fixed size = len(fields). When two types are compared their fields must match.

property type_parameters: Dict

Override this property to parametrize your type. For example, you can specify ‘storage’ type such as float, int, bool with ‘dtype’ keyword. Another example, is if you want to represent a signal with a particular property (say, sample frequency), then you can put sample_freq->value in there. When two types are compared their type_parameters must match.”

class mridc.core.neural_types.elements.FloatType[source]

Bases: ElementType

Element type representing a single float

class mridc.core.neural_types.elements.ImageFeatureValue[source]

Bases: ImageValue

Type representing an element (single value) of a (image) feature maps.

class mridc.core.neural_types.elements.ImageValue[source]

Bases: ElementType

Type representing an element/value of a single image channel,

class mridc.core.neural_types.elements.Index[source]

Bases: ElementType

Type representing an element being an index of the sample.

class mridc.core.neural_types.elements.IntType[source]

Bases: ElementType

Element type representing a single integer

class mridc.core.neural_types.elements.LabelsType[source]

Bases: ElementType

Element type to represent labels of something. For example, labels of a dataset.

class mridc.core.neural_types.elements.Length[source]

Bases: IntType

Type representing an element storing a “length” (e.g. length of a list).

class mridc.core.neural_types.elements.LengthsType[source]

Bases: ElementType

Element type representing lengths of something

class mridc.core.neural_types.elements.LogDeterminantType[source]

Bases: ElementType

Element for representing log determinants usually used in flow models

class mridc.core.neural_types.elements.LogprobsType[source]

Bases: ElementType

Element type to represent log-probabilities. For example, outputs of log softmax layers.

class mridc.core.neural_types.elements.LossType[source]

Bases: ElementType

Element type to represent outputs of Loss modules

class mridc.core.neural_types.elements.MRISignal(freq: Optional[int] = None)[source]

Bases: ElementType

Element type to represent encoded representation returned by the mri model

Parameters

freq (sampling frequency of a signal. Note that two signals will only be the same if their freq is the same.) –

property type_parameters

Returns the type parameters of the element type.

class mridc.core.neural_types.elements.MaskType[source]

Bases: PredictionsType

Element type to represent a boolean mask

class mridc.core.neural_types.elements.NormalDistributionLogVarianceType[source]

Bases: ElementType

Element to represent the log variance of a normal distribution

class mridc.core.neural_types.elements.NormalDistributionMeanType[source]

Bases: ElementType

Element to represent the mean of a normal distribution

class mridc.core.neural_types.elements.NormalDistributionSamplesType[source]

Bases: ProbabilityDistributionSamplesType

Element to represent tensors that meant to be sampled from a valid normal distribution

class mridc.core.neural_types.elements.NormalizedImageValue[source]

Bases: ImageValue

Type representing an element/value of a single image channel normalized to <0-1> range.

class mridc.core.neural_types.elements.PredictionsType[source]

Bases: LabelsType

Element type to represent some sort of predictions returned by model

class mridc.core.neural_types.elements.ProbsType[source]

Bases: ElementType

Element type to represent probabilities. For example, outputs of softmax layers.

class mridc.core.neural_types.elements.ReconstructionTarget[source]

Bases: Target

Type representing an element being target value in the reconstruction task, i.e. identifier of a desired class.

class mridc.core.neural_types.elements.RecurrentsType[source]

Bases: ElementType

Element type to represent recurrent layers

class mridc.core.neural_types.elements.RegressionValuesType[source]

Bases: PredictionsType

Element type to represent labels for regression task

class mridc.core.neural_types.elements.SequenceToSequenceAlignmentType[source]

Bases: ElementType

Class to represent the alignment from seq-to-seq attention outputs. Generally a mapping from encoder time steps to decoder time steps.

class mridc.core.neural_types.elements.StringLabel[source]

Bases: StringType

Type representing a label being a string with class name (e.g. the “hamster” class in CIFAR100).

class mridc.core.neural_types.elements.StringType[source]

Bases: ElementType

Element type representing a single string

class mridc.core.neural_types.elements.Target[source]

Bases: ElementType

Type representing an element being a target value.

class mridc.core.neural_types.elements.VoidType[source]

Bases: ElementType

Void-like type which is compatible with everything. It is a good practice to use this type only as necessary. For example, when you need template-like functionality.

compare(second: ABCMeta) NeuralTypeComparisonResult[source]

Void type is compatible with everything.

mridc.core.neural_types.neural_type module

exception mridc.core.neural_types.neural_type.NeuralPortNameMismatchError(input_port_name)[source]

Bases: NeuralTypeError

Exception raised when neural module is called with incorrect port names.

exception mridc.core.neural_types.neural_type.NeuralPortNmTensorMismatchError(class_name, port_name, first_type, second_type, type_compatibility)[source]

Bases: NeuralTypeError

Exception raised when a port is fed with a NmTensor of incompatible type.

class mridc.core.neural_types.neural_type.NeuralType(axes: Optional[Tuple] = None, elements_type: ElementType = VoidType, optional=False)[source]

Bases: object

This is the main class which would represent neural type concept. It is used to represent the types of inputs and

outputs.

Parameters
  • axes (a tuple of AxisTypes objects representing the semantics of what varying each axis means. You can use a short,) – string-based form here. For example: (‘B’, ‘C’, ‘H’, ‘W’) would correspond to an NCHW format frequently used in computer vision. (‘B’, ‘T’, ‘D’) is frequently used for signal processing and means [batch, time, dimension/channel].

  • elements_type (an instance of ElementType class representing the semantics of what is stored inside the tensor.) –

  • example (For) –

  • optional (By default, this is false. If set to True, it would mean that input to the port of this type can be) –

  • optional.

__eq__(other)[source]

Checks if two NeuralTypes are equal.

__repr__()[source]

Returns string representation of NeuralType.

compare(second) NeuralTypeComparisonResult[source]

Performs neural type comparison of self with second. When you chain two modules’ inputs/outputs via __call__ method, this comparison will be called to ensure neural type compatibility.

compare_and_raise_error(parent_type_name, port_name, second_object)[source]

Method compares definition of one type with another and raises an error if not compatible.

exception mridc.core.neural_types.neural_type.NeuralTypeError[source]

Bases: Exception

Base class for neural type related exceptions.

Module contents