brails.processors.nfloors_detector.lib.efficientnet.utils module
This file contains helper functions for building the model and for loading model parameters. These helper functions are built to mirror those in the official TensorFlow implementation.
- class brails.processors.nfloors_detector.lib.efficientnet.utils.BlockArgs(kernel_size, num_repeat, input_filters, output_filters, expand_ratio, id_skip, stride, se_ratio)
Bases:
tuple
- expand_ratio
Alias for field number 4
- id_skip
Alias for field number 5
- input_filters
Alias for field number 2
- kernel_size
Alias for field number 0
- num_repeat
Alias for field number 1
- output_filters
Alias for field number 3
- se_ratio
Alias for field number 7
- stride
Alias for field number 6
- class brails.processors.nfloors_detector.lib.efficientnet.utils.BlockDecoder
Bases:
object
Block Decoder for readability, straight from the official TensorFlow repository
- static decode(string_list)
Decodes a list of string notations to specify blocks inside the network.
- Parameters:
string_list – a list of strings, each string is a notation of block
- Returns:
a list of BlockArgs namedtuples of block args
- static encode(blocks_args)
Encodes a list of BlockArgs to a list of strings.
- Parameters:
blocks_args – a list of BlockArgs namedtuples of block args
- Returns:
a list of strings, each string is a notation of block
- class brails.processors.nfloors_detector.lib.efficientnet.utils.Conv2dDynamicSamePadding(in_channels, out_channels, kernel_size, stride=1, dilation=1, groups=1, bias=True)
Bases:
Conv2d
2D Convolutions like TensorFlow, for a dynamic image size
- forward(x)
Define 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 brails.processors.nfloors_detector.lib.efficientnet.utils.GlobalParams(batch_norm_momentum, batch_norm_epsilon, dropout_rate, num_classes, width_coefficient, depth_coefficient, depth_divisor, min_depth, drop_connect_rate, image_size)
Bases:
tuple
- batch_norm_epsilon
Alias for field number 1
- batch_norm_momentum
Alias for field number 0
- depth_coefficient
Alias for field number 5
- depth_divisor
Alias for field number 6
- drop_connect_rate
Alias for field number 8
- dropout_rate
Alias for field number 2
- image_size
Alias for field number 9
- min_depth
Alias for field number 7
- num_classes
Alias for field number 3
- width_coefficient
Alias for field number 4
- class brails.processors.nfloors_detector.lib.efficientnet.utils.Identity
Bases:
Module
- forward(input)
Define 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 brails.processors.nfloors_detector.lib.efficientnet.utils.MemoryEfficientSwish(*args, **kwargs)
Bases:
Module
- forward(x)
Define 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 brails.processors.nfloors_detector.lib.efficientnet.utils.Swish(*args, **kwargs)
Bases:
Module
- forward(x)
Define 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 brails.processors.nfloors_detector.lib.efficientnet.utils.SwishImplementation(*args, **kwargs)
Bases:
Function
- static backward(ctx, grad_output)
Define a formula for differentiating the operation with backward mode automatic differentiation.
This function is to be overridden by all subclasses. (Defining this function is equivalent to defining the
vjp
function.)It must accept a context
ctx
as the first argument, followed by as many outputs as theforward()
returned (None will be passed in for non tensor outputs of the forward function), and it should return as many tensors, as there were inputs toforward()
. Each argument is the gradient w.r.t the given output, and each returned value should be the gradient w.r.t. the corresponding input. If an input is not a Tensor or is a Tensor not requiring grads, you can just pass None as a gradient for that input.The context can be used to retrieve tensors saved during the forward pass. It also has an attribute
ctx.needs_input_grad
as a tuple of booleans representing whether each input needs gradient. E.g.,backward()
will havectx.needs_input_grad[0] = True
if the first input toforward()
needs gradient computed w.r.t. the output.
- static forward(ctx, i)
Define the forward of the custom autograd Function.
This function is to be overridden by all subclasses. There are two ways to define forward:
Usage 1 (Combined forward and ctx):
@staticmethod def forward(ctx: Any, *args: Any, **kwargs: Any) -> Any: pass
It must accept a context ctx as the first argument, followed by any number of arguments (tensors or other types).
See combining-forward-context for more details
Usage 2 (Separate forward and ctx):
@staticmethod def forward(*args: Any, **kwargs: Any) -> Any: pass @staticmethod def setup_context(ctx: Any, inputs: Tuple[Any, ...], output: Any) -> None: pass
The forward no longer accepts a ctx argument.
Instead, you must also override the
torch.autograd.Function.setup_context()
staticmethod to handle setting up thectx
object.output
is the output of the forward,inputs
are a Tuple of inputs to the forward.See extending-autograd for more details
The context can be used to store arbitrary data that can be then retrieved during the backward pass. Tensors should not be stored directly on ctx (though this is not currently enforced for backward compatibility). Instead, tensors should be saved either with
ctx.save_for_backward()
if they are intended to be used inbackward
(equivalently,vjp
) orctx.save_for_forward()
if they are intended to be used for injvp
.
- brails.processors.nfloors_detector.lib.efficientnet.utils.drop_connect(inputs, p, training)
Drop connect.
- brails.processors.nfloors_detector.lib.efficientnet.utils.efficientnet(width_coefficient=None, depth_coefficient=None, dropout_rate=0.2, drop_connect_rate=0.2, image_size=None, num_classes=1000)
Creates a efficientnet model.
- brails.processors.nfloors_detector.lib.efficientnet.utils.efficientnet_params(model_name)
Map EfficientNet model name to parameter coefficients.
- brails.processors.nfloors_detector.lib.efficientnet.utils.get_model_params(model_name, override_params)
Get the block args and global params for a given model
- brails.processors.nfloors_detector.lib.efficientnet.utils.get_same_padding_conv2d(image_size=None)
Chooses static padding if you have specified an image size, and dynamic padding otherwise. Static padding is necessary for ONNX exporting of models.
- brails.processors.nfloors_detector.lib.efficientnet.utils.load_pretrained_weights(model, model_name, load_fc=True, advprop=False)
Loads pretrained weights, and downloads if loading for the first time.
- brails.processors.nfloors_detector.lib.efficientnet.utils.round_filters(filters, global_params)
Calculate and round number of filters based on depth multiplier.
- brails.processors.nfloors_detector.lib.efficientnet.utils.round_repeats(repeats, global_params)
Round number of filters based on depth multiplier.