geowatch.tasks.fusion.methods.efficientdet module¶
Original model code “liberated” from https://github.com/toandaominh1997/EfficientDet.Pytorch
Modified from bioharn
from liberator.closer import Closer
closer = Closer() closer.add_static(‘EfficientDet’, ‘models/efficientdet.py’) closer.expand([‘models’]) print(closer.current_sourcecode())
- geowatch.tasks.fusion.methods.efficientdet.bias_init_with_prob(prior_prob)[source]¶
initialize conv/fc bias value according to giving probablity
- geowatch.tasks.fusion.methods.efficientdet.conv_ws_2d(input, weight, bias=None, stride=1, padding=0, dilation=1, groups=1, eps=1e-05)[source]¶
- class geowatch.tasks.fusion.methods.efficientdet.ConvWS2d(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias=True, eps=1e-05)[source]¶
Bases:
Conv2d
- geowatch.tasks.fusion.methods.efficientdet.build_norm_layer(cfg, num_features, postfix='')[source]¶
Build normalization layer :Parameters: * cfg (dict) – cfg should contain:
type (str): identify norm layer type. layer args: args needed to instantiate a norm layer. requires_grad (bool): [optional] whether stop gradient updates
num_features (int) – number of channels from input.
postfix (int, str) – appended into norm abbreviation to create named layer.
- Returns:
abbreviation + postfix layer (nn.Module): created norm layer
- Return type:
name (str)
- geowatch.tasks.fusion.methods.efficientdet.build_conv_layer(cfg, *args, **kwargs)[source]¶
Build convolution layer :Parameters: cfg (None or dict) – cfg should contain:
type (str): identify conv layer type. layer args: args needed to instantiate a conv layer.
- Returns:
created conv layer
- Return type:
layer (nn.Module)
- class geowatch.tasks.fusion.methods.efficientdet.ConvModule(in_channels, out_channels, kernel_size, stride=1, padding=0, dilation=1, groups=1, bias='auto', conv_cfg=None, norm_cfg=None, activation='relu', inplace=True, order=('conv', 'norm', 'act'))[source]¶
Bases:
Module
A conv block that contains conv/norm/activation layers. :Parameters: * in_channels (int) – Same as nn.Conv2d.
out_channels (int) – Same as nn.Conv2d.
kernel_size (int or tuple[int]) – Same as nn.Conv2d.
stride (int or tuple[int]) – Same as nn.Conv2d.
padding (int or tuple[int]) – Same as nn.Conv2d.
dilation (int or tuple[int]) – Same as nn.Conv2d.
groups (int) – Same as nn.Conv2d.
bias (bool or str) – If specified as auto, it will be decided by the norm_cfg. Bias will be set as True if norm_cfg is None, otherwise False.
conv_cfg (dict) – Config dict for convolution layer.
norm_cfg (dict) – Config dict for normalization layer.
activation (str or None) – Activation type, “ReLU” by default.
inplace (bool) – Whether to use inplace mode for activation.
order (tuple[str]) – The order of conv/norm/activation layers. It is a sequence of “conv”, “norm” and “act”. Examples are (“conv”, “norm”, “act”) and (“act”, “conv”, “norm”).
- property norm¶
- class geowatch.tasks.fusion.methods.efficientdet.RetinaHead(num_classes, in_channels, feat_channels=256, stacked_convs=4, num_anchors=9, conv_cfg=None, norm_cfg=None, **kwargs)[source]¶
Bases:
Module
An anchor-based head used in [1]. The head contains two subnetworks. The first classifies anchor boxes and the second regresses deltas for the anchors. .. rubric:: References
Example
>>> from geowatch.tasks.fusion.methods.efficientdet import RetinaHead >>> import torch >>> self = RetinaHead(11, 7) >>> x = torch.rand(1, 7, 32, 32) >>> cls_score, bbox_pred = self.forward_single(x) >>> # Each anchor predicts a score for each class except background >>> cls_per_anchor = cls_score.shape[2] >>> box_per_anchor = bbox_pred.shape[2] >>> assert cls_per_anchor == (self.num_classes) >>> assert box_per_anchor == 4
- class geowatch.tasks.fusion.methods.efficientdet.FocalLoss(*args, **kwargs)[source]¶
Bases:
Module
Todo
validate loss formulation
original derived from https://github.com/kuangliu/pytorch-retinanet/blob/master/loss.py
Alternate impl https://github.com/facebookresearch/detectron2/blob/master/detectron2/modeling/meta_arch/retinanet.py
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- geowatch.tasks.fusion.methods.efficientdet.round_repeats(repeats, global_params)[source]¶
Round number of filters based on depth multiplier.
- geowatch.tasks.fusion.methods.efficientdet.round_filters(filters, global_params)[source]¶
Calculate and round number of filters based on depth multiplier.
- geowatch.tasks.fusion.methods.efficientdet.load_pretrained_weights(model, model_name, load_fc=True)[source]¶
Loads pretrained weights, and downloads if loading for the first time.
- class geowatch.tasks.fusion.methods.efficientdet.Conv2dStaticSamePadding(in_channels, out_channels, kernel_size, image_size=None, **kwargs)[source]¶
Bases:
Conv2d
2D Convolutions like TensorFlow, for a fixed image size
- class geowatch.tasks.fusion.methods.efficientdet.Conv2dDynamicSamePadding(in_channels, out_channels, kernel_size, stride=1, dilation=1, groups=1, bias=True)[source]¶
Bases:
Conv2d
2D Convolutions like TensorFlow, for a dynamic image size
- geowatch.tasks.fusion.methods.efficientdet.get_same_padding_conv2d(image_size=None)[source]¶
Chooses static padding if you have specified an image size, and dynamic padding otherwise. Static padding is necessary for ONNX exporting of models.
- class geowatch.tasks.fusion.methods.efficientdet.BlockArgs(kernel_size, num_repeat, input_filters, output_filters, expand_ratio, id_skip, stride, se_ratio)¶
Bases:
tuple
Create new instance of BlockArgs(kernel_size, num_repeat, input_filters, output_filters, expand_ratio, id_skip, stride, se_ratio)
- 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 geowatch.tasks.fusion.methods.efficientdet.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
Create new instance of GlobalParams(batch_norm_momentum, batch_norm_epsilon, dropout_rate, num_classes, width_coefficient, depth_coefficient, depth_divisor, min_depth, drop_connect_rate, image_size)
- 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 geowatch.tasks.fusion.methods.efficientdet.BlockDecoder[source]¶
Bases:
object
Block Decoder for readability, straight from the official TensorFlow repository
- geowatch.tasks.fusion.methods.efficientdet.efficientnet_params(model_name)[source]¶
Map EfficientNet model name to parameter coefficients.
- geowatch.tasks.fusion.methods.efficientdet.efficientnet(width_coefficient=None, depth_coefficient=None, dropout_rate=0.2, drop_connect_rate=0.2, image_size=None, num_classes=1000)[source]¶
Creates a efficientnet model.
- geowatch.tasks.fusion.methods.efficientdet.get_model_params(model_name, override_params)[source]¶
Get the block args and global params for a given model
- class geowatch.tasks.fusion.methods.efficientdet.Swish(*args, **kwargs)[source]¶
Bases:
Module
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- class geowatch.tasks.fusion.methods.efficientdet.SwishImplementation(*args, **kwargs)[source]¶
Bases:
Function
- class geowatch.tasks.fusion.methods.efficientdet.MemoryEfficientSwish(*args, **kwargs)[source]¶
Bases:
Module
Initialize internal Module state, shared by both nn.Module and ScriptModule.
- class geowatch.tasks.fusion.methods.efficientdet.MBConvBlock(block_args, global_params)[source]¶
Bases:
Module
Mobile Inverted Residual Bottleneck Block :Parameters: * block_args (namedtuple) – BlockArgs, see above
global_params (namedtuple) – GlobalParam, see above
- Variables:
has_se (bool) – Whether the block contains a Squeeze and Excitation layer.
- class geowatch.tasks.fusion.methods.efficientdet.EfficientNet(blocks_args=None, global_params=None)[source]¶
Bases:
Module
An EfficientNet model. Most easily loaded with the .from_name or .from_pretrained methods :Parameters: * blocks_args (list) – A list of BlockArgs to construct blocks
global_params (namedtuple) – A set of GlobalParams shared between blocks
Example
model = EfficientNet.from_pretrained(‘efficientnet-b0’)
- set_swish(memory_efficient=True)[source]¶
Sets swish function as memory efficient (for training) or standard (for export)
- class geowatch.tasks.fusion.methods.efficientdet.ClipBoxes(width=None, height=None)[source]¶
Bases:
Module
- geowatch.tasks.fusion.methods.efficientdet.xavier_init(module, gain=1, bias=0, distribution='normal')[source]¶
- class geowatch.tasks.fusion.methods.efficientdet.BiFPNModule(channels, levels, init=0.5, conv_cfg=None, norm_cfg=None, activation=None, eps=0.0001)[source]¶
Bases:
Module
- class geowatch.tasks.fusion.methods.efficientdet.BIFPN(in_channels, out_channels, num_outs, start_level=0, end_level=-1, stack=1, add_extra_convs=False, extra_convs_on_inputs=True, relu_before_extra_convs=False, no_norm_on_lateral=False, conv_cfg=None, norm_cfg=None, activation=None)[source]¶
Bases:
Module
I think this means bidirectional feature pyramid network
- class geowatch.tasks.fusion.methods.efficientdet.BBoxTransform(mean=None, std=None)[source]¶
Bases:
Module
- geowatch.tasks.fusion.methods.efficientdet.generate_anchors(base_size=16, ratios=None, scales=None)[source]¶
Generate anchor (reference) windows by enumerating aspect ratios X scales w.r.t. a reference window.
- class geowatch.tasks.fusion.methods.efficientdet.Anchors(pyramid_levels=None, strides=None, sizes=None, ratios=None, scales=None)[source]¶
Bases:
Module
Example
>>> self = anchors = Anchors() >>> image_shape = (130, 130) >>> anchors = self.forward(image_shape) >>> anchors = kwimage.Boxes(anchors, 'tlbr') >>> print(anchors.to_cxywh())
- class geowatch.tasks.fusion.methods.efficientdet.EfficientDetCoder(classes, threshold, iou_threshold)[source]¶
Bases:
object
Transforms output of EfficientDet into kwimage.Detections
- class geowatch.tasks.fusion.methods.efficientdet.EfficientDet(classes=None, input_stats=None, channels=None, network='efficientdet-d0', D_bifpn=3, W_bifpn=88, D_class=3, threshold=0.01, iou_threshold=0.5, n_scales=5)[source]¶
Bases:
Module