-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scripts for visualizing eg3d generator architecture.
- Loading branch information
1 parent
bbbab7d
commit fd33438
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import pickle | ||
import torch | ||
import io | ||
import legacy | ||
import dnnlib | ||
import json | ||
|
||
def named_params_and_buffers(module): | ||
assert isinstance(module, torch.nn.Module) | ||
return list(module.named_parameters()) + list(module.named_buffers()) | ||
|
||
def copy_params_and_buffers(src_module, dst_module, require_all=False): | ||
assert isinstance(src_module, torch.nn.Module) | ||
assert isinstance(dst_module, torch.nn.Module) | ||
src_tensors = dict(named_params_and_buffers(src_module)) | ||
for name, tensor in named_params_and_buffers(dst_module): | ||
assert (name in src_tensors) or (not require_all) | ||
if name in src_tensors: | ||
tensor.copy_(src_tensors[name].detach()).requires_grad_(tensor.requires_grad) | ||
|
||
|
||
device = torch.device('cpu') | ||
with dnnlib.util.open_url("ffhqrebalanced512-128.pkl") as f: | ||
|
||
data = legacy.load_network_pkl(f) | ||
G = data['G'].to(device)# type: ignore | ||
|
||
G_em = data['G_ema'].to(device) # type: ignore | ||
D = data['D'].to(device) | ||
# train_set = data['training_set_kwargs'].to(device) # type: ignore | ||
# augment_pipe = data['augment_pipe'].to(device) | ||
|
||
print(G) | ||
print("--------------------------------------------") | ||
print(G_em) | ||
print("--------------------------------------------") | ||
# print(D) |