Views
No views yet
1from torchvision.transforms import Compose, Resize, ToTensor, Normalize
2from PIL import Image
3from torchvision.utils import save_image
4import cv2
5from huggan.pytorch.pix2pix.modeling_pix2pix import GeneratorUNet
6
7transform = Compose(
8 [
9 Resize((256, 256), Image.BICUBIC),
10 ToTensor(),
11 Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
12 ]
13)
14model = GeneratorUNet.from_pretrained('huggan/pix2pix-uavid-15)
15
16def predict_fn(img):
17 inp = transform(img).unsqueeze(0)
18 out = model(inp)
19 save_image(out, 'out.png', normalize=True)
20 return 'out.png'
21
22predict_fn(img)# clone the repository
git clone https://github.com/huggingface/community-events.git
pip install .
# change directory
cd community-events/huggan/pytorch/pix2pix/
# define config
accelerate config
# launch training with required parameters
accelerate launch train.py --checkpoint_interval 1 --dataset arakesh/uavid-15-hq-mixedres --push_to_hub --model_name pix2pix-uavid-15 --batch_size 2 --n_epochs 50 --image_size 1024 --sample_interval 500

1@article{pix2pix2017,
2 title={Image-to-Image Translation with Conditional Adversarial Networks},
3 author={Isola, Phillip and Zhu, Jun-Yan and Zhou, Tinghui and Efros, Alexei A},
4 journal={CVPR},
5 year={2017}
6}