Skip to content

Commit e20bcc5

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

1 file changed

Lines changed: 15 additions & 44 deletions

File tree

keras_hub/src/models/cspnet/cspnet_backbone.py

Lines changed: 15 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -242,53 +242,24 @@ def get_config(self):
242242
}
243243
)
244244
return config
245-
246245
@classmethod
247246
def from_config(cls, config):
248-
if "config" in config and isinstance(config["config"], dict):
249-
config = config["config"]
250-
251-
config = dict(config)
252-
253-
if "stackwise_channels" in config:
254-
config["stackwise_num_filters"] = config.pop("stackwise_channels")
255-
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-
]
247+
if "config" in config and isinstance(config["config"], dict):
248+
config = config["config"]
249+
250+
config = dict(config)
251+
252+
if "stackwise_channels" in config:
253+
config["stackwise_num_filters"] = config.pop("stackwise_channels")
254+
config.setdefault("expand_ratio", 1.0)
255+
config.setdefault("bottle_ratio", 0.5)
256+
config.setdefault("stage_type", "cs3")
257+
258+
if "use_depthwise" in config:
259+
if config.pop("use_depthwise"):
260+
config["block_type"] = "depthwise_dark_block"
290261

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

293264

294265
def bottleneck_block(

0 commit comments

Comments
 (0)