Model Utils#

class ModelReconstructor(feature_extractor, classifier, connection_fn=None)[source]#

reconstructs a model out of a feature_extractor and a classifier.

Parameters
  • feature_extractor (Module) -- feature-extractor module

  • classifier (Module) -- classifier module

  • connection_fn (Callable, optional) -- optional connection function to apply on the output of feature-extractor before feeding to the classifier. Defaults to None.

forward(input)[source]#

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#
get_output_size(in_size, pad, kernel, stride)[source]#

Calculates the output size after applying a kernel (for one dimension).

Parameters
  • in_size (int) -- input size.

  • pad (int) -- padding size. If set to same, input size is directly returned.

  • kernel (int) -- kernel size.

  • stride (int) -- size of strides.

Returns

int -- output size