Comments (4)
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.)
from pytorch-cyclegan-and-pix2pix.
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
"python test.py --dataroot directory, e.g. (/content/data/A) --name model_name --model test..."
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.
please help me with this
heartily thank you in advance
from pytorch-cyclegan-and-pix2pix.
import torch
from models.networks import define_G
from PIL import Image
from torchvision import transforms
from IPython.display import display
Define the generator model
generator = 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 checkpoint
generator_checkpoint_path = 'latest_net_G.pth'
checkpoint = torch.load(generator_checkpoint_path, map_location=torch.device('cuda' if torch.cuda.is_available() else 'cpu'))
Load the generator state_dict
generator.load_state_dict(checkpoint, strict=False)
Set the model to evaluation mode (important if using dropout during training)
generator.eval()
Load your input image
input_image_path = 'nt6.jpg'
input_image = Image.open(input_image_path).convert('RGB')
Resize the input image to the expected size
input_image = input_image.resize((512, 512))
Convert the input image to a PyTorch tensor
input_tensor = transforms.ToTensor()(input_image).unsqueeze(0) # Add batch dimension
Move the input tensor to the GPU if available
if torch.cuda.is_available():
input_tensor = input_tensor.to('cuda')
Move the generator to the same device as the input tensor
generator = generator.to(input_tensor.device)
Generate the output image
with torch.no_grad():
output_tensor = generator(input_tensor)
Move the output tensor to the CPU if necessary
output_tensor = output_tensor.cpu()
Convert the output tensor to a PIL image
output_image = transforms.ToPILImage()(output_tensor.squeeze(0))
Display the generated image
display(output_image)
Save the generated image
output_image.save('generated_image.jpg')
this is my code
from pytorch-cyclegan-and-pix2pix.
Hi AGRocky,
To help troubleshoot your CycleGAN model issue, could you provide:
- Versions: Exact versions of Python, PyTorch, and other libraries used.
- System Specs: Your GPU model and overall system configuration.
- Error Details: Any specific error messages or warnings during model loading.
These details will help in accurately replicating the issue and providing a solution.
Thanks!
from pytorch-cyclegan-and-pix2pix.
Related Issues (20)
- 礼貌提问并虚心请教:线性衰减学习率政策
- 请问作者 HOT 1
- 生成图像的质量太低怎么办
- 请问对于输入图像大小不一样时,该代码中是否对图像进行预处理了呢?
- CPU
- It gets stuck when running for more than 20 rounds, but the graphics card is still running. What is the reason for this?
- Is the Model Capable of Processing and Maintaining Consistent Output Sizes Across Varied Image Dimensions? HOT 6
- 请问测试集应该下载保存到什么文件夹呢,每次都会报错'./checkpoints\\facades_label2photo_pretrained\\latest_net_G.pth'
- Hello, HOT 1
- introducing CycleGAN-Turbo and pix2pix-turbo
- Add ROI specific loss function to generator
- Error testing my own dataset using pix2pix
- How can I train with multi-input like (A1 ,A2……)->B? HOT 1
- How to finish Scene Text Editing task using Pix2Pix
- Input images are stretched when using test HOT 1
- Error in combine_A_and_B.py for TIFF-files
- Training Parameters or Architecture Settings Recommendations
- Perform interpolation between Input and Output
- value of lambda_identity not to change the color
- good
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytorch-cyclegan-and-pix2pix.