BatchIterator#

from wholeslidedata.iterators import create_batch_iterator
from wholeslidedata.visualization.plotting import plot_batch
from dicfg.magics import ConfigMagics

# This will allow loading yaml in an notebook cell
ConfigMagics.register_magics()

User config#

Configuring the BatchIterator of wholeslidedata requires a configuration file. While most settings have default values that can be overridden, the data, labels, and batch shape settings must be provided by the user. In the example below, we illustrate how to set these parameters using a YAML configuration file. This YAML file is automatically converted into a Python dictionary called “user_config” using the “yaml” magic function. It is important to note that “user_config” can also be a path to a YAML/JSON file or a pre-existing Python dictionary.

%%yaml user_config 

wholeslidedata:
    default:
        yaml_source:
            training:
            -   wsi: 
                    path: /tmp/TCGA-21-5784-01Z-00-DX1.tif
                wsa: 
                    path: /tmp/TCGA-21-5784-01Z-00-DX1.xml
                        
        labels:
            stroma: 1
            tumor: 2
            lymphocytes: 3
            
        batch_shape:
            batch_size: 4
            spacing: 1.0
            shape: [512, 512, 3]

See also

  • For more information about the mode, please see the user guide about modes

  • For an explanation about the user_config please see the batchiterator configuration

Creating a Batch Iterator#

with create_batch_iterator(user_config=user_config, 
                            mode='training') as training_batch_generator:
    
    x_batch, y_batch, info =  next(training_batch_generator)
    plot_batch(x_batch, y_batch)
../../../_images/a550008faea7766731b8740e21d099c2c6f07ce85de2e8b2ec9b4ca7dafaa8ce.png

See also

For more advanced initialization settings of the batch iterator please see the initialize batch iterator user guide