ModelIOConfigABC¶
tiatoolbox.models.engine.io_config.ModelIOConfigABC
- class ModelIOConfigABC(input_resolutions, patch_input_shape, stride_shape=None, output_resolutions=<factory>)[source]¶
Defines a data class for holding a deep learning model’s I/O information.
Enforcing such that following attributes must always be defined by the subclass.
- Parameters:
input_resolutions (list(dict)) – Resolution of each input head of model inference, must be in the same order as target model.forward().
patch_input_shape (
numpy.ndarray, list(int), tuple(int, int)) – Shape of the largest input in (height, width).stride_shape (
numpy.ndarray, list(int), tuple(int)) – Stride in (x, y) direction for patch extraction.output_resolutions (list(dict)) – Resolution of each output head from model inference, must be in the same order as target model.infer_batch().
- input_resolutions¶
Resolution of each input head of model inference, must be in the same order as target model.forward().
- patch_input_shape¶
Shape of the largest input in (height, width).
- Type:
numpy.ndarray, list(int), tuple(int, int)
- stride_shape¶
Stride in (x, y) direction for patch extraction.
- Type:
numpy.ndarray, list(int), tuple(int, int)
- output_resolutions¶
Resolution of each output head from model inference, must be in the same order as target model.infer_batch().
- highest_input_resolution¶
Highest resolution to process the image based on input and output resolutions. This helps to read the image at the optimal resolution and improves performance.
- Type:
Examples
>>> # Defining io for a base network and converting to baseline. >>> ioconfig = ModelIOConfigABC( ... input_resolutions=[{"units": "mpp", "resolution": 0.5}], ... output_resolutions=[{"units": "mpp", "resolution": 1.0}], ... patch_input_shape=(224, 224), ... stride_shape=(224, 224), ... ) >>> ioconfig = ioconfig.to_baseline()
Methods
Get the scaling factor from input resolutions.
Returns a new config object converted to baseline form.
Attributes
- static scale_to_highest(resolutions, units)[source]¶
Get the scaling factor from input resolutions.
This will convert resolutions to a scaling factor with respect to the highest resolution found in the input resolutions list. If a model requires images at multiple resolutions. This helps to read the image a single resolution. The image will be read at the highest required resolution and will be scaled for low resolution requirements using interpolation.
- Parameters:
- Returns:
A 1D array of scaling factors having the same length as resolutions.
- Return type:
Examples
>>> # Defining io for a base network and converting to baseline. >>> ioconfig = ModelIOConfigABC( ... input_resolutions=[ ... {"units": "mpp", "resolution": 0.25}, ... {"units": "mpp", "resolution": 0.5}, ... ], ... output_resolutions=[{"units": "mpp", "resolution": 1.0}], ... patch_input_shape=(224, 224), ... stride_shape=(224, 224), ... ) >>> ioconfig = ioconfig.scale_to_highest() ... array([1. , 0.5]) # output >>> >>> # Defining io for a base network and converting to baseline. >>> ioconfig = ModelIOConfigABC( ... input_resolutions=[ ... {"units": "mpp", "resolution": 0.5}, ... {"units": "mpp", "resolution": 0.25}, ... ], ... output_resolutions=[{"units": "mpp", "resolution": 1.0}], ... patch_input_shape=(224, 224), ... stride_shape=(224, 224), ... ) >>> ioconfig = ioconfig.scale_to_highest() ... array([0.5 , 1.]) # output
- to_baseline()[source]¶
Returns a new config object converted to baseline form.
This will return a new
ModelIOConfigABCwhere resolutions have been converted to baseline format with the highest possible resolution found in both input and output as reference.- Parameters:
self (ModelIOConfigABC)
- Return type: