pytorch-CycleGAN-and-pix2pix
pytorch-CycleGAN-and-pix2pix copied to clipboard
How to get result images have same names suffix as testA?
Hi,
Firstly thank you very much for such a nice implementation. My question is related to CycleGan:
- I have 500 files in /testA/ named such as 1.jpg, 2.jpg, ... , 500.jpg
- I want to have the results to have outputs say 1_real.png , 1_fake.png, ..., 500_real.png, 500_fake.png - that refers to the original 1.jpg, .... , 500.jpg (in sequence).
Right now it comes as randomized even when number of test images is changed to 500 instead of the default.
Any tips on how to achieve this? I think it should be a simple change in some lines.
Thanks.
PS. As an aside (though not important), can the jpg format preserved and not changed to png?
Nevermind the first part. The arguments --batch_size 1 --serial_batches made it happen.
Still, any way to have outputs as jpg's (the same format as the inputs)?
Hi @adnan0819 ! You can change the extension of the image file being saved in the 'save_image' function defined at /util/[visualizer.py] (https://github.com/junyanz/pytorch-CycleGAN-and-pix2pix/tree/003efc4c8819de47ff11b5a0af7ba09aee7f5fc1/util/visualizer.py)
def save_images(webpage, visuals, image_path, aspect_ratio=1.0, width=256, use_wandb=False):
"""Save images to the disk.
Parameters:
webpage (the HTML class) -- the HTML webpage class that stores these imaegs (see html.py for more details)
visuals (OrderedDict) -- an ordered dictionary that stores (name, images (either tensor or numpy) ) pairs
image_path (str) -- the string is used to create image paths
aspect_ratio (float) -- the aspect ratio of saved images
width (int) -- the images will be resized to width x width
``This function will save images stored in 'visuals' to the HTML file specified by 'webpage'.
"""``
image_dir = webpage.get_image_dir()
short_path = ntpath.basename(image_path[0])
name = os.path.splitext(short_path)[0]
webpage.add_header(name)
ims, txts, links = [], [], []
ims_dict = {}
for label, im_data in visuals.items():
im = util.tensor2im(im_data)
#Look here -----------------------------------------
image_name = '%s_%s.png' % (name, label) # Here the image name is being defined you can change it what way you want to.
#Change here --------------------------------------
save_path = os.path.join(image_dir, image_name)
util.save_image(im, save_path, aspect_ratio=aspect_ratio)
ims.append(image_name)
txts.append(label)
links.append(image_name)
if use_wandb:
ims_dict[label] = wandb.Image(im)
webpage.add_images(ims, txts, links, width=width)
if use_wandb:
wandb.log(ims_dict)``
Hope it helps!
You can also change this line in the test.py.