(G)
| 58 | |
| 59 | |
| 60 | def register_hook(G): |
| 61 | # Create a new attribute called "activations" for the Generator class |
| 62 | # This will be a list of activations from each layer |
| 63 | G.__setattr__("activations", None) |
| 64 | |
| 65 | # Forward hook to collect features |
| 66 | def hook(module, input, output): |
| 67 | G.activations = output |
| 68 | |
| 69 | # Apply the hook to the 7th layer (256x256) |
| 70 | for i, (name, module) in enumerate(G.synthesis.named_children()): |
| 71 | if i == 6: |
| 72 | print("Registering hook for:", name) |
| 73 | module.register_forward_hook(hook) |
| 74 | return G |
| 75 | |
| 76 | |
| 77 | def generate_W( |
no test coverage detected