Update pintar.py
Browse files123456789101112137 unmodified lines2122232425262722 unmodified lines50515253545556575859606162import osimport numpy as npfrom skimage import color, ioimport torchimport torch.nn.functional as Ffrom PIL import Imagefrom models import ColorEncoder, ColorUNetfrom extractor.manga_panel_extractor import PanelExtractoros.environ["CUDA_VISIBLE_DEVICES"] = '0'7 unmodified linesimg_ab = img_lab[:,1:,:,:]img_l = img_l + 50pred_lab = torch.cat((img_l, img_ab), 1)[0,...].numpy()out = (np.clip(color.lab2rgb(pred_lab.transpose(1, 2, 0)), 0, 1)* 255).astype("uint8")return outdef RGB2Lab(inputs):22 unmodified linesreturn img.unsqueeze(0), img_lab.unsqueeze(0)if __name__ == "__main__":device = "cuda"# Specify the paths hereimg_path = 'path/to/your/input/image.jpg'ckpt_path = 'path/to/your/model_checkpoint.pt'reference_image_path = 'path/to/your/reference/image.jpg'imgsize = 256ckpt = torch.load(ckpt_path, map_location=lambda storage, loc: storage)1234567891011127 unmodified lines2021222324252622 unmodified lines49505152535455565758596061626364656667import osimport numpy as npfrom skimage import color, ioimport torchimport torch.nn.functional as Ffrom PIL import Imagefrom models import ColorEncoder, ColorUNetfrom extractor.manga_panel_extractor import PanelExtractorimport argparseos.environ["CUDA_VISIBLE_DEVICES"] = '0'7 unmodified linesimg_ab = img_lab[:,1:,:,:]img_l = img_l + 50pred_lab = torch.cat((img_l, img_ab), 1)[0,...].numpy()out = (np.clip(color.lab2rgb(pred_lab.transpose(1, 2, 0)), 0, 1) * 255).astype("uint8")return outdef RGB2Lab(inputs):22 unmodified linesreturn img.unsqueeze(0), img_lab.unsqueeze(0)if __name__ == "__main__":parser = argparse.ArgumentParser(description="Colorize manga images.")parser.add_argument("-i", "--input", type=str, required=True, help="Path to input image directory")parser.add_argument("-r", "--reference", type=str, required=True, help="Path to reference image")parser.add_argument("-o", "--output", type=str, required=True, help="Output directory")parser.add_argument("-ckpt", "--checkpoint", type=str, required=True, help="Path to model checkpoint")args = parser.parse_args()device = "cuda"input_image_dir = args.inputoutput_directory = args.outputmodel_checkpoint_path = args.checkpointreference_image_path = args.referenceimgsize = 256ckpt = torch.load(ckpt_path, map_location=lambda storage, loc: storage)
pintar.py+13-8