Views
No views yet
dnnlib and custom CUDA kernels (such as fused upsample/downsample and upfirdn2d filters)..pt state dictionary rather than a Hugging Face compatible class, you must define the network architecture locally before loading the weights.1import torch
2import torch.nn as nn
3from huggingface_hub import hf_hub_download
4
5# 1. Define the exact Generator architecture used during training
6class CustomStyleGANGenerator(nn.Module):
7 def __init__(self):
8 super().__init__()
9 # [USER MUST PASTE THE GENERATOR CLASS CODE HERE]
10 pass
11
12 def forward(self, z):
13 # [USER MUST PASTE THE FORWARD PASS HERE]
14 pass
15
16# 2. Download and load the weights
17repo_id = "Pradeep016/StyleGAN-FFHQ"
18filename = "styleGAN_Model.pt"
19
20weights_path = hf_hub_download(repo_id=repo_id, filename=filename)
21
22# 3. Instantiate and load
23device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
24generator = CustomStyleGANGenerator().to(device)
25generator.load_state_dict(torch.load(weights_path, map_location=device))
26generator.eval()
27
28# 4. Generate a sample (example using latent dim of 512)
29with torch.no_grad():
30 z = torch.randn(1, 512).to(device)
31 # Apply truncation psi=0.7 manually if required by your implementation
32 output_image = generator(z)
33