How to use from_args method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

mobilenet_edgetpu_v2_model_blocks.py

Source:mobilenet_edgetpu_v2_model_blocks.py Github

copy

Full Screen

...84 fused_project = False85 conv_type = 'group'86 else:87 raise NotImplementedError(f'Unsupported IBN type {block_op_type.type}.')88 return cls.from_args(89 input_filters=input_filters,90 output_filters=output_filters,91 kernel_size=block_search_config.kernel_size,92 num_repeat=num_repeat,93 expand_ratio=block_search_config.expand_ratio,94 strides=(block_search_config.stride, block_search_config.stride),95 se_ratio=se_ratio,96 id_skip=id_skip,97 fused_expand=fused_expand,98 fused_project=fused_project,99 conv_type=conv_type,100 group_size=block_search_config.group_size)101@dataclasses.dataclass102class BlockGroupConfig(base_config.Config):103 """Config for group of blocks that share the same filter size."""104 blocks: List[BlockSearchConfig] = dataclasses.field(default_factory=list)105 filters: int = 64106def _default_mobilenet_edgetpu_v2_topology():107 return [108 # Block Group 0109 BlockGroupConfig(110 blocks=[111 # BlockSearchConfig: op_type, kernel_size, expand_ratio, stride112 BlockSearchConfig.from_args(113 BlockType.from_args('ibn_fused'), 3, 1, 1),114 ],115 filters=24),116 # Block Group 1117 BlockGroupConfig(118 blocks=[119 BlockSearchConfig.from_args(120 BlockType.from_args('ibn_fused'), 3, 8, 2),121 BlockSearchConfig.from_args(122 BlockType.from_args('ibn_fused_grouped'), 3, 4, 1),123 ],124 filters=48),125 # Block Group 2126 BlockGroupConfig(127 blocks=[128 BlockSearchConfig.from_args(129 BlockType.from_args('ibn_fused'), 3, 8, 2),130 BlockSearchConfig.from_args(131 BlockType.from_args('ibn_fused_grouped'), 3, 4, 1),132 BlockSearchConfig.from_args(133 BlockType.from_args('ibn_fused'), 3, 4, 1),134 BlockSearchConfig.from_args(135 BlockType.from_args('ibn_fused_grouped'), 3, 4, 1),136 ],137 filters=64),138 # Block Group 3139 BlockGroupConfig(140 blocks=[141 BlockSearchConfig.from_args(142 BlockType.from_args('ibn_fused'), 3, 8, 2),143 BlockSearchConfig.from_args(144 BlockType.from_args('ibn_dw'), 3, 4, 1),145 BlockSearchConfig.from_args(146 BlockType.from_args('ibn_dw'), 3, 4, 1),147 BlockSearchConfig.from_args(148 BlockType.from_args('ibn_dw'), 3, 4, 1),149 ],150 filters=128),151 # Block Group 4152 BlockGroupConfig(153 blocks=[154 BlockSearchConfig.from_args(155 BlockType.from_args('ibn_dw'), 3, 8, 1),156 BlockSearchConfig.from_args(157 BlockType.from_args('ibn_dw'), 3, 4, 1),158 BlockSearchConfig.from_args(159 BlockType.from_args('ibn_dw'), 3, 4, 1),160 BlockSearchConfig.from_args(161 BlockType.from_args('ibn_dw'), 3, 4, 1),162 ],163 filters=160),164 # Block Group 5165 BlockGroupConfig(166 blocks=[167 BlockSearchConfig.from_args(168 BlockType.from_args('ibn_dw'), 3, 8, 2),169 BlockSearchConfig.from_args(170 BlockType.from_args('ibn_dw'), 3, 4, 1),171 BlockSearchConfig.from_args(172 BlockType.from_args('ibn_dw'), 3, 4, 1),173 BlockSearchConfig.from_args(174 BlockType.from_args('ibn_dw'), 3, 4, 1),175 ],176 filters=192),177 # Block Group 6178 BlockGroupConfig(179 blocks=[180 BlockSearchConfig.from_args(181 BlockType.from_args('ibn_dw'), 3, 8, 1),182 ],183 filters=256),184 ]185@dataclasses.dataclass186class TopologyConfig(base_config.Config):187 """Config for model topology as a collection of BlockGroupConfigs."""188 block_groups: List[BlockGroupConfig] = dataclasses.field(189 default_factory=_default_mobilenet_edgetpu_v2_topology)190@dataclasses.dataclass191class ModelConfig(base_config.Config):192 """Default Config for MobilenetEdgeTPUV2."""193 width_coefficient: float = 1.0194 depth_coefficient: float = 1.0195 resolution: Union[int, Tuple[int, int]] = 224196 dropout_rate: float = 0.1197 stem_base_filters: int = 64198 stem_kernel_size: int = 5199 top_base_filters: int = 1280200 blocks: Tuple[BlockConfig, ...] = (201 # (input_filters, output_filters, kernel_size, num_repeat,202 # expand_ratio, strides, se_ratio, id_skip, fused_conv, conv_type)203 # pylint: disable=bad-whitespace204 BlockConfig.from_args(205 stem_base_filters, 24, 3, 1, 1, (1, 1), conv_type='full'),206 BlockConfig.from_args(207 24, 48, 3, 1, 8, (2, 2), fused_expand=True, conv_type='full'),208 BlockConfig.from_args(209 48, 48, 3, 1, 4, (1, 1), fused_expand=True, conv_type='group'),210 BlockConfig.from_args(211 48, 64, 3, 1, 8, (2, 2), fused_expand=True, conv_type='full'),212 BlockConfig.from_args(213 64, 64, 3, 1, 4, (1, 1), fused_expand=True, conv_type='group'),214 BlockConfig.from_args(215 64, 64, 3, 1, 4, (1, 1), fused_expand=True, conv_type='full'),216 BlockConfig.from_args(217 64, 64, 3, 1, 4, (1, 1), fused_expand=True, conv_type='group'),218 BlockConfig.from_args(219 64, 128, 3, 1, 8, (2, 2), fused_expand=True, conv_type='full'),220 BlockConfig.from_args(128, 128, 3, 3, 4, (1, 1)),221 BlockConfig.from_args(128, 160, 3, 1, 8, (1, 1)),222 BlockConfig.from_args(160, 160, 3, 3, 4, (1, 1)),223 BlockConfig.from_args(160, 192, 5, 1, 8, (2, 2)),224 BlockConfig.from_args(192, 192, 5, 3, 4, (1, 1)),225 BlockConfig.from_args(192, 256, 5, 1, 8, (1, 1)),226 # pylint: enable=bad-whitespace227 )228 activation: str = 'relu'229 batch_norm: str = 'default'230 bn_momentum: float = 0.99231 bn_epsilon: float = 1e-3232 # While the original implementation used a weight decay of 1e-5,233 # tf.nn.l2_loss divides it by 2, so we halve this to compensate in Keras234 weight_decay: float = 5e-6235 drop_connect_rate: float = 0.1236 depth_divisor: int = 8237 min_depth: Optional[int] = None238 # No Squeeze/Excite for MobilenetEdgeTPUV2239 use_se: bool = False240 input_channels: int = 3241 num_classes: int = 1001242 model_name: str = 'mobilenet_edgetpu_v2'243 rescale_input: bool = False244 data_format: str = 'channels_last'245 dtype: str = 'float32'246 # The number of filters in each group. HW arch dependent.247 group_base_size: int = 64248 backbone_only: bool = False249 features_as_dict: bool = False250def mobilenet_edgetpu_v2_base(251 width_coefficient: float = 1.0,252 depth_coefficient: float = 1.0,253 stem_base_filters: int = 64,254 stem_kernel_size: int = 5,255 top_base_filters: int = 1280,256 group_base_size: int = 64,257 dropout_rate: float = 0.2,258 drop_connect_rate: float = 0.1,259 filter_size_overrides: Optional[Dict[int, int]] = None,260 block_op_overrides: Optional[Dict[int, Dict[int, Dict[str, Any]]]] = None,261 block_group_overrides: Optional[Dict[int, Dict[str, Any]]] = None):262 """Creates MobilenetEdgeTPUV2 ModelConfig based on tuning parameters."""263 config = ModelConfig()264 param_overrides = {265 'width_coefficient': width_coefficient,266 'depth_coefficient': depth_coefficient,267 'stem_base_filters': stem_base_filters,268 'stem_kernel_size': stem_kernel_size,269 'top_base_filters': top_base_filters,270 'group_base_size': group_base_size,271 'dropout_rate': dropout_rate,272 'drop_connect_rate': drop_connect_rate273 }274 config = config.replace(**param_overrides)275 topology_config = TopologyConfig()276 if filter_size_overrides:277 for group_id in filter_size_overrides:278 topology_config.block_groups[group_id].filters = filter_size_overrides[279 group_id]280 if block_op_overrides:281 for group_id in block_op_overrides:282 for block_id in block_op_overrides[group_id]:283 replaced_block = topology_config.block_groups[group_id].blocks[284 block_id].replace(**block_op_overrides[group_id][block_id])285 topology_config.block_groups[group_id].blocks[block_id] = replaced_block286 if block_group_overrides:287 for group_id in block_group_overrides:288 replaced_group = topology_config.block_groups[group_id].replace(289 **block_group_overrides[group_id])290 topology_config.block_groups[group_id] = replaced_group291 blocks = ()292 input_filters = stem_base_filters293 for group in topology_config.block_groups:294 for block_search in group.blocks:295 if block_search.op_type != BlockType.skip:296 block = BlockConfig.from_search_config(297 input_filters=input_filters,298 output_filters=group.filters,299 block_search_config=block_search)300 blocks += (block,)301 # Set input filters for the next block302 input_filters = group.filters303 config = config.replace(blocks=blocks)304 return config305def autoseg_edgetpu_backbone_base(306 width_coefficient: float = 1.0,307 depth_coefficient: float = 1.0,308 stem_base_filters: int = 64,309 stem_kernel_size: int = 5,310 top_base_filters: int = 1280,311 group_base_size: int = 64,312 dropout_rate: float = 0.2,313 drop_connect_rate: float = 0.1,314 blocks_overrides: Optional[Tuple[BlockConfig, ...]] = None):315 """Creates a edgetpu ModelConfig based on search on segmentation."""316 config = ModelConfig()317 config.depth_divisor = 4318 param_overrides = {319 'width_coefficient': width_coefficient,320 'depth_coefficient': depth_coefficient,321 'stem_base_filters': stem_base_filters,322 'stem_kernel_size': stem_kernel_size,323 'top_base_filters': top_base_filters,324 'group_base_size': group_base_size,325 'dropout_rate': dropout_rate,326 'drop_connect_rate': drop_connect_rate,327 }328 if blocks_overrides:329 param_overrides['blocks'] = blocks_overrides330 config = config.replace(**param_overrides)331 return config332def autoseg_edgetpu_backbone_s() -> ModelConfig:333 """AutoML searched model with 2.5ms target simulated latency."""334 stem_base_filters = 32335 stem_kernel_size = 3336 top_base_filters = 1280337 blocks = (338 # (input_filters, output_filters, kernel_size, num_repeat,339 # expand_ratio, strides, se_ratio, id_skip, fused_conv, conv_type)340 # pylint: disable=bad-whitespace341 BlockConfig.from_args(342 stem_base_filters,343 12,344 3,345 1,346 1, (1, 1),347 fused_expand=True,348 conv_type='full'),349 BlockConfig.from_args(350 12, 36, 3, 1, 6, (2, 2), fused_expand=True, conv_type='full'),351 BlockConfig.from_args(36, 18, 5, 1, 3, (1, 1)),352 BlockConfig.from_args(353 18, 60, 5, 1, 6, (2, 2), fused_expand=True, conv_type='full'),354 BlockConfig.from_args(60, 60, 3, 1, 3, (1, 1)),355 BlockConfig.from_args(60, 120, 5, 1, 6, (2, 2)),356 BlockConfig.from_args(120, 120, 3, 1, 3, (1, 1)),357 BlockConfig.from_args(120, 120, 5, 1, 6, (1, 1)),358 BlockConfig.from_args(120, 112, 3, 1, 6, (1, 1)),359 BlockConfig.from_args(112, 112, 5, 2, 6, (1, 1)),360 BlockConfig.from_args(112, 112, 5, 1, 1, (2, 2), id_skip=False),361 BlockConfig.from_args(362 112, 192, 1, 1, 6, (1, 1), fused_expand=True, id_skip=False),363 BlockConfig.from_args(192, 192, 5, 1, 1, (1, 1), id_skip=False),364 BlockConfig.from_args(365 192, 96, 1, 1, 6, (1, 1), fused_expand=True, id_skip=False),366 BlockConfig.from_args(96, 96, 5, 1, 3, (1, 1)),367 BlockConfig.from_args(96, 96, 5, 1, 1, (1, 1), id_skip=False),368 BlockConfig.from_args(369 96, 192, 1, 1, 6, (1, 1), fused_expand=True, id_skip=False),370 BlockConfig.from_args(192, 192, 5, 1, 1, (1, 1), id_skip=False),371 BlockConfig.from_args(372 192, 160, 1, 1, 3, (1, 1), fused_expand=True, id_skip=False),373 # pylint: enable=bad-whitespace374 )375 return autoseg_edgetpu_backbone_base(376 stem_base_filters=stem_base_filters,377 stem_kernel_size=stem_kernel_size,378 top_base_filters=top_base_filters,379 blocks_overrides=blocks,380 dropout_rate=0.2,381 drop_connect_rate=0.2)382def autoseg_edgetpu_backbone_xs() -> ModelConfig:383 """AutoML searched model with 2ms target simulated latency."""384 stem_base_filters = 32385 stem_kernel_size = 3386 top_base_filters = 1280387 blocks = (388 # (input_filters, output_filters, kernel_size, num_repeat,389 # expand_ratio, strides, se_ratio, id_skip, fused_conv, conv_type)390 # pylint: disable=bad-whitespace391 BlockConfig.from_args(392 stem_base_filters,393 12,394 3,395 1,396 1, (1, 1),397 fused_expand=True,398 conv_type='full'),399 BlockConfig.from_args(400 12, 24, 3, 1, 6, (2, 2), fused_expand=True, conv_type='full'),401 BlockConfig.from_args(24, 24, 3, 1, 3, (1, 1)),402 BlockConfig.from_args(403 24, 60, 3, 1, 3, (2, 2), fused_expand=True, conv_type='full'),404 BlockConfig.from_args(60, 40, 3, 1, 6, (1, 1)),405 BlockConfig.from_args(40, 40, 5, 1, 3, (2, 2)),406 BlockConfig.from_args(40, 40, 3, 1, 6, (1, 1)),407 BlockConfig.from_args(408 40, 120, 3, 1, 6, (1, 1), fused_expand=True, conv_type='full'),409 BlockConfig.from_args(120, 168, 3, 1, 6, (1, 1)),410 BlockConfig.from_args(168, 84, 5, 1, 6, (1, 1)),411 BlockConfig.from_args(84, 84, 5, 1, 3, (1, 1)),412 BlockConfig.from_args(84, 84, 5, 1, 1, (2, 2), id_skip=False),413 BlockConfig.from_args(414 84, 288, 1, 1, 6, (1, 1), fused_expand=True, id_skip=False),415 BlockConfig.from_args(288, 288, 5, 1, 1, (1, 1), id_skip=False),416 BlockConfig.from_args(417 288, 96, 1, 1, 3, (1, 1), fused_expand=True, id_skip=False),418 BlockConfig.from_args(96, 96, 5, 1, 1, (1, 1), id_skip=False),419 BlockConfig.from_args(420 96, 96, 1, 1, 6, (1, 1), fused_expand=True, id_skip=False),421 BlockConfig.from_args(96, 96, 5, 1, 1, (1, 1), id_skip=False),422 BlockConfig.from_args(423 96, 96, 1, 1, 6, (1, 1), fused_expand=True, id_skip=False),424 BlockConfig.from_args(96, 480, 5, 1, 3, (1, 1)),425 # pylint: enable=bad-whitespace426 )427 return autoseg_edgetpu_backbone_base(428 stem_base_filters=stem_base_filters,429 stem_kernel_size=stem_kernel_size,430 top_base_filters=top_base_filters,431 blocks_overrides=blocks,432 dropout_rate=0.2,433 drop_connect_rate=0.2)434def autoseg_edgetpu_backbone_m() -> ModelConfig:435 """AutoML searched model with 3ms target simulated latency."""436 stem_base_filters = 32437 stem_kernel_size = 3438 top_base_filters = 1280439 blocks = (440 # (input_filters, output_filters, kernel_size, num_repeat,441 # expand_ratio, strides, se_ratio, id_skip, fused_conv, conv_type)442 # pylint: disable=bad-whitespace443 BlockConfig.from_args(stem_base_filters, 16, 5, 1, 1, (1, 1)),444 BlockConfig.from_args(445 16, 36, 3, 1, 6, (2, 2), fused_expand=True, conv_type='full'),446 BlockConfig.from_args(36, 36, 3, 1, 3, (1, 1)),447 BlockConfig.from_args(448 36, 60, 3, 1, 6, (2, 2), fused_expand=True, conv_type='full'),449 BlockConfig.from_args(60, 60, 3, 1, 6, (1, 1)),450 BlockConfig.from_args(451 60, 120, 5, 1, 6, (2, 2), fused_expand=True, conv_type='full'),452 BlockConfig.from_args(120, 120, 5, 1, 6, (1, 1)),453 BlockConfig.from_args(454 120, 80, 3, 1, 6, (1, 1), fused_expand=True, conv_type='full'),455 BlockConfig.from_args(80, 168, 3, 1, 6, (1, 1)),456 BlockConfig.from_args(168, 168, 5, 1, 6, (1, 1)),457 BlockConfig.from_args(168, 168, 5, 1, 1, (1, 1), id_skip=False),458 BlockConfig.from_args(459 168, 168, 1, 1, 6, (1, 1), fused_expand=True, id_skip=False),460 BlockConfig.from_args(168, 168, 3, 1, 1, (2, 2), id_skip=False),461 BlockConfig.from_args(462 168, 192, 1, 1, 3, (1, 1), fused_expand=True, id_skip=False),463 BlockConfig.from_args(192, 192, 5, 1, 1, (1, 1), id_skip=False),464 BlockConfig.from_args(465 192, 288, 1, 1, 6, (1, 1), fused_expand=True, id_skip=False),466 BlockConfig.from_args(288, 288, 5, 1, 1, (1, 1), id_skip=False),467 BlockConfig.from_args(468 288, 96, 1, 1, 6, (1, 1), fused_expand=True, id_skip=False),469 BlockConfig.from_args(96, 96, 5, 1, 1, (1, 1), id_skip=False),470 BlockConfig.from_args(471 96, 192, 1, 1, 3, (1, 1), fused_expand=True, id_skip=False),472 BlockConfig.from_args(192, 192, 5, 1, 1, (1, 1), id_skip=False),473 BlockConfig.from_args(474 192, 320, 1, 1, 3, (1, 1), fused_expand=True, id_skip=False),475 # pylint: enable=bad-whitespace476 )477 return autoseg_edgetpu_backbone_base(478 stem_base_filters=stem_base_filters,479 stem_kernel_size=stem_kernel_size,480 top_base_filters=top_base_filters,481 blocks_overrides=blocks,482 dropout_rate=0.3,483 drop_connect_rate=0.3)484def mobilenet_edgetpu_v2_tiny() -> ModelConfig:485 """MobilenetEdgeTPUV2 tiny model config."""486 stem_base_filters = 32487 stem_kernel_size = 5488 top_base_filters = 1280489 filter_sizes = [16, 32, 48, 80, 112, 160, 192]490 filter_size_overrides = {491 k: v for (k, v) in zip(range(len(filter_sizes)), filter_sizes)492 }493 block_op_overrides = {494 2: {495 0: {'op_type': BlockType.from_args('ibn_fused_grouped')},496 2: {'op_type': BlockType.from_args('ibn_fused_grouped')},497 },498 3: {499 0: {'op_type': BlockType.from_args('ibn_fused_grouped')},500 }501 }502 return mobilenet_edgetpu_v2_base(503 stem_base_filters=stem_base_filters,504 stem_kernel_size=stem_kernel_size,505 top_base_filters=top_base_filters,506 filter_size_overrides=filter_size_overrides,507 block_op_overrides=block_op_overrides,508 dropout_rate=0.05,509 drop_connect_rate=0.05)510def mobilenet_edgetpu_v2_xs() -> ModelConfig:511 """MobilenetEdgeTPUV2 extra small model config."""512 stem_base_filters = 32513 stem_kernel_size = 5...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run dbt-osmosis automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful