ceyda commited on
Commit
99584c3
·
1 Parent(s): 95a9596

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +58 -15
README.md CHANGED
@@ -2,49 +2,92 @@
2
  tags:
3
  - huggan
4
  - gan
 
 
5
  # See a list of available tags here:
6
  # https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts#L12
7
- # task: unconditional-image-generation or conditional-image-generation or image-to-image
8
- license: mit
9
  ---
10
 
11
- # MyModelName
12
 
13
  ## Model description
14
 
15
- Describe the model here (what it does, what it's used for, etc.)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
 
17
  ## Intended uses & limitations
18
 
 
 
19
  #### How to use
20
 
21
  ```python
22
- # You can include sample code which will be formatted
 
 
 
 
 
 
 
 
 
 
23
  ```
24
 
25
  #### Limitations and bias
26
 
27
- Provide examples of latent issues and potential remediations.
 
 
 
 
28
 
29
  ## Training data
30
 
31
- Describe the data you used to train the model.
32
- If you initialized it with pre-trained weights, add a link to the pre-trained model card or repository with description of the pre-training data.
 
 
 
33
 
34
  ## Training procedure
35
 
36
- Preprocessing, hardware used, hyperparameters...
 
 
37
 
38
  ## Eval results
39
 
 
 
 
 
40
  ## Generated Images
41
 
42
- You can embed local or remote images using `![](...)`
43
 
44
  ### BibTeX entry and citation info
45
 
46
- ```bibtex
47
- @inproceedings{...,
48
- year={2020}
49
- }
50
- ```
 
2
  tags:
3
  - huggan
4
  - gan
5
+ task: unconditional-image-generation
6
+ license: mit
7
  # See a list of available tags here:
8
  # https://github.com/huggingface/hub-docs/blob/main/js/src/lib/interfaces/Types.ts#L12
9
+
 
10
  ---
11
 
12
+ # Butterfly GAN
13
 
14
  ## Model description
15
 
16
+ Based on [paper:](https://openreview.net/forum?id=1Fqg133qRaI) *Towards Faster and Stabilized GAN Training for High-fidelity Few-shot Image Synthesis*
17
+
18
+ which states:
19
+ "Notably, the model converges from scratch with just a **few hours of training** on a single RTX-2080 GPU, and has a consistent performance, even with **less than 100 training samples**"
20
+
21
+ also dubbed the Light-GAN model. This model was trained using the script [here](https://github.com/huggingface/community-events/tree/main/huggan/pytorch/lightweight_gan) which is adapted from the lucidrains [repo](https://github.com/lucidrains/lightweight-gan).
22
+
23
+ Differently from the script above, I used the transforms from the official repo. Because our training images were already cropped and aligned.
24
+ official paper implementation [repo](https://github.com/odegeasslbc/FastGAN-pytorch)
25
+
26
+ ```py
27
+ transform_list = [
28
+ transforms.Resize((int(im_size),int(im_size))),
29
+ transforms.RandomHorizontalFlip(),
30
+ transforms.ToTensor(),
31
+ transforms.Normalize(mean=[0.5, 0.5, 0.5], std=[0.5, 0.5, 0.5])
32
+ ]
33
+ ```
34
 
35
  ## Intended uses & limitations
36
 
37
+ Intended for fun & learning~
38
+
39
  #### How to use
40
 
41
  ```python
42
+
43
+ import torch
44
+ from huggan.pytorch.lightweight_gan.lightweight_gan import LightweightGAN # install the community-events repo above
45
+
46
+ gan = LightweightGAN.from_pretrained("ceyda/butterfly_cropped_uniq1K_512")
47
+ gan.eval()
48
+ batch_size = 1
49
+ with torch.no_grad():
50
+ ims = gan.G(torch.randn(batch_size, gan.latent_dim)).clamp_(0., 1.)*255
51
+ ims = ims.permute(0,2,3,1).detach().cpu().numpy().astype(np.uint8)
52
+ # ims is [BxWxHxC] call Image.fromarray(ims[0])
53
  ```
54
 
55
  #### Limitations and bias
56
 
57
+ - During training I filtered the dataset to have only 1 butterfly from each species available.
58
+ Otherwise the model generated less varied butterflies (a few species with more images would dominate).
59
+ - The dataset was also filtered using CLIP scores for ['pretty butterfly','one butterfly','butterfly with open wings','colorful butterfly'].
60
+ While this was done to eliminate images that contained no butterflies(just scientific tags, cluttered images) from the [full dataset](https://huggingface.co/datasets/ceyda/smithsonian_butterflies).
61
+ It is easy to imagine where this type of approach would be problematic in certain scenarios; who is to say which butterfly is "pretty" and should be in the dataset.ie; CLIP failing to identify a butterfly might exclude it from the dataset causing bias.
62
 
63
  ## Training data
64
 
65
+ 1000 images are used, while it was possible to increase this number, we didn't have time to manually curate the dataset.
66
+
67
+ & also wanted to see if it was possible to do low data training as mention in the paper.
68
+
69
+ More details are on the [data card](https://huggingface.co/datasets/huggan/smithsonian_butterflies_subset)
70
 
71
  ## Training procedure
72
 
73
+ Trained on 2xA4000s for ~1day. Can see good results within 7-12h.
74
+ Importans params: "--batch_size 64 --gradient_accumulate_every 4 --image_size 512 --mixed_precision fp16"
75
+ Training logs can be seen [here](https://wandb.ai/cceyda/butterfly-gan/runs/2e0bm7h8?workspace=user-cceyda)
76
 
77
  ## Eval results
78
 
79
+ calculated FID score on 100 images. results for different checkpoints are [here](https://wandb.ai/cceyda/butterfly-gan-fid?workspace=user-cceyda)
80
+
81
+ but can't say it is too meaningful (due to the shortcomings of FID score)
82
+
83
  ## Generated Images
84
 
85
+ Play with the [demo](https://huggingface.co/spaces/huggan/butterfly-gan)
86
 
87
  ### BibTeX entry and citation info
88
 
89
+ Made during the huggan sprint.
90
+
91
+ Model trained by: Ceyda Cinarel https://twitter.com/ceyda_cinarel
92
+
93
+ Additional contributions by Jonathan Whitaker https://twitter.com/johnowhitaker