Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactoring #8

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions simlarity/feature_extraction.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,7 @@ def _warn_graph_differences(train_tracer: NodePathTracer, eval_tracer: NodePathT

def _get_leaf_modules_for_ops() -> List[type]:
members = inspect.getmembers(torchvision.ops)
result = []
for _, obj in members:
if inspect.isclass(obj) and issubclass(obj, torch.nn.Module):
result.append(obj)
return result
return [obj for _, obj in members if inspect.isclass(obj) and issubclass(obj, torch.nn.Module)]


def get_graph_node_names(
Expand Down Expand Up @@ -496,10 +492,7 @@ def to_strdict(n) -> Dict[str, str]:
)

# Remove existing output nodes (train mode)
orig_output_nodes = []
for n in reversed(graph_module.graph.nodes):
if n.op == "output":
orig_output_nodes.append(n)
orig_output_nodes = [n for n in reversed(graph_module.graph.nodes) if n.op == "output"]
assert len(orig_output_nodes)
for n in orig_output_nodes:
graph_module.graph.erase_node(n)
Expand Down Expand Up @@ -654,19 +647,13 @@ def to_strdict(n) -> Dict[str, str]:
)

# Remove existing output nodes (train mode)
orig_output_nodes = []
for n in reversed(graph_module.graph.nodes):
if n.op == "output":
orig_output_nodes.append(n)
orig_output_nodes = [n for n in reversed(graph_module.graph.nodes) if n.op == "output"]
assert len(orig_output_nodes)
for n in orig_output_nodes:
graph_module.graph.erase_node(n)

# Remove existing input nodes (train mode)
orig_input_nodes = []
for n in reversed(graph_module.graph.nodes):
if n.op == "placeholder":
orig_input_nodes.append(n)
orig_input_nodes = [n for n in reversed(graph_module.graph.nodes) if n.op == "placeholder"]
assert len(orig_input_nodes)
# for n in orig_input_nodes:
# n.users=()
Expand Down