-
Notifications
You must be signed in to change notification settings - Fork 6.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Not able to load a pre trained weight that I have used for training of custom data. #1621
Comments
Was it CycleGAN or Pix2pix model? To test it on a different data set, you could use this command as an example: python test.py --dataroot directory, e.g. (/content/data/A) --name model_name --model test --netD n_layers --n_layers_D 3 --netG=unet_256 --norm=instance --direction AtoB --dataset_mode single --preprocess none --input_nc 1 --output_nc 3 --ndf 64 --ngf 64 --num_test 512 Make sure to replace the parameters with the same ones you used for training of the model (netD, n_layers, netG, ndf, ngf, etc.) |
Hey @JustinasLekavicius thank you for replying to my issue. I am using CycleGAN for training purpose is to denoise the image. However I have the pre trained weight which works well when it is used with the python command line code But when I try the same thing by creating a class to load the model and give image as input and get the output as denoised image, I am unable to do it. However if I try to load the model the prediction or the testing output image which is denoised image isn't getting generated accurately but it's happening in with the above python command code. heartily thank you in advance |
import torch Define the generator modelgenerator = define_G(input_nc=3, output_nc=3, ngf=64, netG='resnet_9blocks', norm='instance', use_dropout=False,init_type='normal',init_gain=0.02) Load the pre-trained weights from a saved checkpointgenerator_checkpoint_path = 'latest_net_G.pth' Load the generator state_dictgenerator.load_state_dict(checkpoint, strict=False) Set the model to evaluation mode (important if using dropout during training)generator.eval() Load your input imageinput_image_path = 'nt6.jpg' Resize the input image to the expected sizeinput_image = input_image.resize((512, 512)) Convert the input image to a PyTorch tensorinput_tensor = transforms.ToTensor()(input_image).unsqueeze(0) # Add batch dimension Move the input tensor to the GPU if availableif torch.cuda.is_available(): Move the generator to the same device as the input tensorgenerator = generator.to(input_tensor.device) Generate the output imagewith torch.no_grad(): Move the output tensor to the CPU if necessaryoutput_tensor = output_tensor.cpu() Convert the output tensor to a PIL imageoutput_image = transforms.ToPILImage()(output_tensor.squeeze(0)) Display the generated imagedisplay(output_image) Save the generated imageoutput_image.save('generated_image.jpg') this is my code |
Hi AGRocky, To help troubleshoot your CycleGAN model issue, could you provide:
These details will help in accurately replicating the issue and providing a solution. Thanks! |
Hey Guys, Please hear out.
I have trained a model and have a pre trained weight but not able to load that model to test it on different set of images which i have prepared. please help me out on this one. It would be deeply appretiated.
thanks in advance
The text was updated successfully, but these errors were encountered: