Giter Site home page Giter Site logo

bcmi / f2gan-few-shot-image-generation Goto Github PK

View Code? Open in Web Editor NEW
74.0 8.0 11.0 6.52 MB

Fusing-and-Filling GAN (F2GAN) for few-shot image generation, ACM MM2020

Python 99.23% Dockerfile 0.32% Shell 0.44%
few-shot-learning image-generation few-shot-image-generation few-shot-classification data-augmentation

f2gan-few-shot-image-generation's Introduction

F2GAN: Few-Shot Image Generation

Code for our ACM MM 2020 paper "F2GAN: Fusing-and-Filling GAN for Few-shot Image Generation".

Created by Yan Hong, Li Niu*, Jianfu Zhang, Liqing Zhang.

Paper Link: [arXiv]

If you find our work useful in your research, please consider citing:

@inproceedings{HongF2GAN,
  title={F2GAN: Fusing-and-Filling GAN for Few-shot Image Generation},
  author={Hong, Yan and Niu, Li and Zhang, Jianfu and Zhao, Weijie and Fu, Chen and Zhang, Liqing},
  booktitle={ACM International Conference on Multimedia},
  year={2020}
}

Introduction

Few-shot image generation aims at generating images for a new category with only a few images, which can benefit a wide range of downstream category-aware tasks like few-shot classification. In this paper, we propose a novel fusing-and-filling GAN (F2GAN) to enhance the ability of fusing conditional images. The high-level idea is fusing the high-level features of conditional images and filling in the details of generated image with relevant low-level features of conditional images. In detail, our method contains a fusion generator and a fusion discriminator. In our generator, we interpolate the high-level bottleneck features of multiple conditional images with random interpolation coefficients. Then, the fused high-level feature is upsampled through the decoder to produce a new image. In each upsampling stage, we borrow missing details from the skip-connected shallow encoder block by using our Non-local Attentional Fusion (NAF) module. In the fusion discriminator, we employ typical adversarial loss and classification loss to enforce the generated images to be close to real images and from the same category of conditional images. To ensure the diversity of generated images, we additionally employ a mode seeking loss and an interpolation regression loss, both of which are related to interpolation coefficients. We have conducted extensive generation and classification experiments on five datasets to demonstrated the effectiveness of our method.

Visualization

More generated reuslts to view here

Poster Presentation

Experiments

Hardware& Software Dependency

  • Hardware

    ** a single GPU or multiple GPUs

  • Software

    ** Tensorflow-gpu (version >= 1.7)

    ** Opencv

    ** scipy

  • Click here to view detailed software dependency

Datasets Preparation

  • The Download links can be found here
  • Omniglot

    Categories/Samples: 1412/ 32460

    Split: 1200 seen classes, 212 unseen classes

  • Emnist

    Categories/Samples: 38/ 106400

    Split: 28 seen classes, 10 unseen classes

  • VGGFace

    Categories/Samples: 2299/ 229900

    Split: 1802 seen classes, 497 unseen classes

  • Flowers

    Categories/Samples: 102/ 8189

    Split: 85 seen classes, 17 unseen classes

  • Animal Faces

    Categories/Samples: 149/ 214105

    Split: 119 seen classes, 30 unseen classes

Baselines

Few-shot Image Generation

Few-shot Image Classification

  • Matching Networks for One Shot Learning paper code

  • Model-Agnostic Meta-Learning for Fast Adaptation of Deep Networks paper code

  • Learning to Compare: Relation Network for Few-Shot Learning paper code

  • Meta-Transfer Learning for Few-Shot Learning paper code

  • Cross-Domain Few-Shot Classification via Learned Feature-Wise Transformation paper code

  • Revisiting local descriptor based image-to-class measure for few-shot learning paper code

Getting Started

Installation

1.Clone this repository.

git clone https://github.com/bcmi/F2GAN-Few-Shot-Image-Generation.git

2.Create python environment for F2GAN via pip.

pip install -r requirements.txt

Training

1.Train on Omniglot dataset

python train_dagan_with_matchingclassifier.py --dataset omniglot --image_width 96 --batch_size 20  --experiment_title MMF2GAN/omniglot1way3shot   --selected_classes 1 --support_number 3  --loss_G 1 --loss_D 1 --loss_CLA 1  --loss_recons_B 1 --loss_matching_G 1 --loss_matching_D 1 --loss_sim 1 

2.Train on EMNIST dataset

python train_dagan_with_matchingclassifier.py --dataset emnist --image_width 96 --batch_size 20  --experiment_title MMF2GAN/emnist1way3shot   --selected_classes 1 --support_number 3  --loss_G 1 --loss_D 1 --loss_CLA 1  --loss_recons_B 1 --loss_matching_G 1 --loss_matching_D 1 --loss_sim 1  

3.Train on VGGFce dataset

python train_dagan_with_matchingclassifier.py --dataset vggface --image_width 96 --batch_size 20  --experiment_title MMF2GAN/vggface1way3shot   --selected_classes 1 --support_number 3  --loss_G 1 --loss_D 1 --loss_CLA 1  --loss_recons_B 1 --loss_matching_G 1 --loss_matching_D 1 --loss_sim 1  

4.Train on Flowers dataset

python train_dagan_with_matchingclassifier.py --dataset flowers --image_width 96 --batch_size 20  --experiment_title MMF2GAN/flowers1way3shot   --selected_classes 1 --support_number 3  --loss_G 1 --loss_D 1 --loss_CLA 1  --loss_recons_B 1 --loss_matching_G 1 --loss_matching_D 1 --loss_sim 1  

5.Train on Animal Faces dataset

python train_dagan_with_matchingclassifier.py --dataset animals --image_width 96 --batch_size 20  --experiment_title MMF2GAN/animals1way3shot   --selected_classes 1 --support_number 3  --loss_G 1 --loss_D 1 --loss_CLA 1  --loss_recons_B 1 --loss_matching_G 1 --loss_matching_D 1 --loss_sim 1  

Trained Model

Evaluation from three aspects including GAN metrics, low-data classification, and few-shot classification.

1. Visualizing the generated images based on trained models, the generated images are stored in the path '--experiment_title'

Omniglot generated images

python test_dagan_with_matchingclassifier_for_generation.py  --is_training 0 --is_all_test_categories 1 --is_generation_for_classifier 1  --general_classification_samples 3 --dataset omniglot --image_width 96  --batch_size 30  --num_generations 128 --experiment_title EVALUATION_Augmented_omniglot_MM --selected_classes 1 --support_number 3   --restore_path  ./trained_models/omniglot/ --continue_from_epoch 100

EMNIST generated images

python test_dagan_with_matchingclassifier_for_generation.py  --is_training 0 --is_all_test_categories 1 --is_generation_for_classifier 1  --general_classification_samples 3 --dataset emnist --image_width 96  --batch_size 30  --num_generations 128 --experiment_title EVALUATION_Augmented_emnist_MM --selected_classes 1 --support_number 3   --restore_path   ./trained_models/emnist/  --continue_from_epoch 100

VGGFace generated images

python test_dagan_with_matchingclassifier_for_generation.py  --is_training 0 --is_all_test_categories 1 --is_generation_for_classifier 1  --general_classification_samples 3 --dataset vggface --image_width 96  --batch_size 30  --num_generations 128 --experiment_title EVALUATION_Augmented_vggface_MM --selected_classes 1 --support_number 3   --restore_path    ./trained_models/vggface/  --continue_from_epoch 100

FLowers generated images

python test_dagan_with_matchingclassifier_for_generation.py  --is_training 0 --is_all_test_categories 1 --is_generation_for_classifier 1  --general_classification_samples 3 --dataset flowers --image_width 96  --batch_size 30  --num_generations 128 --experiment_title EVALUATION_Augmented_flowers_MM --selected_classes 1 --support_number 3   --restore_path    ./trained_models/flowers/  --continue_from_epoch 100

Animal Faces generated images

python test_dagan_with_matchingclassifier_for_generation.py  --is_training 0 --is_all_test_categories 1 --is_generation_for_classifier 1  --general_classification_samples 3 --dataset animals --image_width 96  --batch_size 30  --num_generations 128 --experiment_title EVALUATION_Augmented_animals_MM --selected_classes 1 --support_number 3   --restore_path  ./trained_models/animals/  --continue_from_epoch 100

2. Testing the GAN metrics including FID and IPIPS for generated images, which is suitable for RGB 3-channel images like VGGFace, Flowers, and Animal Faces datasets.

VGGFace GAN metrics

python GAN_metrcis_FID_IS_LPIPS.py  --dataroot_real ./EVALUATION/Augmented/vggface/MM/visual_outputs_realimages/ --dataroot_fake  ./EVALUATION/Augmented/vggface/MM/visual_outputs_forquality/  --image_width 96 --image_channel 3 --augmented_support 100  --dir ./EVALUATION/Augmented/vggface/MM/visual_outputs_forquality/ --out ./EVALUATION/Augmented/vggface/MM/GAN_METRICS.txt 

Flowers GAN metrics

python GAN_metrcis_FID_IS_LPIPS.py  --dataroot_real ./EVALUATION/Augmented/flowers/MM/visual_outputs_realimages/ --dataroot_fake  ./EVALUATION/Augmented/flowers/MM/visual_outputs_forquality/  --image_width 96 --image_channel 3 --augmented_support 100  --dir ./EVALUATION/Augmented/flowers/MM/visual_outputs_forquality/ --out ./EVALUATION/Augmented/flowers/MM/GAN_METRICS.txt 

Animals Faces GAN metrics

python GAN_metrcis_FID_IS_LPIPS.py  --dataroot_real ./EVALUATION/Augmented/animals/MM/visual_outputs_realimages/ --dataroot_fake  ./EVALUATION/Augmented/animals/MM/visual_outputs_forquality/  --image_width 96 --image_channel 3 --augmented_support 100  --dir ./EVALUATION/Augmented/animals/MM/visual_outputs_forquality/ --out ./EVALUATION/Augmented/animals/MM/GAN_METRICS.txt 

3. Testing the classification in low-data setting with augmented images.

take Omniglot as example, low-data classification with augmented images generated from our trained model

3.1. Gnerating augmented images using three conditional images

python test_dagan_with_matchingclassifier_for_generation.py  --is_training 0 --is_all_test_categories 1 --is_generation_for_classifier 1  --general_classification_samples 10 --dataset omniglot --image_width 96  --batch_size 30  --num_generations 512 --experiment_title EVALUATION_Augmented_omniglot_MM --selected_classes 1 --support_number 3   --restore_path path ./trained_models/omniglot/ --continue_from_epoch 100

3.2. Preparing generated images: the generated images are stored in the 'storepath/visual_outputs_forclassifier' and setting the storepath for preprocessed data, running below script

python data_preparation.py --dataroot storepath/visual_outputs_forclassifier  --storepath --image_width 96 --channel 1 

3.3. Replacing the datapath in data_with_matchingclassifier_for_quality_and_classifier.py with the storepath for preprocessed data.

3.4. Running the script for low-data classification.

train_classifier_with_augmented_images.py --dataset omniglot  --selected_classes testing_categories  --batch_size 16 --classification_total_epoch 50  --experiment_title AugmentedLowdataClassifier_omniglot  --image_width 96  --image_height 96 --image_channel 1

--selected_classes: the number of total testing categories

4. Testing the classification in few-shot setting with augmented images.

take Omniglot as example, NwayKshot classification with augmented images generated from our trained model

4.1. Gnerating augmented images using Kshot conditional images

python test_dagan_with_matchingclassifier_for_generation.py  --is_training 0 --is_all_test_categories 1 --is_generation_for_classifier 1  --general_classification_samples 10 --dataset omniglot --image_width 96  --batch_size 30  --num_generations 128 --experiment_title EVALUATION_Augmented_omniglot_MM --selected_classes 1 --support_number K   --restore_path path ./trained_models/omniglot/ --continue_from_epoch 100

setting the '--support_number' as K.

4.2. Preprocessing the generated images

python data_preparation.py --dataroot ./EVALUATION/Augmented/omniglot/MM/visual_outputs_forclassifier  --storepath ./EVALUATION/Augmented/omniglot/MM/  --image_width 96 --channel 1 

4.3. Replacing the datapath in data_with_matchingclassifier_for_quality_and_classifier.py with ./EVALUATION/Augmented/omniglot/MM/omniglot.npy.

4.4. Running the script for few-shot classification.

train_classifier_with_augmented_images.py --dataset omniglot  --selected_classes N  --batch_size 16 --classification_total_epoch 50  --experiment_title AugmentedFewshotClassifier_omniglot --image_width 96  --image_height 96 --image_channel 1

setting the '--selected_classes' as N.

Results

Learned Attention

GAN metrics of Generated Images

Low-data Image Classification

Few-shot Image Classification

Acknowledgement

Some of the codes are built upon DAGAN. Thanks them for their great work!

If you get any problems or if you find any bugs, don't hesitate to comment on GitHub or make a pull request!

F2GAN is freely available for non-commercial use, and may be redistributed under these conditions. For commercial queries, please drop an e-mail. We will send the detail agreement to you.

f2gan-few-shot-image-generation's People

Contributors

hy-zpg avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

f2gan-few-shot-image-generation's Issues

unable to reproduce the classification accuracy, it is too low

Hi there! I have used DAGAN on omniglot 5-shot classification as mentioned in your paper and your code and I only achieved an accuracy of 69% instead of the 88.81% accuracy as reported in Table 2 in the paper.

Can you help me with getting the 88.81% accuracy with DAGAN, please? Thanks

DeltaGAN

《DeltaGAN: Towards Diverse Few-shot Image Generation with Sample-Specific Delta》这篇会开源吗?

Questions on low data classification

Hello, I'm interested in the low data classification experiment and its implemental detail. Could you please help me to answer my doubts?

  1. I notice that you use the first 20 real images for validation and the rest 512 generated images for training in data_for_augmentedimages_for_classifier.py. Does that mean the real images are always used as the validation set? And how can I test the classification accuracy on the testing images of the unseen categories?

training_dataset = self.datasets[dataset_name][:, 20:]
testing_dataset = self.datasets[dataset_name][:, :20]

  1. What does the testing_num=10 mean in generation_builder_with_matchingclassifier.py?

  2. It seems that the only difference between low-data experiment and few-shot experiment is the value of selected_class N and support_num K. Can one consider the low data classification as [num of unseen class]-way-1-shot setting in few-shot learning?

  3. Did you use data augmentation to pre-train the ResNet 18 on the seen categories for low-data and few-shot experiments?

Thanks again :)

Dataset generation

Hi there, how did you generate the following datasets in data_with_matchingclassifier.py? Thanks!

Flowers

  • /datasets/flowers_c8189_s128_data.npy
  • /datasets/flowers_3_30_selected_3_30_data.npy

Animals

  • /datasets/AnimalFaceEasyPairs-10pairs.npy
  • /datasets/AnimalFaceTest.np

EMNIST

  • /datasets/emnist.npy

Omniglot

  • /datasets/omniglot_data.npy

段错误

  • When I use the update codes.

  • And I use

python3 train_dagan_with_matchingclassifier.py --dataset emnist --image_width 28 --batch_size 20 --experiment_title MMF2GAN/emnist1way3shot --selected_classes 1 --support_number 3 --loss_G 1 --loss_D 1 --loss_CLA 1 --loss_recons_B 1 --loss_matching_G 0.01 --loss_matching_D 1 --loss_sim 1

  • The I got

2020-10-19 17:10:01.832958: W tensorflow/compiler/jit/mark_for_compilation_pass.cc:1412] (One-time warning): Not using XLA:CPU for cluster because envvar TF_XLA_FLAGS=--tf_xla_cpu_global_jit was not set. If you want XLA:CPU, either set that envvar, or use experimental_jit_scope to enable XLA:CPU. To confirm that XLA is active, pass --vmodule=xla_compilation_cache=1 (as a proper command-line flag, not via TF_XLA_FLAGS) or set the envvar XLA_FLAGS=--xla_hlo_profile.
time for initializing global parameters: 28.6798198223114
0%| | 0/600 [00:00<?, ?it/s]段错误

  • My tensorflow version is 1.4.0 . And i do not know the error is from GPU or tensorflow version?

TypeError: cannot unpack non-iterable NoneType object

when i use " python3 train_dagan_with_matchingclassifier.py --dataset emnist --image_width 28 --batch_size 20 --experiment_title MMF2GAN/emnist1way3shot --selected_classes 1 --support_number 3 --loss_G 1 --loss_D 1 --loss_CLA 1 --loss_recons_B 1 --loss_matching_G 0.01 --loss_matching_D 1 --loss_sim 1 "

  • i got the wrong message at "dagan_networks_wgan_with_matchingclassifier.py", line 147, in generate -> z_dim = self.z_dim)
    TypeError: cannot unpack non-iterable NoneType object

i can not to find what happen

No module named 'data_with_matchingclassifier_for_quality_and_classifier'

I tried generating flower images using the pretrained model train_LOSS_z2vae0_z20_g1.0_d1.0_kl0.0_cla1.0_fzl_cla0.0_reconsB1.0_matchingG5.0_matchingD1.0_sim1.0_Net_batchsize20_classencodedim128_imgsize96_epoch325.ckpt.data-00000-of-00001 with command

python test_dagan_with_matchingclassifier_for_generation.py  --is_training 0 --is_all_test_categories 1 
--is_generation_for_classifier 1  --general_classification_samples 3 --dataset flowers 
--image_width 96  --batch_size 30  --num_generations 128 
--experiment_title EVALUATION_Augmented_flowers_MM 
--selected_classes 1 --support_number 3   
--restore_path    ./trained_models/flowers/  --continue_from_epoch 100

and I get No module named 'data_with_matchingclassifier_for_quality_and_classifier'

may be the test.py need update?

  • I use the python3 test_dagan_with_matchingclassifier_for_generation.py --is_training 0 --is_all_test_categories 1 --is_generation_for_classifier 1 --general_classification_samples 10 --dataset emnist --image_width 28 --batch_size 30 --num_generations 128 --experiment_title EVALUATION_Augmented_emnist_F2GAN --selected_classes 1 --support_number 3 --restore_path ./trained_models/ --continue_from_epoch 100

-Then, i got :
File "test_dagan_with_matchingclassifier_for_generation.py", line 12, in
import data_with_matchingclassifier_for_quality_and_classifier as dataset
ModuleNotFoundError: No module named 'data_with_matchingclassifier_for_quality_and_classifier'

  • the file not have "data_with_matchingclassifier_for_quality_and_classifier.py"

  • In fact, i try to use the train_dagan_augmented_general_fewshot_classification_with_matchingclassifier.py

  • and i use the same environment as the authors. But the codes can not run.

  • May be the codes have some grammar or parameter setting errors?

  • And I recommend that authors download this code in "github" and try to run.

  • And few-shot GAN is a meaningful job.

Trained models

Thanks for the code! can we have access to the trained models please? Thank you :))

Question about the dataset setting

Hello, thanks for this repo.
The dataset split seems to differ from the description in the paper.

In the paper:

For EMNIST, following MatchingGAN[16], we randomly select 28 categories from total 48 categories as training seen categories and select 10 categories from remaining categories as unseen testing categories

which suppose be 28:10:10 for train, val and test.

In the code:

x_train, x_val, x_test = self.x[:35], self.x[35:42], self.x[42:]

which is 35:7:5 for train, val and test.

Which is the setting to re-implement the result in the paper?

About the split of classes

Hi, thanks for the interesting work! I hope to cite your work in my later research.

I have some questions about the source code and the paper.

  1. In the paper, the split of the classes for train, test, validation for flower102 is the same as FUNIT's split. Then, the first 85 classes are for train and the remaining 17 classes are for the test. However, when I run "data_preparation.py" to prepare ".npy" file, the classes are not sorted so that class 087 is mapped to 0. It might not be the same as the split of FUNIT. Can you provide more details about it?

  2. For EMNIST dataset, you mentioned that the split is: 28 (seen), 10 (unseen) among 48 classes. And in "MatchingGAN" paper, the split is : (28, 10, 10) for 48 classes. However, EMNIST contains 47 classes (for "Balanced" split). Is it just a misspelling?

  3. Some of the source codes for the test do not seem to be for F2GAN but MatchingGAN. As mentioned in #4 , there are some issues to run. Please provide some details to reproduce the results in the paper.

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.