File size: 2,565 Bytes
25097e9 968f23f 25097e9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
---
tags:
- huggan
- gan
# See a list of available tags here:
# https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts#L12
# task: unconditional-image-generation or conditional-image-generation or image-to-image
license: mit
---
# MyModelName
## Model description
[Pix2pix Model](https://arxiv.org/abs/1611.07004) is a conditional adversarial networks, a general-purpose solution to image-to-image translation problems. These networks not only learn the mapping from input image to output image, but also learn a loss function to train this mapping. This makes it possible to apply the same generic approach to problems that traditionally would require very different loss formulations. We demonstrate that this approach is effective at synthesizing photos from label maps, reconstructing objects from edge maps, and colorizing images, among other tasks.
## Intended uses & limitations:
Used for reconstruction of images from edges
#### How to use
```python
from torchvision.transforms import Compose, Resize, ToTensor, Normalize
from PIL import Image
from torchvision.utils import save_image
import cv2
from huggan.pytorch.pix2pix.modeling_pix2pix import GeneratorUNet
transform = Compose(
[
Resize((256, 256), Image.BICUBIC),
ToTensor(),
Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)),
]
)
model = GeneratorUNet.from_pretrained('huggan/pix2pix-cityscapes')
def predict_fn(img):
inp = transform(img).unsqueeze(0)
out = model(inp)
save_image(out, 'out.png', normalize=True)
return 'out.png'
predict_fn(img)
```
#### Limitations and bias
* Gives unrealistic colors in the image
* Patterns in the edge drawing are not recognize properly
## Training data
* [edges2shoes](https://huggingface.co/datasets/huggan/edges2shoes)
## Training procedure
```
# 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 huggan/edges2shoes --push_to_hub --output_dir pix2pix-edge2shoes --hub_model_id huggan/pix2pix-edge2shoes --wandb --batch_size 64 --n_epochs 5
```
## Generated Images
### BibTeX entry and citation info
```bibtex
@article{pix2pix2017,
title={Image-to-Image Translation with Conditional Adversarial Networks},
author={Isola, Phillip and Zhu, Jun-Yan and Zhou, Tinghui and Efros, Alexei A},
journal={CVPR},
year={2017}
}
``` |