Skip to content

Commit 7f2ee56

Browse files
Fix from_config to prevent stripping architectural parameters
1 parent c9d47ec commit 7f2ee56

1 file changed

Lines changed: 7 additions & 35 deletions

File tree

keras_hub/src/models/cspnet/cspnet_backbone.py

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -252,43 +252,15 @@ def from_config(cls, config):
252252

253253
if "stackwise_channels" in config:
254254
config["stackwise_num_filters"] = config.pop("stackwise_channels")
255+
config.setdefault("expand_ratio", 1.0)
256+
config.setdefault("bottle_ratio", 0.5)
257+
config.setdefault("stage_type", "cs3")
255258

256-
depths = config.get("stackwise_depth", [])
257-
num_stages = len(depths)
258-
259-
if "stackwise_num_filters" not in config:
260-
config["stackwise_num_filters"] = [64, 128, 256, 512]
261-
262-
if "stackwise_strides" not in config:
263-
config["stackwise_strides"] = [2] * num_stages
264-
265-
if "stem_filters" not in config:
266-
filters = config.get("stackwise_num_filters")
267-
config["stem_filters"] = filters[0] // 2 if filters else 32
268-
269-
config.setdefault("stem_kernel_size", 3)
270-
config.setdefault("stem_strides", 2)
271-
config.setdefault("block_type", "dark_block")
272-
config.setdefault("stage_type", "cs3")
273-
config.setdefault("expand_ratio", 1.0)
274-
config.setdefault("bottle_ratio", 0.5)
275-
276-
valid_keys = [
277-
"stackwise_num_filters",
278-
"stackwise_depth",
279-
"stackwise_strides",
280-
"stem_filters",
281-
"stem_kernel_size",
282-
"stem_strides",
283-
"block_type",
284-
"stage_type",
285-
"expand_ratio",
286-
"bottle_ratio",
287-
"name",
288-
"trainable",
289-
]
259+
if "use_depthwise" in config:
260+
if config.pop("use_depthwise"):
261+
config["block_type"] = "depthwise_dark_block"
290262

291-
return cls(**{k: v for k, v in config.items() if k in valid_keys})
263+
return cls(**config)
292264

293265

294266
def bottleneck_block(

0 commit comments

Comments
 (0)