PretrainedNetwork

class imagepypelines.builtin_blocks.PretrainedNetwork(network='densenet121', pooling_type='avg')[source]

Bases: imagepypelines.core.block_subclasses.BatchBlock

Block to extract features from pretrained neural networks

pretrained networks are trained on imagenet with pooling applied.

if grayscale images are passed into this network, they will be converted to RGB (this is required for features to be extracted from a network).

This class utilizes keras to automatically leverage hardware resources and retrieve pretrained networks. available networks are: - xception - vgg16 - vgg19 - resnet50 - inception_v3 - inception_resnet_v2 - mobilenet - densenet121 - densenet169 - densenet201 - nasnetlarge - nasnetmobile - mobilenetv2 see: https://keras.io/applications/ for more details kwargs for network instantiation are: - include_top = False, - weights = ‘imagenet’, - pooling = self.pooling_type

Parameters:
  • network_name (str) – name of network to extract features from Default is ‘densenet121’
  • pooling_type (str) – the type of pooling to perform on the features, must be one of [‘max’,’avg’]. Default is ‘avg’
network_name

name of network to extract features from Default is ‘densenet121’

Type:str
pooling_type

the type of pooling to perform on the features, must be one of [‘max’,’avg’]. Default is ‘avg’

Type:str
model_fn

function to generate features on an image stack

Type:callable
preprocess_fn

function to preprocess an image stack

Type:callable
io_map

object that maps inputs to this block to outputs

Type:IoMap
name

unique name for this block

Type:str
requires_training

whether or not this block will require training

Type:bool
trained

whether or not this block has been trained, True by default if requires_training = False

Type:bool
printer

printer object for this block, registered to ‘name’

Type:ip.Printer

Attributes Summary

EXTANT

Methods Summary

after_process() (optional overload)function that runs after processing for optional functionality.
batch_process(batch_data[, batch_labels]) (required overload)processes a list of data using this block’s algorithm
before_process(data[, labels]) (optional overload)function that runs before processing for optional functionality.
label_strategy(labels) runs self.labels
labels(labels) (optional overload) returns all labels for input datums or None
process_strategy(data) runs self.batch_process
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()

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

Parameters:None
batch_process(batch_data, batch_labels=None)[source]

(required overload)processes a list of data using this block’s algorithm

Parameters:data (list) – list of datums to process
Returns:list of processed datums
Return type:process(list)
before_process(data, labels=None)

(optional overload)function that runs before processing for optional functionality. this function takes in the full data list and label list. does nothing unless overloaded

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

runs self.labels

labels(labels)

(optional overload) returns all labels for input datums or None

process_strategy(data)

runs self.batch_process

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