-
I have a question about understanding the structure and functionality of backbone stages. I want to know how to identify which layers belong to each stage. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 6 replies
-
@jawi289o you can use FX to extract graph node names, split them based on feature info module names def split_nodes(nodes, split_names):
"""Split nodes at exact match if found, otherwise at last prefix match."""
result = []
start = 0
for split in split_names:
# First try exact match
exact_matches = [i for i, node in enumerate(nodes) if node == split]
if exact_matches:
# If exact match found, split at first exact match
end = exact_matches[0] + 1
else:
# Otherwise, split at last prefix match
prefix_matches = [i for i, node in enumerate(nodes) if node.startswith(split)]
if not prefix_matches:
raise ValueError(f"No nodes found matching '{split}'")
end = max(prefix_matches) + 1
# Add segment and update start
if end > start: # Only add non-empty segments
result.append(nodes[start:end])
start = end
# Add remaining nodes if any
if start < len(nodes):
result.append(nodes[start:])
return result
feature_model = timm.create_model(model_name, features_only=True)
feat_names = feature_model.feature_info.module_name()
model = timm.create_model(model_name)
nodes = timm.models.get_graph_node_names(model)
split_nodes(nodes, feat_names) |
Beta Was this translation helpful? Give feedback.
@jawi289o the model returned by features_only give you a model that produces the 5 feature maps you'd want to use with a unet, that is the whole point. I don't know why you'd want to do anything else if that is your goal.
There are 7 blocks but 2 of them are stride=1, the outputs for features_only are the deepest at each respective resolution. Beyond what features_only=True provides you, you can hack the models however you feel appropriate.. make a manual forward, etc but as I said, that's what features_only=True is doing for you, in a model agnostic way.