Are you the author?
GPU deploy isn't supported for this model type.
1import torch
2from dcgan import Generator
3
4# Load the configuration
5config = {
6 "latent_dim": 100,
7 "ngf": 64,
8 "nc": 3
9}
10
11# Initialize the generator
12generator = Generator(config)
13
14# Load the trained weights
15model_path = "./dcgan_celeba.pth"
16
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)