Models

Feature Extractors

Basic Conv Nets

class topaz.model.features.basic.BasicConv(layers, units, unit_scaling=1, dropout=0, bn=True, pooling=None, activation=<class 'torch.nn.modules.activation.PReLU'>)

A generic convolutional neural network scaffold.

fill(stride=1)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
unfill()
class topaz.model.features.basic.Conv127(units, **kwargs)
training: bool
class topaz.model.features.basic.Conv63(units, **kwargs)
training: bool

DenseNets

class topaz.model.features.densenet.DenseBlock(nin, ng)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class topaz.model.features.densenet.DenseLayer(nin, ng, bn_size=4, dilation=1, dropout=0, bn=True)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class topaz.model.features.densenet.DenseNet(init_units=64, ng=32, bn_size=4, fc_units=1000, num_layers=12, dropout=0, bn=True)
fill(stride=1)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
unfill()
class topaz.model.features.densenet.MultiscaleDenseNet(base_units=64, ng=48, num_blocks=4)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

MSNets

class topaz.model.features.msnet.DenseBlock(nin, ng)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class topaz.model.features.msnet.DenseLayer(nin, ng, bn_size=4, dilation=1, dropout=0, bn=True)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

class topaz.model.features.msnet.DenseNet(init_units=64, ng=32, bn_size=4, fc_units=1000, num_layers=12, dropout=0, bn=True)
fill(stride=1)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
unfill()
class topaz.model.features.msnet.MultiscaleDenseNet(base_units=64, ng=48, num_blocks=4)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class topaz.model.features.msnet.PyramidNet(base_units=64, scales=[2, 4, 8, 16], pooling='max')
fill(*args, **kwargs)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
unfill(*args, **kwargs)
class topaz.model.features.msnet.RMSNet10(units=[64, 64, 128, 128, 256])
fill(*args, **kwargs)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
unfill(*args, **kwargs)
class topaz.model.features.msnet.RMSNet7(units=[64, 64, 128, 128, 256])
fill(*args, **kwargs)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
unfill(*args, **kwargs)
class topaz.model.features.msnet.ResidMultiScaleBlock(nin, ng, nout, scales=[1, 2, 4], pooling='max', padding=False)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
class topaz.model.features.msnet.ResidMultiScaleNet(units=[64, 64, 64, 128, 128, 128, 128, 128, 128, 256, 256, 256], scales=[1, 2, 4])
fill(*args, **kwargs)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool
unfill(*args, **kwargs)

ResNets

class topaz.model.features.resnet.BasicConv2d(nin, nout, kernel_size, dilation=1, stride=1, bn=False, activation=<class 'torch.nn.modules.activation.ReLU'>)
fill(stride)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

set_padding(pad)
training: bool
unfill()
class topaz.model.features.resnet.MaxPool(kernel_size, stride=1)
fill(stride)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

set_padding(pad)
training: bool
unfill()
class topaz.model.features.resnet.ResNet(*args, **kwargs)
fill(stride=1)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

set_padding(pad)
training: bool
unfill()
class topaz.model.features.resnet.ResNet16(*args, **kwargs)
make_modules(units=[32, 64, 128], bn=True, dropout=0.0, activation=<class 'torch.nn.modules.activation.ReLU'>, pooling=None, **kwargs)
training: bool
class topaz.model.features.resnet.ResNet6(*args, **kwargs)
make_modules(units=[32, 64, 128], bn=True, dropout=0.0, activation=<class 'torch.nn.modules.activation.ReLU'>, **kwargs)
training: bool
class topaz.model.features.resnet.ResNet8(*args, **kwargs)
make_modules(units=[32, 64, 128], bn=True, dropout=0.0, activation=<class 'torch.nn.modules.activation.ReLU'>, pooling=None, **kwargs)
training: bool
class topaz.model.features.resnet.ResidA(nin, nhidden, nout, dilation=1, stride=1, activation=<class 'torch.nn.modules.activation.ReLU'>, bn=False)
fill(stride)
forward(x)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

set_padding(pad)
training: bool
unfill()

Linear Classifier

class topaz.model.classifier.LinearClassifier(features)

A simple convolutional layer without non-linear activation.

fill(stride=1)
forward(x)

Applies the classifier to an input.

Parameters

x (np.ndarray) – the image from which features are extracted and classified

Returns

output of the classifer

Return type

z (np.ndarray)

property latent_dim
training: bool
unfill()
property width

Model Factory

topaz.model.factory.conv127(*args, **kwargs)
topaz.model.factory.conv31(*args, **kwargs)
topaz.model.factory.conv63(*args, **kwargs)
topaz.model.factory.get_feature_extractor(model, *args, **kwargs)
topaz.model.factory.load_model(path)

Model Generator

class topaz.model.generative.ConvGenerator(nin, units=32, depth=3, activation=<class 'torch.nn.modules.activation.LeakyReLU'>)
forward(z)

Defines the computation performed at every call.

Should be overridden by all subclasses.

Note

Although the recipe for forward pass needs to be defined within this function, one should call the Module instance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.

training: bool

Model Utilities

topaz.model.utils.insize_from_outsize(layers, outsize)

calculates in input size of a convolution stack given the layers and output size