CSPNetBackbone
classkeras_hub.models.CSPNetBackbone(
stem_filters,
stem_kernel_size,
stem_strides,
stackwise_depth,
stackwise_strides,
stackwise_num_filters,
block_type,
groups=1,
stage_type=None,
activation="leaky_relu",
output_strides=32,
bottle_ratio=[1.0],
block_ratio=[1.0],
expand_ratio=[1.0],
stem_padding="valid",
stem_pooling=None,
avg_down=False,
down_growth=False,
cross_linear=False,
image_shape=(None, None, 3),
data_format=None,
dtype=None,
**kwargs
)
This class represents Keras Backbone of CSPNet model.
This class implements a CSPNet backbone as described in CSPNet: A New Backbone that can Enhance Learning Capability of CNN.
Arguments
"bottleneck_block"
, "dark_block"
, or
"edge_block"
. Use "dark_block"
for DarkNet blocks,
"edge_block"
for EdgeResidual / Fused-MBConv blocks.1
."csp"
, "dark"
, or "cs3"
. Use "dark"
for
DarkNet stages, "csp"
for Cross Stage, and "cs3"
for Cross Stage
with only one transition conv. Defaults to None
, which defaults to
"cs3"
.(8, 16, 32)
. Defaults to 32
.(filters * bottle_ratio)
and applied to:"dark_block"
and "edge_block"
"bottleneck_block"
of each stage. Defaults to 1.0
.(stackwise_num_filters * block_ratio)
for each
stage. Defaults to 1.0
."csp"
and "cs3"
stages at different levels. Defaults to 1.0
."valid"
or
"same"
. Defaults to "valid"
.None
.True
, AveragePooling2D
is applied at the
beginning of each stage when strides == 2
. Defaults to False
.False
.True
, activation will not be applied after the
expansion convolution. Applies to Cross Stage only. Defaults to
False
.None
or str. If specified, either "channels_last"
or
"channels_first"
. The ordering of the dimensions in the inputs.
"channels_last"
corresponds to inputs with shape
(batch_size, height, width, channels)
while "channels_first"
corresponds to inputs with shape
(batch_size, channels, height, width)
. It defaults to the
image_data_format
value found in your Keras config file at
~/.keras/keras.json
. If you never set it, then it will be
"channels_last"
.(None, None, 3)
.None
or str or keras.mixed_precision.DTypePolicy
. The dtype
to use for the model's computations and weights.Examples
input_data = np.ones(shape=(8, 224, 224, 3))
# Pretrained backbone
model = keras_hub.models.CSPNetBackbone.from_preset(
"cspdarknet53_ra_imagenet"
)
model(input_data)
# Randomly initialized backbone with a custom config
model = keras_hub.models.CSPNetBackbone(
stem_filters=32,
stem_kernel_size=3,
stem_strides=1,
stackwise_depth=[1, 2, 4],
stackwise_strides=[1, 2, 2],
stackwise_num_filters=[32, 64, 128],
block_type="dark,
)
model(input_data)
from_preset
methodCSPNetBackbone.from_preset(preset, load_weights=True, **kwargs)
Instantiate a keras_hub.models.Backbone
from a model preset.
A preset is a directory of configs, weights and other file assets used
to save and load a pre-trained model. The preset
can be passed as a
one of:
'bert_base_en'
'kaggle://user/bert/keras/bert_base_en'
'hf://user/bert_base_en'
'./bert_base_en'
This constructor can be called in one of two ways. Either from the base
class like keras_hub.models.Backbone.from_preset()
, or from
a model class like keras_hub.models.GemmaBackbone.from_preset()
.
If calling from the base class, the subclass of the returning object
will be inferred from the config in the preset directory.
For any Backbone
subclass, you can run cls.presets.keys()
to list
all built-in presets available on the class.
Arguments
True
, the weights will be loaded into the
model architecture. If False
, the weights will be randomly
initialized.Examples
# Load a Gemma backbone with pre-trained weights.
model = keras_hub.models.Backbone.from_preset(
"gemma_2b_en",
)
# Load a Bert backbone with a pre-trained config and random weights.
model = keras_hub.models.Backbone.from_preset(
"bert_base_en",
load_weights=False,
)
Preset | Parameters | Description |
---|---|---|
csp_darknet_53_ra_imagenet | 26.65M | A CSP-DarkNet (Cross-Stage-Partial) image classification model pre-trained on the Randomly Augmented ImageNet 1k dataset at a 224x224 resolution. |