cd.models
This submodule contains model definitions and common modules.
U-Net
- class MobileNetV3LargeUNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
Large MobileNet V3 U-Net.
A U-Net with Large MobileNet V3 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class MobileNetV3SmallUNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
Small MobileNet V3 U-Net.
A U-Net with Small MobileNet V3 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class ResNeXt101UNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
ResNeXt 101 U-Net.
A U-Net with ResNeXt 101 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class ResNeXt152UNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
ResNeXt 152 U-Net.
A U-Net with ResNeXt 152 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class ResNeXt50UNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
ResNeXt 50 U-Net.
A U-Net with ResNeXt 50 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class ResNet101UNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
ResNet 101 U-Net.
A U-Net with ResNet 101 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class ResNet152UNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
ResNet 152 U-Net.
A U-Net with ResNet 152 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class ResNet18UNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
ResNet 18 U-Net.
A U-Net with ResNet 18 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class ResNet34UNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
ResNet 34 U-Net.
A U-Net with ResNet 34 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class ResNet50UNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
ResNet 50 U-Net.
A U-Net with ResNet 50 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class ResUNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
Residual U-Net.
U-Net with residual blocks.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function.
backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
ResBlock
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class SlimU22(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
Slim U-Net 22.
U-Net with 22 convolutions on 5 feature resolutions (1, 1/2, 1/4, 1/8, 1/16) and one final output layer. Like U22, but number of feature channels reduce by half.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class U12(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
U-Net 12.
U-Net with 12 convolutions on 3 feature resolutions (1, 1/2, 1/4) and one final output layer.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class U17(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
U-Net 17.
U-Net with 17 convolutions on 4 feature resolutions (1, 1/2, 1/4, 1/8) and one final output layer.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class U22(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
U-Net 22.
U-Net with 22 convolutions on 5 feature resolutions (1, 1/2, 1/4, 1/8, 1/16) and one final output layer.
References
https://arxiv.org/abs/1505.04597
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function.
backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class UNet(backbone, out_channels: int, return_layers: ~typing.Optional[dict] = None, block: ~typing.Type[~torch.nn.modules.module.Module] = <class 'celldetection.models.commons.TwoConvNormRelu'>, block_kwargs: ~typing.Optional[dict] = None, final_activation=None, interpolate='nearest', **kwargs)
U-Net.
Examples
>>> model = UNet(UNetEncoder(in_channels=3), out_channels=2)
>>> model = UNet(UNetEncoder(in_channels=3, base_channels=16), out_channels=2) >>> o = model(torch.rand(1, 3, 256, 256)) >>> for k, v in o.items(): ... print(k, " ", v.shape) out torch.Size([1, 2, 256, 256]) 0 torch.Size([1, 16, 256, 256]) 1 torch.Size([1, 32, 128, 128]) 2 torch.Size([1, 64, 64, 64]) 3 torch.Size([1, 128, 32, 32]) 4 torch.Size([1, 256, 16, 16])
- Parameters
backbone – Backbone instance.
out_channels – Output channels.
return_layers – Dictionary like {backbone_layer_name: out_name}. Note that this influences how outputs are computed, as the input for the upsampling is gathered by IntermediateLayerGetter based on given dict keys.
block – Module class. Default is block=TwoConvNormRelu. Must be callable: block(in_channels, out_channels).
final_activation – Final activation function.
- training: bool
- class UNetEncoder(in_channels, depth=5, base_channels=64, factor=2, pool=True, block_cls: Optional[Type[Module]] = None)
U-Net Encoder.
- Parameters
in_channels – Input channels.
depth – Model depth.
base_channels – Base channels.
factor – Growth factor of base_channels.
pool – Whether to use max pooling or stride 2 for downsampling.
block_cls – Block class. Callable as block_cls(in_channels, out_channels, stride=stride).
- class WideResNet101UNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
Wide ResNet 101 U-Net.
A U-Net with Wide ResNet 101 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class WideResNet50UNet(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
Wide ResNet 50 U-Net.
A U-Net with Wide ResNet 50 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
- class WideU22(in_channels, out_channels, final_activation=None, backbone_kwargs=None, pretrained=False, block_cls=None, **kwargs)
Slim U-Net 22.
U-Net with 22 convolutions on 5 feature resolutions (1, 1/2, 1/4, 1/8, 1/16) and one final output layer. Like U22, but number of feature channels doubled.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_activation – Final activation function. Only used if
out_channels > 0
.backbone_kwargs – Keyword arguments for encoder.
pretrained – Whether to use a pretrained encoder. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.block_cls – Module class that defines a convolutional block. Default:
TwoConvNormRelu
.**kwargs – Additional keyword arguments for
cd.models.UNet
.
- training: bool
Contour Proposal Network
- class CPN(backbone: Module, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, certainty_thresh: Optional[float] = None, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, contour_features='1', refinement_features='0', uncertainty_head=False, uncertainty_nms=False, uncertainty_factor=10.0, contour_head_channels=None, contour_head_stride=1, order_weights=True, refinement_head_channels=None, refinement_head_stride=1, refinement_interpolation='bilinear', score_encoder_features=False, refinement_encoder_features=False)
CPN base class.
This is the base class for the Contour Proposal Network.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
backbone – A backbone network. E.g.
cd.models.U22(in_channels, 0)
.order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.contour_features – If
backbone
returns a dictionary of features, this is the key used to retrieve the features that are used to predict contours.refinement_features – If
backbone
returns a dictionary of features, this is the key used to retrieve the features that are used to predict the refinement tensor.contour_head_channels – Number of intermediate channels in contour
ReadOut
Modules. By default, this is the number of incoming feature channels.contour_head_stride – Stride used for the contour prediction. Larger stride means less contours can be proposed in total, which speeds up execution times.
order_weights – Whether to use order specific weights.
refinement_head_channels – Number of intermediate channels in refinement
ReadOut
Modules. By default, this is the number of incoming feature channels.refinement_head_stride – Stride used for the refinement prediction. Larger stride means less detail, but speeds up execution times.
refinement_interpolation – Interpolation mode that is used to ensure that refinement tensor and input image have the same shape.
score_encoder_features – Whether to use encoder-head skip connections for the score head.
refinement_encoder_features – Whether to use encoder-head skip connections for the refinement head.
- compute_loss(uncertainty, fourier, locations, contours, refined_contours, boxes, raw_scores, targets: dict, labels, fg_masks, b)
- forward(inputs, targets: Optional[Dict[str, Tensor]] = None, nms=True)
- training: bool
- class CpnMobileNetV3LargeFPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with Large MobileNetV3 FPN backbone.
A Contour Proposal Network that uses a Large MobileNetV3 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.MobileNetV3LargeFPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnMobileNetV3SmallFPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with Small MobileNetV3 FPN backbone.
A Contour Proposal Network that uses a Small MobileNetV3 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.MobileNetV3SmallFPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNeXt101FPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with ResNeXt 101 FPN backbone.
A Contour Proposal Network that uses a ResNeXt 101 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNeXt101FPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNeXt101UNet(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs=None, **kwargs)
Contour Proposal Network with ResNeXt 101 U-Net backbone.
A Contour Proposal Network that uses a ResNeXt 101 U-Net as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNeXt101UNet
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNeXt152FPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with ResNeXt 152 FPN backbone.
A Contour Proposal Network that uses a ResNeXt 152 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNeXt152FPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNeXt152UNet(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs=None, **kwargs)
Contour Proposal Network with ResNeXt 152 U-Net backbone.
A Contour Proposal Network that uses a ResNet 152 U-Net as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNeXt152UNet
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNeXt50FPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with ResNeXt 50 FPN backbone.
A Contour Proposal Network that uses a ResNeXt 50 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNeXt50FPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNeXt50UNet(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs=None, **kwargs)
Contour Proposal Network with ResNeXt 50 U-Net backbone.
A Contour Proposal Network that uses a ResNeXt 50 U-Net as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNeXt50UNet
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNet101FPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with ResNet 101 FPN backbone.
A Contour Proposal Network that uses a ResNet 101 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNet101FPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNet101UNet(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs=None, **kwargs)
Contour Proposal Network with ResNet 101 U-Net backbone.
A Contour Proposal Network that uses a ResNet 101 U-Net as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNet101UNet
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNet152FPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with ResNet 152 FPN backbone.
A Contour Proposal Network that uses a ResNet 152 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNet152FPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNet152UNet(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs=None, **kwargs)
Contour Proposal Network with ResNet 152 U-Net backbone.
A Contour Proposal Network that uses a ResNet 152 U-Net as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNet152UNet
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNet18FPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with ResNet 18 FPN backbone.
A Contour Proposal Network that uses a ResNet 18 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNet18FPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNet18UNet(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs=None, **kwargs)
Contour Proposal Network with ResNet 18 U-Net backbone.
A Contour Proposal Network that uses a ResNet 18 U-Net as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNet18UNet
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNet34FPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with ResNet 34 FPN backbone.
A Contour Proposal Network that uses a ResNet 34 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNet34FPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNet34UNet(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs=None, **kwargs)
Contour Proposal Network with ResNet 34 U-Net backbone.
A Contour Proposal Network that uses a ResNet 34 U-Net as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNet34UNet
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNet50FPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with ResNet 50 FPN backbone.
A Contour Proposal Network that uses a ResNet 50 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNet50FPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResNet50UNet(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs=None, **kwargs)
Contour Proposal Network with ResNet 50 U-Net backbone.
A Contour Proposal Network that uses a ResNet 50 U-Net as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResNet50UNet
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnResUNet(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with Residual U-Net backbone.
A Contour Proposal Network that uses a U-Net build with residual blocks.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.ResUNet
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnSlimU22(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with Slim U-Net 22 backbone.
A Contour Proposal Network that uses a Slim U-Net as a backbone. Slim U-Net has 22 convolutions with less feature channels than normal U22.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.SlimU22
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnU22(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with U-Net 22 backbone.
A Contour Proposal Network that uses a U-Net with 22 convolutions as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.U22
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnWideResNet101FPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with Wide ResNet 101 FPN backbone.
A Contour Proposal Network that uses a Wide ResNet 101 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.WideResNet101FPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnWideResNet50FPN(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with Wide ResNet 50 FPN backbone.
A Contour Proposal Network that uses a Wide ResNet 50 Feature Pyramid Network as a backbone.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.WideResNet50FPN
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
- class CpnWideU22(in_channels: int, order: int = 5, nms_thresh: float = 0.2, score_thresh: float = 0.5, samples: int = 32, classes: int = 2, refinement: bool = True, refinement_iterations: int = 4, refinement_margin: float = 3.0, refinement_buckets: int = 1, backbone_kwargs: Optional[dict] = None, **kwargs)
Contour Proposal Network with Wide U-Net 22 backbone.
A Contour Proposal Network that uses a Wide U-Net as a backbone. Wide U-Net has 22 convolutions with more feature channels than normal U22.
References
https://www.sciencedirect.com/science/article/pii/S136184152200024X
- Parameters
in_channels – Number of input channels.
order – Contour order. The higher, the more complex contours can be proposed.
order=1
restricts the CPN to propose ellipses,order=3
allows for non-convex rough outlines,order=8
allows even finer detail.nms_thresh – IoU threshold for non-maximum suppression (NMS). NMS considers all objects with
iou > nms_thresh
to be identical.score_thresh – Score threshold. For binary classification problems (object vs. background) an object must have
score > score_thresh
to be proposed as a result.samples – Number of samples. This sets the number of coordinates with which a contour is defined. This setting can be changed on the fly, e.g. small for training and large for inference. Small settings reduces computational costs, while larger settings capture more detail.
classes – Number of classes. Default: 2 (object vs. background).
refinement – Whether to use local refinement or not. Local refinement generally improves pixel precision of the proposed contours.
refinement_iterations – Number of refinement iterations.
refinement_margin – Maximum refinement margin (step size) per iteration.
refinement_buckets – Number of refinement buckets. Bucketed refinement is especially recommended for data with overlapping objects.
refinement_buckets=1
practically disables bucketing,refinement_buckets=6
uses 6 different buckets, each influencing different fractions of a contour.backbone_kwargs – Additional backbone keyword arguments. See docstring of
cd.models.WideU22
.**kwargs – Additional CPN keyword arguments. See docstring of
cd.models.CPN
.
- training: bool
ResNet
- class ResNeXt101_32x8d(in_channels, out_channels=0, pretrained=False, **kwargs)
ResNeXt 101.
ResNeXt 101 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_layer – Final output layer. Default: 1x1 Conv2d if
out_channels >= 1
,None
otherwise.final_activation – Final activation layer (e.g.
nn.ReLU
or'relu'
). Default:None
.pretrained – Whether to load weights from a pretrained network. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.**kwargs – Additional keyword arguments.
- class ResNeXt152_32x8d(in_channels, out_channels=0, **kwargs)
ResNeXt 152.
ResNeXt 152 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_layer – Final output layer. Default: 1x1 Conv2d if
out_channels >= 1
,None
otherwise.final_activation – Final activation layer (e.g.
nn.ReLU
or'relu'
). Default:None
.pretrained – Whether to load weights from a pretrained network. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.**kwargs – Additional keyword arguments.
- class ResNeXt50_32x4d(in_channels, out_channels=0, pretrained=False, **kwargs)
ResNeXt 50.
ResNeXt 50 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_layer – Final output layer. Default: 1x1 Conv2d if
out_channels >= 1
,None
otherwise.final_activation – Final activation layer (e.g.
nn.ReLU
or'relu'
). Default:None
.pretrained – Whether to load weights from a pretrained network. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.**kwargs – Additional keyword arguments.
- class ResNet101(in_channels, out_channels=0, pretrained=False, **kwargs)
ResNet 101.
ResNet 101 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_layer – Final output layer. Default: 1x1 Conv2d if
out_channels >= 1
,None
otherwise.final_activation – Final activation layer (e.g.
nn.ReLU
or'relu'
). Default:None
.pretrained – Whether to load weights from a pretrained network. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.**kwargs – Additional keyword arguments.
- class ResNet152(in_channels, out_channels=0, pretrained=False, **kwargs)
ResNet 152.
ResNet 152 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_layer – Final output layer. Default: 1x1 Conv2d if
out_channels >= 1
,None
otherwise.final_activation – Final activation layer (e.g.
nn.ReLU
or'relu'
). Default:None
.pretrained – Whether to load weights from a pretrained network. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.**kwargs – Additional keyword arguments.
- class ResNet18(in_channels, out_channels=0, pretrained=False, **kwargs)
ResNet 18.
ResNet 18 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_layer – Final output layer. Default: 1x1 Conv2d if
out_channels >= 1
,None
otherwise.final_activation – Final activation layer (e.g.
nn.ReLU
or'relu'
). Default:None
.pretrained – Whether to load weights from a pretrained network. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.**kwargs – Additional keyword arguments.
- class ResNet34(in_channels, out_channels=0, pretrained=False, **kwargs)
ResNet 34.
ResNet 34 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_layer – Final output layer. Default: 1x1 Conv2d if
out_channels >= 1
,None
otherwise.final_activation – Final activation layer (e.g.
nn.ReLU
or'relu'
). Default:None
.pretrained – Whether to load weights from a pretrained network. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.**kwargs – Additional keyword arguments.
- class ResNet50(in_channels, out_channels=0, pretrained=False, **kwargs)
ResNet 50.
ResNet 50 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_layer – Final output layer. Default: 1x1 Conv2d if
out_channels >= 1
,None
otherwise.final_activation – Final activation layer (e.g.
nn.ReLU
or'relu'
). Default:None
.pretrained – Whether to load weights from a pretrained network. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.**kwargs – Additional keyword arguments.
- class WideResNet101_2(in_channels, out_channels=0, pretrained=False, **kwargs)
Wide ResNet 101.
Wide ResNet 101 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_layer – Final output layer. Default: 1x1 Conv2d if
out_channels >= 1
,None
otherwise.final_activation – Final activation layer (e.g.
nn.ReLU
or'relu'
). Default:None
.pretrained – Whether to load weights from a pretrained network. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.**kwargs – Additional keyword arguments.
- class WideResNet50_2(in_channels, out_channels=0, pretrained=False, **kwargs)
Wide ResNet 50.
Wide ResNet 50 encoder.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels. If set to 0, the output layer is omitted.
final_layer – Final output layer. Default: 1x1 Conv2d if
out_channels >= 1
,None
otherwise.final_activation – Final activation layer (e.g.
nn.ReLU
or'relu'
). Default:None
.pretrained – Whether to load weights from a pretrained network. If True default weights are used. Alternatively,
pretrained
can be a URL of astate_dict
that is hosted online.**kwargs – Additional keyword arguments.
- get_resnet(name, in_channels, **kwargs)
Feature Pyramid Network
- class FPN(backbone, channels=256, return_layers: Optional[dict] = None)
Examples
>>> from celldetection.models import ResNet18, FPN ... import torch >>> model = FPN(ResNet18(in_channels=1)) >>> for k, v in model(torch.rand(1, 1, 128, 128)).items(): ... print(k, " ", v.shape) 0 torch.Size([1, 256, 32, 32]) 1 torch.Size([1, 256, 16, 16]) 2 torch.Size([1, 256, 8, 8]) 3 torch.Size([1, 256, 4, 4]) pool torch.Size([1, 256, 2, 2])
- Parameters
backbone – Backbone module Note that backbone.out_channels must be defined.
channels – Channels in the upsampling branch.
return_layers – Dictionary like {backbone_layer_name: out_name}. Note that this influences how outputs are computed, as the input for the upsampling is gathered by IntermediateLayerGetter based on given dict keys.
- training: bool
- class MobileNetV3LargeFPN(in_channels, fpn_channels=256, **kwargs)
Feature Pyramid Network with MobileNetV3Large.
Examples
>>> import torch >>> from celldetection import models >>> model = models.MobileNetV3LargeFPN(in_channels=3) >>> out: dict = model(torch.rand(1, 3, 256, 256)) >>> for k, v in out.items(): ... print(k, v.shape) 0 torch.Size([1, 256, 128, 128]) 1 torch.Size([1, 256, 64, 64]) 2 torch.Size([1, 256, 32, 32]) 3 torch.Size([1, 256, 16, 16]) 4 torch.Size([1, 256, 8, 8]) pool torch.Size([1, 256, 4, 4])
- training: bool
- class MobileNetV3SmallFPN(in_channels, fpn_channels=256, **kwargs)
Feature Pyramid Network with MobileNetV3Small.
Examples
>>> import torch >>> from celldetection import models >>> model = models.MobileNetV3SmallFPN(in_channels=3) >>> out: dict = model(torch.rand(1, 3, 256, 256)) >>> for k, v in out.items(): ... print(k, v.shape) 0 torch.Size([1, 256, 128, 128]) 1 torch.Size([1, 256, 64, 64]) 2 torch.Size([1, 256, 32, 32]) 3 torch.Size([1, 256, 16, 16]) 4 torch.Size([1, 256, 8, 8]) pool torch.Size([1, 256, 4, 4])
- training: bool
MobileNet
- class MobileNetV3Large(in_channels, width_mult: float = 1.0, reduced_tail: bool = False, dilated: bool = False)
- class MobileNetV3Small(in_channels, width_mult: float = 1.0, reduced_tail: bool = False, dilated: bool = False)
Common Modules
- class BottleneckBlock(in_channels, out_channels, kernel_size=3, padding=1, mid_channels=None, compression=4, base_channels=64, norm_layer='BatchNorm2d', activation='ReLU', stride=1, downsample=None, **kwargs)
Bottleneck Block.
Typical Bottleneck Block with variable kernel size and an included mapping of the identity to correct dimensions.
References
Notes
Similar to
torchvision.models.resnet.Bottleneck
, with different interface and defaults.Consistent with standard signature
in_channels, out_channels, kernel_size, ...
.Stride handled in bottleneck.
- Parameters
in_channels – Input channels.
out_channels – Output channels.
kernel_size – Kernel size.
padding – Padding.
mid_channels –
compression – Compression rate of the bottleneck. The default 4 compresses 256 channels to 64=256/4.
base_channels – Minimum number of
mid_channels
.norm_layer – Norm layer.
activation – Activation.
stride – Stride.
downsample – Downsample module that maps identity to correct dimensions. Default is an optionally strided 1x1 Conv2d with BatchNorm2d, as per He et al. (2015) (3.3. Network Architectures, Residual Network, “option (B)”).
**kwargs – Keyword arguments for Conv2d layers.
- training: bool
- class ConvNorm(in_channels, out_channels, kernel_size=3, padding=1, stride=1, norm_layer=<class 'torch.nn.modules.batchnorm.BatchNorm2d'>, **kwargs)
ConvNorm.
Just a convolution and a normalization layer.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels.
kernel_size – Kernel size.
padding – Padding.
stride – Stride.
norm_layer – Normalization layer (e.g.
nn.BatchNorm2d
).**kwargs – Additional keyword arguments.
- class ConvNormRelu(in_channels, out_channels, kernel_size=3, padding=1, stride=1, norm_layer=<class 'torch.nn.modules.batchnorm.BatchNorm2d'>, activation='relu', **kwargs)
ConvNormReLU.
Just a convolution, normalization layer and an activation.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels.
kernel_size – Kernel size.
padding – Padding.
stride – Stride.
norm_layer – Normalization layer (e.g.
nn.BatchNorm2d
).activation – Activation function. (e.g.
nn.ReLU
,'relu'
)**kwargs – Additional keyword arguments.
- class MinibatchStdLayer(channels=1, group_channels=None, epsilon=1e-08)
Minibatch standard deviation layer.
The minibatch standard deviation layer first splits the batch dimension into slices of size
group_channels
. The channel dimension is split intochannels
slices. For the groups the standard deviation is calculated and averaged over spatial dimensions and channel slice depth. The result is broadcasted to the spatial dimensions, repeated for the batch dimension and then concatenated to the channel dimension ofx
.References
- Parameters
channels – Number of averaged standard deviation channels.
group_channels – Number of channels per group. Default: batch size.
epsilon – Epsilon.
- extra_repr() str
- forward(x)
- training: bool
- class NoAmp(module: Type[Module])
No AMP.
Wrap a
Module
object and disabletorch.cuda.amp.autocast
during forward pass if it is enabled.Examples
>>> import celldetection as cd ... model = cd.models.CpnU22(1) ... # Wrap all ReadOut modules in model with NoAmp, thus disabling autocast for those modules ... cd.wrap_module_(model, cd.models.ReadOut, cd.models.NoAmp)
- Parameters
module – Module.
- forward(*args, **kwargs)
- training: bool
- class ReadOut(channels_in, channels_out, kernel_size=3, padding=1, activation='relu', norm='batchnorm2d', final_activation=None, dropout=0.1, channels_mid=None, stride=1)
- forward(x)
- training: bool
- class ReplayCache(size=128)
Replay Cache.
Typical cache that can be used for experience replay in GAN training.
Notes
Items remain on their current device.
- Parameters
size – Number of batch items that fit in cache.
- add(x, fraction=0.5)
Add.
Add a
fraction
of batchx
to cache. Drop random items if cache is full.- Parameters
x – Batch Tensor[n, …].
fraction – Fraction in 0..1.
- is_empty()
- class ResBlock(in_channels, out_channels, kernel_size=3, padding=1, norm_layer='BatchNorm2d', activation='ReLU', stride=1, downsample=None, **kwargs)
ResBlock.
Typical ResBlock with variable kernel size and an included mapping of the identity to correct dimensions.
References
Notes
Similar to
torchvision.models.resnet.BasicBlock
, with different interface and defaults.Consistent with standard signature
in_channels, out_channels, kernel_size, ...
.
- Parameters
in_channels – Input channels.
out_channels – Output channels.
kernel_size – Kernel size.
padding – Padding.
norm_layer – Norm layer.
activation – Activation.
stride – Stride.
downsample – Downsample module that maps identity to correct dimensions. Default is an optionally strided 1x1 Conv2d with BatchNorm2d, as per He et al. (2015) (3.3. Network Architectures, Residual Network, “option (B)”).
**kwargs – Keyword arguments for Conv2d layers.
- training: bool
- class ScaledSigmoid(factor, shift=0.0)
Scaled Sigmoid.
Computes the scaled and shifted sigmoid:
- Parameters
factor – Scaling factor.
shift – Shifting constant.
- training: bool
- class ScaledTanh(factor, shift=0.0)
Scaled Tanh.
Computes the scaled and shifted hyperbolic tangent:
- Parameters
factor – Scaling factor.
shift – Shifting constant.
- training: bool
- class SpatialSplit(height, width=None)
Spatial split.
Splits spatial dimensions of input Tensor into patches of size
(height, width)
and adds the patches to the batch dimension.- Parameters
height – Patch height.
width – Patch width.
- forward(x)
- training: bool
- class TwoConvNormRelu(in_channels, out_channels, kernel_size=3, padding=1, stride=1, mid_channels=None, norm_layer=<class 'torch.nn.modules.batchnorm.BatchNorm2d'>, activation='relu', **kwargs)
TwoConvNormReLU.
A sequence of conv, norm, activation, conv, norm, activation.
- Parameters
in_channels – Number of input channels.
out_channels – Number of output channels.
kernel_size – Kernel size.
padding – Padding.
stride – Stride.
mid_channels – Mid-channels. Default: Same as
out_channels
.norm_layer – Normalization layer (e.g.
nn.BatchNorm2d
).activation – Activation function. (e.g.
nn.ReLU
,'relu'
)**kwargs – Additional keyword arguments.
Filters
- class BoxFilter2d(in_channels: int, kernel_size, stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 0, dilation: Union[int, Tuple[int, int]] = 1, padding_mode: str = 'zeros', device=None, dtype=None, odd_padding=True, trainable=False, normalize=True)
Box Filter 2d.
- Parameters
in_channels – Number of input channels.
stride – Stride.
padding – Padding.
dilation – Spacing between kernel elements.
padding_mode – One of
'zeros'
,'reflect'
,'replicate'
or'circular'
. Default:'zeros'
.device – Device.
dtype – Data type.
odd_padding – Whether to apply one-sided padding to account for even kernel sizes.
trainable – Whether the kernel should be trainable.
normalize – Whether to normalize the kernel to retain magnitude.
- bias: Optional[Tensor]
- dilation: Tuple[int, ...]
- static get_kernel2d(kernel_size, normalize=True)
- groups: int
- in_channels: int
- kernel_size: Tuple[int, ...]
- out_channels: int
- output_padding: Tuple[int, ...]
- padding: Union[str, Tuple[int, ...]]
- padding_mode: str
- stride: Tuple[int, ...]
- transposed: bool
- weight: Tensor
- class EdgeFilter2d(in_channels: int, stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 1, dilation: Union[int, Tuple[int, int]] = 1, padding_mode: str = 'replicate', device=None, dtype=None, magnitude=True, trainable=False, **kwargs)
Edge Filter 2d.
Find edges in an image using the Sobel filter.
- Parameters
in_channels – Number of input channels.
stride – Stride.
padding – Padding. Default: 1.
dilation – Spacing between kernel elements.
padding_mode – One of
'zeros'
,'reflect'
,'replicate'
or'circular'
. Default:'replicate'
.device – Device.
dtype – Data type.
trainable – Whether the kernel should be trainable.
magnitude – Whether to compute the magnitude image.
**kwargs – Additional keyword arguments for
cd.models.Filter2d
.
- forward(x)
- training: bool
- class Filter2d(in_channels: int, kernel, stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 0, dilation: Union[int, Tuple[int, int]] = 1, padding_mode: str = 'zeros', device=None, dtype=None, odd_padding=True, trainable=True)
Filter 2d.
Applies a 2d filter to all channels of input.
Examples
>>> sobel = torch.as_tensor([ ... [1, 0, -1], ... [2, 0, -2], ... [1, 0, -1], ... ], dtype=torch.float32) ... sobel_layer = Filter2d(in_channels=3, kernel=sobel, padding=1, trainable=False) ... sobel_layer, sobel_layer.weight (Filter2d(3, 3, kernel_size=(3, 3), stride=(1, 1), padding=(1, 1), groups=3, bias=False), tensor([[ 1., 0., -1.], [ 2., 0., -2.], [ 1., 0., -1.]]))
- Parameters
in_channels – Number of input channels.
kernel – Filter matrix.
stride – Stride.
padding – Padding.
dilation – Spacing between kernel elements.
padding_mode – One of
'zeros'
,'reflect'
,'replicate'
or'circular'
. Default:'zeros'
.device – Device.
dtype – Data type.
odd_padding – Whether to apply one-sided padding to account for even kernel sizes.
trainable – Whether the kernel should be trainable.
- bias: Optional[Tensor]
- dilation: Tuple[int, ...]
- forward(x: Tensor) Tensor
- groups: int
- in_channels: int
- kernel_size: Tuple[int, ...]
- out_channels: int
- output_padding: Tuple[int, ...]
- padding: Union[str, Tuple[int, ...]]
- padding_mode: str
- reset_parameters()
- stride: Tuple[int, ...]
- transposed: bool
- weight: Tensor
- class GaussianFilter2d(in_channels: int, kernel_size, stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 0, dilation: Union[int, Tuple[int, int]] = 1, padding_mode: str = 'zeros', device=None, dtype=None, odd_padding=True, trainable=False, sigma=-1)
Gaussian Filter 2d.
- Parameters
in_channels – Number of input channels.
kernel_size – Kernel size.
stride – Stride.
padding – Padding.
dilation – Spacing between kernel elements.
padding_mode – One of
'zeros'
,'reflect'
,'replicate'
or'circular'
. Default:'zeros'
.device – Device.
dtype – Data type.
odd_padding – Whether to apply one-sided padding to account for even kernel sizes.
trainable – Whether the kernel should be trainable.
sigma – Gaussian standard deviation as float or tuple. If it is non-positive, it is computed from kernel_size as
sigma = 0.3*((kernel_size-1)*0.5 - 1) + 0.8
.
- bias: Optional[Tensor]
- dilation: Tuple[int, ...]
- static get_kernel2d(kernel_size, sigma=-1)
- groups: int
- in_channels: int
- kernel_size: Tuple[int, ...]
- out_channels: int
- output_padding: Tuple[int, ...]
- padding: Union[str, Tuple[int, ...]]
- padding_mode: str
- stride: Tuple[int, ...]
- training: bool
- transposed: bool
- weight: Tensor
- class LaplaceFilter2d(in_channels: int, stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 0, dilation: Union[int, Tuple[int, int]] = 1, padding_mode: str = 'zeros', device=None, dtype=None, odd_padding=True, trainable=False, diagonal=False)
Laplace Filter 2d.
Applies the 3x3 Laplace operator.
References
- Parameters
in_channels – Number of input channels.
stride – Stride.
padding – Padding.
dilation – Spacing between kernel elements.
padding_mode – One of
'zeros'
,'reflect'
,'replicate'
or'circular'
. Default:'zeros'
.device – Device.
dtype – Data type.
odd_padding – Whether to apply one-sided padding to account for even kernel sizes.
trainable – Whether the kernel should be trainable.
diagonal – Whether to use a kernel that includes diagonals.
- bias: Optional[Tensor]
- dilation: Tuple[int, ...]
- static get_kernel2d(diagonal=False)
- groups: int
- in_channels: int
- kernel_size: Tuple[int, ...]
- out_channels: int
- output_padding: Tuple[int, ...]
- padding: Union[str, Tuple[int, ...]]
- padding_mode: str
- stride: Tuple[int, ...]
- training: bool
- transposed: bool
- weight: Tensor
- class PascalFilter2d(in_channels: int, kernel_size, stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 0, dilation: Union[int, Tuple[int, int]] = 1, padding_mode: str = 'zeros', device=None, dtype=None, odd_padding=True, trainable=False, normalize=True)
Pascal Filter 2d.
Applies a 2d pascal filter to all channels of input.
References
- Parameters
in_channels – Number of input channels.
kernel_size – Kernel size.
stride – Stride.
padding – Padding.
dilation – Spacing between kernel elements.
padding_mode – One of
'zeros'
,'reflect'
,'replicate'
or'circular'
. Default:'zeros'
.device – Device.
dtype – Data type.
odd_padding – Whether to apply one-sided padding to account for even kernel sizes.
trainable – Whether the kernel should be trainable.
normalize – Whether to normalize the kernel to retain magnitude.
- bias: Optional[Tensor]
- dilation: Tuple[int, ...]
- static get_kernel1d(kernel_size, normalize=True)
- static get_kernel2d(kernel_size, normalize=True)
- groups: int
- in_channels: int
- kernel_size: Tuple[int, ...]
- out_channels: int
- output_padding: Tuple[int, ...]
- padding: Union[str, Tuple[int, ...]]
- padding_mode: str
- stride: Tuple[int, ...]
- training: bool
- transposed: bool
- weight: Tensor
- class ScharrFilter2d(in_channels: int, stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 0, dilation: Union[int, Tuple[int, int]] = 1, padding_mode: str = 'zeros', device=None, dtype=None, odd_padding=True, trainable=False, transpose=False)
Scharr Filter 2d.
Applies the Scharr gradient operator, a 3x3 kernel optimized for rotational symmetry.
References
- Parameters
in_channels – Number of input channels.
stride – Stride.
padding – Padding.
dilation – Spacing between kernel elements.
padding_mode – One of
'zeros'
,'reflect'
,'replicate'
or'circular'
. Default:'zeros'
.device – Device.
dtype – Data type.
odd_padding – Whether to apply one-sided padding to account for even kernel sizes.
trainable – Whether the kernel should be trainable.
transpose –
False
forkernel,
True
forkernel.
- bias: Optional[Tensor]
- dilation: Tuple[int, ...]
- static get_kernel2d(transpose=False)
- groups: int
- in_channels: int
- kernel_size: Tuple[int, ...]
- out_channels: int
- output_padding: Tuple[int, ...]
- padding: Union[str, Tuple[int, ...]]
- padding_mode: str
- stride: Tuple[int, ...]
- training: bool
- transposed: bool
- weight: Tensor
- class SobelFilter2d(in_channels: int, stride: Union[int, Tuple[int, int]] = 1, padding: Union[str, int, Tuple[int, int]] = 0, dilation: Union[int, Tuple[int, int]] = 1, padding_mode: str = 'zeros', device=None, dtype=None, odd_padding=True, trainable=False, transpose=False)
Sobel Filter 2d.
Applies the 3x3 Sobel image gradient operator.
References
- Parameters
in_channels – Number of input channels.
stride – Stride.
padding – Padding.
dilation – Spacing between kernel elements.
padding_mode – One of
'zeros'
,'reflect'
,'replicate'
or'circular'
. Default:'zeros'
.device – Device.
dtype – Data type.
odd_padding – Whether to apply one-sided padding to account for even kernel sizes.
trainable – Whether the kernel should be trainable.
transpose –
False
forkernel,
True
forkernel.
- bias: Optional[Tensor]
- dilation: Tuple[int, ...]
- static get_kernel2d(transpose=False)
- groups: int
- in_channels: int
- kernel_size: Tuple[int, ...]
- out_channels: int
- output_padding: Tuple[int, ...]
- padding: Union[str, Tuple[int, ...]]
- padding_mode: str
- stride: Tuple[int, ...]
- training: bool
- transposed: bool
- weight: Tensor
- class UpFilter2d(module, scale_factor: int = 2)
Upsample Filter 2d.
This Module performs the upsampling step of a typical image pyramid. First, it upsamples the input Tensor by injecting zeros as columns and rows, then it applies the given
module
, which could be for example acd.models.PascalFilter2d
.- Parameters
module – Filter module.
scale_factor – Scale factor.
- forward(x: Tensor) Tensor
- training: bool
Normalization
- class PixelNorm(dim=1, eps=1e-08)
Pixel normalization.
References
https://papers.nips.cc/paper/2012/file/c399862d3b9d6b76c8436e924a68c45b-Paper.pdf (“Local Repose Norm”)
- Parameters
dim – Dimension to normalize.
eps – Epsilon.
- forward(x)
- training: bool
Losses
- class BoxNpllLoss(factor=10.0, sigmoid=False, min_size=None, epsilon=1e-08, size_average=None, reduce=None, reduction: str = 'mean')
- forward(uncertainty: Tensor, input: Tensor, target: Tensor) Tensor
- reduction: str