WriterBlock

class imagepypelines.builtin_blocks.WriterBlock(output_dir, base_filename='image.png', return_type='filename')[source]

Bases: imagepypelines.core.block_subclasses.SimpleBlock

Block that operates as a system that saves single frames to a specified output directory.

this block will not impact dataflow through the pipeline and will return whatever images are passed into it

every new frame passed in will be saved in the following format:
output_dir/000001base_filename.png output_dir/000002base_filename.png output_dir/000003base_filename.png …
Parameters:
  • output_dir (str) – path to output directory that images will be saved to
  • base_filename (str) – default is ‘image.png’ filename common among all images, these will be incremented numerically with each new image saved

Attributes Summary

EXTANT

Methods Summary

after_process() (optional overload)function that runs after processing for optional functionality.
before_process(data, labels) generates output directories for each image in the batch
label(lbl) (optional overload)retrieves the label for this datum
label_strategy(labels) calls self.label for each datum and returns a list or Nonetype
process(datum) writes an image frame to the specificed directory
process_strategy(data) processes each datum using self.process and return list
rename(name) Renames this block to the given name
train(data[, labels]) (optional or required overload)trains the block.

Attributes Documentation

EXTANT = {}

Methods Documentation

after_process()[source]

(optional overload)function that runs after processing for optional functionality. intended for optional use as a cleanup function

Parameters:None
before_process(data, labels)[source]

generates output directories for each image in the batch

Parameters:
  • data (list) – list of images to save
  • labels (list) – labels for each image
Returns:

None

label(lbl)

(optional overload)retrieves the label for this datum

label_strategy(labels)

calls self.label for each datum and returns a list or Nonetype

process(datum)[source]

writes an image frame to the specificed directory

Parameters:datum (np.ndarray) – frame to be saved to the output_dir
Returns:
datum passed in if return_type == ‘datum’,
or the written filename if return_type == ‘filename’
Return type:ret (np.ndarray)
process_strategy(data)

processes each datum using self.process and return list

rename(name)

Renames this block to the given name

Parameters:name (str) – the new name for your Block
Returns:object reference to this block (self)
Return type:ip.Block

Note

unlike naming your block using the name parameter in instantiation, imagepypelines will not guarantee that this name will be unique. It is considered the user’s responsibility to determine that this will not cause problems in your pipeline.

train(data, labels=None)

(optional or required overload)trains the block. overloading is required if the ‘requires_training’ parameter is set to True

users are expected to save pertinent variables as instance variables

Parameters:
  • data (list) – list of datums to train on
  • labels (list,None) – corresponding label for each datum, None by default (for unsupervised systems)
Returns:

None