Views
No views yet
1from huggingface_hub import hf_hub_download
2
3# Download the model checkpoint from the hub
4checkpoint_path = hf_hub_download(repo_id="hussamalafandi/cGAN-MNIST", filename="generator.pth")1import torch
2from c_gan import Generator
3
4# Load the configuration
5config = {
6 "latent_dim": 100,
7 "ngf": 64,
8 "nc": 1,
9 "num_classes": 10,
10 "embed_dim": 50
11}
12
13# Initialize the generator
14generator = Generator(config)
15
16# Load the downloaded checkpoint (or a local path)
17generator.load_state_dict(torch.load(checkpoint_path, map_location=torch.device('cuda' if torch.cuda.is_available() else 'cpu')))
18
19# Set the model to evaluation mode
20generator.eval()
21
22# Example: Generate an image
23latent_vector = torch.randn(1, config["latent_dim"], 1, 1) # Batch size of 1
24
25if torch.cuda.is_available():
26 latent_vector = latent_vector.cuda()
27 generator = generator.cuda()
28
29generated_image = generator(latent_vector, torch.tensor([7])) # Example label: 7