mobileone
MobileOne
Overview
MobileOne is a fully convolutional neural network designed to have minimal latency when running in mobile/edge devices. The architecture consists of a series of depthwise separable convolutions and squeeze and excitation (SE) blocks. The network also uses standard batch normalization and ReLU activations that can be easily fused into the convolutional layers. Lastly, the network uses over-parameterized branches to improve training, yet can be merged into a single branch during inference.
For more info, refer to the original paper MobileOne: An Improved One millisecond Mobile Backbone.
Classes:
-
MobileOneParams
–MobileOne parameters
-
MobileOneBlockParams
–MobileOne block parameters
-
MobileOneModel
–Helper class to generate model from parameters
Functions:
-
mobileone_block
–MobileOne block
-
mobileone_layer
–MobileOne layer
Additions
The MobileOne architecture has been modified to allow the following:
- Enable 1D and 2D variants.
- Enable dilated convolutions.
Usage
import keras
from neuralspot_edge.models import MobileOne, MobileOneParams, MobileOneBlockParams
inputs = keras.Input(shape=(800, 1), name="inputs")
model = MobileOne.model_from_params(
x=inputs,
params=MobileOneParams(
input_filters=24,
input_kernel_size=(1, 7),
input_strides=(1, 2),
blocks=[
MobileOneBlockParams(filters=32, depth=2, kernel_size=(1, 7), strides=(1, 2), se_ratio=2, se_depth=2, num_conv_branches=2)
],
include_top=True,
model_name="MobileOne",
),
)
model.summary()
Classes
MobileOneBlockParams
MobileOne block parameters
Attributes:
-
filters
(int
) –Number of filters
-
depth
(int
) –Layer depth
-
kernel_size
(int | tuple[int, int]
) –Kernel size
-
strides
(int | tuple[int, int]
) –Stride size
-
padding
(int | tuple[int, int]
) –Padding size
-
se_ratio
(float
) –Squeeze Excite ratio
-
se_depth
(int
) –Depth length to apply SE
-
num_conv_branches
(int
) –Number of conv branches
-
activation
(str
) –Activation function
MobileOneParams
MobileOne parameters
Attributes:
-
blocks
(list[MobileOneBlockParams]
) –MobileOne blocks
-
input_filters
(int
) –Input filters
-
input_kernel_size
(int | tuple[int, int]
) –Input kernel size
-
input_strides
(int | tuple[int, int]
) –Input stride
-
input_padding
(int | tuple[int, int]
) –Input padding
-
include_top
(bool
) –Include top
-
output_activation
(str | None
) –Output activation
-
dropout
(float
) –Dropout rate
-
name
(str
) –Model name
MobileOneModel
Helper class to generate model from parameters
Functions
layer_from_params
staticmethod
layer_from_params(inputs: keras.Input, params: MobileOneParams | dict, num_classes: int | None = None)
Create layer from parameters
Source code in neuralspot_edge/models/mobileone.py
model_from_params
staticmethod
model_from_params(inputs: keras.Input, params: MobileOneParams | dict, num_classes: int | None = None)
Create model from parameters
Source code in neuralspot_edge/models/mobileone.py
Functions
mobileone_block
mobileone_block(output_filters: int, kernel_size: int | tuple[int, int] = 3, strides: int | tuple[int, int] = 1, padding: int | tuple[int, int] = 0, groups: int = 1, dilation: int = 1, inference_mode: bool = False, se_ratio: int = 0, num_conv_branches: int = 1, activation: str = 'relu6', name: str | None = None) -> keras.Layer
MBConv block w/ expansion and SE
Parameters:
-
output_filters
(int
) –Number of output filter channels
-
kernel_size
(int | tuple[int, int]
, default:3
) –Kernel size. Defaults to 3.
-
strides
(int | tuple[int, int]
, default:1
) –Stride length. Defaults to 1.
-
se_ratio
(float
, default:0
) –SE ratio. Defaults to 8.
-
name
(str | None
, default:None
) –Block name. Defaults to None.
Returns:
-
Layer
–keras.Layer: Functional layer
Source code in neuralspot_edge/models/mobileone.py
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
mobileone_layer
mobileone_layer(x: keras.KerasTensor, params: MobileOneParams, num_classes: int | None = None, inference_mode: bool = False) -> keras.KerasTensor
Create MobileOne TF functional model
Parameters:
-
x
(KerasTensor
) –Input tensor
-
params
(MobileOneParams
) –Model parameters.
-
num_classes
(int
, default:None
) –Number of classes.
Returns:
-
KerasTensor
–keras.KerasTensor: Output tensor
Source code in neuralspot_edge/models/mobileone.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
|