Tensorflow implementation of "BEGAN: Boundary Equilibrium Generative Adversarial Networks"

Overview

BEGAN in Tensorflow

Tensorflow implementation of BEGAN: Boundary Equilibrium Generative Adversarial Networks.

alt tag

Requirements

Usage

First download CelebA datasets with:

$ apt-get install p7zip-full # ubuntu
$ brew install p7zip # Mac
$ python download.py

or you can use your own dataset by placing images like:

data
└── YOUR_DATASET_NAME
    ├── xxx.jpg (name doesn't matter)
    ├── yyy.jpg
    └── ...

To train a model:

$ python main.py --dataset=CelebA --use_gpu=True
$ python main.py --dataset=YOUR_DATASET_NAME --use_gpu=True

To test a model (use your load_path):

$ python main.py --dataset=CelebA --load_path=CelebA_0405_124806 --use_gpu=True --is_train=False --split valid

Results

Generator output (64x64) with gamma=0.5 after 300k steps

all_G_z0_64x64

Generator output (128x128) with gamma=0.5 after 200k steps

all_G_z0_64x64

Interpolation of Generator output (64x64) with gamma=0.5 after 300k steps

interp_G0_64x64

Interpolation of Generator output (128x128) with gamma=0.5 after 200k steps

interp_G0_128x128

Interpolation of Discriminator output of real images

alt tag
alt tag
alt tag
alt tag
alt tag
alt tag
alt tag
alt tag
alt tag
alt tag
alt tag

Related works

Author

Taehoon Kim / @carpedm20

Comments
  • ValueError: last dimension shape must be known but is None?

    ValueError: last dimension shape must be known but is None?

    This is the problem that came up in the first place. So I printed some information and positioned it here. Can you tell me why?Thank you!!! I use my own database and tensorflow 0.10.0. from tranier.py: self.z: Tensor("random_uniform:0", shape=(?, ?), dtype=float32) from models.py : self.z: Tensor("random_uniform:0", shape=(?, ?), dtype=float32)

    Here is the complete error message:

    root: /media/z/lhj/images/testData_aligned/testData_aligned/ [16, 64, 64, 3] 3 64 64 self.data_loader: Tensor("ToFloat:0", shape=(16, 3, 64, 64), dtype=float32) self.z_num: 64 trainer x: Tensor("sub:0", shape=(16, 3, 64, 64), dtype=float32) tf.shape(x)[0]: Tensor("strided_slice:0", shape=(), dtype=int32) self.z: Tensor("random_uniform:0", shape=(?, ?), dtype=float32) self.conv_hidden_num: 128 self.channel: 3 self.repeat_num: 4 self.data_format: NCHW from models begin: num_output: 8192 z: Tensor("random_uniform:0", shape=(?, ?), dtype=float32) Traceback (most recent call last): File "main.py", line 44, in main(config) File "main.py", line 32, in main trainer = Trainer(config, data_loader_) File "/home/lhj/software/BEGAN-tensorflow-master/trainer.py", line 93, in init self.build_model() File "/home/lhj/software/BEGAN-tensorflow-master/trainer.py", line 199, in build_model self.repeat_num, self.data_format, reuse=False) File "/home/lhj/software/BEGAN-tensorflow-master/models.py", line 13, in GeneratorCNN x = slim.fully_connected(z, num_output, activation_fn=None) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 171, in func_with_args return func(*args, **current_args) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/layers.py", line 792, in fully_connected num_input_units = utils.last_dimension(inputs_shape, min_rank=2) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/utils.py", line 199, in last_dimension raise ValueError('last dimension shape must be known but is None') ValueError: last dimension shape must be known but is None

    opened by lensea 14
  • Sudden mode collapse after 400k epochs

    Sudden mode collapse after 400k epochs

    I have had this weird behaviour where after 380000 epochs the generator suddenly mode collapses. For example see:

    epoch 350k 349500_g

    epoch 390k 389500_g

    epoch 396k 396000_g

    epoch 400k 402000_g

    epoch 480k 483000_g

    I am suspecting that portrait guy in the middle of the lower row as the poltergeist that caused the mode collapse but I can't prove it :laughing: . Anyone seen this happen before?

    You can also see the g_loss and d_loss_fake increasing around epoch 380k screenshot from 2017-04-30 10-23-16

    opened by stefdoerr 8
  • Unable to train datasets

    Unable to train datasets

    Hi, I put the datasets in the data file, and execute this command:$python main.py --dataset=CelebA --use_gpu=True ,The following bug: Traceback (most recent call last): File "main.py", line 4, in from trainer import Trainer File "E:\product\faceVerification\faceAttributes\BEGAN-tensorflow\trainer.py", line 4, in import StringIO ImportError: No module named 'StringIO'

    Thank you for your help!

    opened by molyswu 8
  • Mode collapsing

    Mode collapsing

    Couldn't find a reason why, but the model always shows mode collapsing even after learning rate decay one or two times unlike the paper's description. I guess there could be an error on loss but first of all, I don't know how BEGAN tackle this without push-away factor of EBGAN (not sure learning rate decay is enough?).

    bug help wanted 
    opened by carpedm20 6
  • 'image' must be three-dimensional

    'image' must be three-dimensional

    Hi, sorry to interrupt you , I got another problem when running the program as follows :

    Traceback (most recent call last): File "main.py", line 42, in main(config) File "main.py", line 28, in main config.data_format, config.split) File "/home/chikiuso/Downloads/BEGAN-tensorflow/data_loader.py", line 48, in get_loader queue = tf.image.crop_to_bounding_box(queue, 50, 25, 128, 128) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/image_ops_impl.py", line 473, in crop_to_bounding_box assert_ops += _Check3DImage(image, require_static=False) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/ops/image_ops_impl.py", line 131, in _Check3DImage raise ValueError("'image' must be three-dimensional.") ValueError: 'image' must be three-dimensional.

    opened by chikiuso 6
  • Train problem

    Train problem

    I'm new to machine learning. Can anyone tell me how to solve this problem. Thanks ahead.

    File "main.py", line 43, in main(config) File "main.py", line 35, in main trainer.train() File "/Users/developer/Documents/git/opensource/BEGAN-tensorflow/BEGAN-tensorflow/trainer.py", line 158, in train self.autoencode(x_fixed, self.model_dir, idx=step, x_fake=x_fake) File "/Users/developer/Documents/git/opensource/BEGAN-tensorflow/BEGAN-tensorflow/trainer.py", line 263, in autoencode x = self.sess.run(self.AE_x, {self.x: img}) File "/Users/developer/anaconda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 778, in run run_metadata_ptr) File "/Users/developer/anaconda/envs/tensorflow/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 961, in _run % (np_val.shape, subfeed_t.name, str(subfeed_t.get_shape()))) ValueError: Cannot feed value of shape (16, 3, 64, 64) for Tensor 'ToFloat:0', which has shape '(16, 64, 64, 3)'

    opened by qinritukou 4
  • What about MNIST dataset?

    What about MNIST dataset?

    The model can not show any convergence clues in MNIST dataset during my training. agg_d_mnist after 1600 batch of training. It just remain no change with serious mode collapse. something wrong?

    opened by HolyCaonima 4
  • mode collapse?

    mode collapse?

    Hi @carpedm20 - this codebase is now working well for me, wanted to compare notes. with your latest changes I get pretty good results on 64x64 celeba. 128x128 doesn't do as well - probably needs different hyperparams.

    Here are some 64x64 results after 130k cycles of training. first x_fixed, D_real :

    x_fixed

    130000_d_real

    That looks like pretty good auto-encoder reconstruction results - the resemblance is pretty clear. OK, now here's the D_fake, and G:

    130000_d_fake

    130000_g

    Now here my knowledge of this model gets a little hazy. These look fairly good and they look like each other - but they no longer bear very much resemblance x_fixed - should they? If so, then I think this is would likely be a symptom of a pretty significant mode collapse.

    Just for comparison, here's what taking the same x_fixed looks like when passed through a trained ALI model:

    x_fixed

    20170414_ali64_montage_began

    Some of these come out better than others, but note the overall variation in hair color, skin tone, glasses, hats, backgrounds that seems to be missing from the current BEGAN generator. Curious if you have any thoughts from your own investigations.

    opened by dribnet 2
  • Interpolation of images done differently

    Interpolation of images done differently

    Just a word of caution: As far as I understand, the way the interpolation of images is implemented here does not correspond to the way it was done in the paper:

    In the paper, they approximate the G's z_1 and z_2 for two real images using Adam (reversing G(z)), then they interpolate between those z_1, z_2 and show G(z_{interp}).

    In this implementation, the discriminator's latent codes h_1, h_2 are calculated from the two images, and the discriminator output for the interpolation is shown.

    opened by wohnjayne 2
  • Naive question on training with A to B datasets

    Naive question on training with A to B datasets

    Is it possible to use BEGAN for predicted "B" image based on input "A" image? I know this is generally possible in GAN but in BEGAN implementations look like there is no implicit A-B training and prediction.

    opened by kickbox 1
  • fix param type bug in python 3

    fix param type bug in python 3

    method numpy.prod returns a numpy.int64 value, which will cause an ValueError in python3. Refer to the following code block in layers.py$fully_connected()

    if not isinstance(num_outputs, six.integer_types): raise ValueError('num_outputs should be int or long, got %s.', num_outputs)

    and int() method converts numpy.int64 to be compatible with six.integer_types

    This is compatible with python 2

    opened by chengdazhi 1
  • Pause the training

    Pause the training

    I wanted to pause the training with my dataset

    as mentioned on this issues :

    I tried to keep the same params python main.py --dataset=mydata

    python main.py --dataset=mydata --load_path=mydata_[08...]

    It still begin from scratch and erase the old checkpoint.

    Since the training is quite long I wonder how I could pause it

    opened by Fqlox 1
  • Pretrained weights for CelebA 64X64 and 128X128

    Pretrained weights for CelebA 64X64 and 128X128

    Thanks for the awesome repo. Will it be possible for you to release the pre-trained weights for CelebA on 64X64 and 128X128 resolution ?

    Thanks, Avisek Lahiri Indian Institute of Technology Kharagpur

    opened by avisekiit 0
  • cannot run test model perfectly

    cannot run test model perfectly

    I tried to run the test model which I had trained before, but I failed. The results all seemed noise after 'generate()' function. I had check the input z_r, they were numbers between -1~1. (It's correct.) I also print the tensors and variables from checkpoint files, they had numbers inside. Is there any one can help me? thanks!!

    opened by hanchun24 0
  • if i want to use the d_loss on caffe , how can i compute the Gradient

    if i want to use the d_loss on caffe , how can i compute the Gradient

    i want to use the Wasserstein loss on caffe,as we know BEGAN use tf.train.AdamOptimizer() to min the loss , however i want to to use the Wasserstein loss that 'd_loss =|Y-D(Y)| - |D(G(z)-G(z))|' on the caffe. how to compute the Gradient

    opened by paleblackless 0
Owner
Taehoon Kim
ex OpenAI
Taehoon Kim
TensorFlow Ranking is a library for Learning-to-Rank (LTR) techniques on the TensorFlow platform

TensorFlow Ranking is a library for Learning-to-Rank (LTR) techniques on the TensorFlow platform

null 2.6k Jan 4, 2023
Robust Video Matting in PyTorch, TensorFlow, TensorFlow.js, ONNX, CoreML!

Robust Video Matting in PyTorch, TensorFlow, TensorFlow.js, ONNX, CoreML!

Peter Lin 6.5k Jan 4, 2023
Robust Video Matting in PyTorch, TensorFlow, TensorFlow.js, ONNX, CoreML!

Robust Video Matting (RVM) English | 中文 Official repository for the paper Robust High-Resolution Video Matting with Temporal Guidance. RVM is specific

flow-dev 2 Aug 21, 2022
Implementation of Restricted Boltzmann Machine (RBM) and its variants in Tensorflow

xRBM Library Implementation of Restricted Boltzmann Machine (RBM) and its variants in Tensorflow Installation Using pip: pip install xrbm Examples Tut

Omid Alemi 55 Dec 29, 2022
Functional TensorFlow Implementation of Singular Value Decomposition for paper Fast Graph Learning

tf-fsvd TensorFlow Implementation of Functional Singular Value Decomposition for paper Fast Graph Learning with Unique Optimal Solutions Cite If you f

Sami Abu-El-Haija 14 Nov 25, 2021
StyleGAN2 - Official TensorFlow Implementation

StyleGAN2 - Official TensorFlow Implementation

NVIDIA Research Projects 10.1k Dec 28, 2022
An efficient and effective learning to rank algorithm by mining information across ranking candidates. This repository contains the tensorflow implementation of SERank model. The code is developed based on TF-Ranking.

SERank An efficient and effective learning to rank algorithm by mining information across ranking candidates. This repository contains the tensorflow

Zhihu 44 Oct 20, 2022
Implementation of Perceiver, General Perception with Iterative Attention in TensorFlow

Perceiver This Python package implements Perceiver: General Perception with Iterative Attention by Andrew Jaegle in TensorFlow. This model builds on t

Rishit Dagli 84 Oct 15, 2022
Minimal implementation of Denoised Smoothing: A Provable Defense for Pretrained Classifiers in TensorFlow.

Denoised-Smoothing-TF Minimal implementation of Denoised Smoothing: A Provable Defense for Pretrained Classifiers in TensorFlow. Denoised Smoothing is

Sayak Paul 19 Dec 11, 2022
Unofficial Implementation of MLP-Mixer in TensorFlow

mlp-mixer-tf Unofficial Implementation of MLP-Mixer [abs, pdf] in TensorFlow. Note: This project may have some bugs in it. I'm still learning how to i

Rishabh Anand 24 Mar 23, 2022
Tensorflow implementation for Self-supervised Graph Learning for Recommendation

If the compilation is successful, the evaluator of cpp implementation will be called automatically. Otherwise, the evaluator of python implementation will be called.

null 152 Jan 7, 2023
Minimal implementation of PAWS (https://arxiv.org/abs/2104.13963) in TensorFlow.

PAWS-TF ?? Implementation of Semi-Supervised Learning of Visual Features by Non-Parametrically Predicting View Assignments with Support Samples (PAWS)

Sayak Paul 43 Jan 8, 2023
Unofficial TensorFlow implementation of the Keyword Spotting Transformer model

Keyword Spotting Transformer This is the unofficial TensorFlow implementation of the Keyword Spotting Transformer model. This model is used to train o

Intelligent Machines Limited 8 May 11, 2022
A tensorflow implementation of GCN-LPA

GCN-LPA This repository is the implementation of GCN-LPA (arXiv): Unifying Graph Convolutional Neural Networks and Label Propagation Hongwei Wang, Jur

Hongwei Wang 83 Nov 28, 2022
Official Tensorflow implementation of "M-LSD: Towards Light-weight and Real-time Line Segment Detection"

M-LSD: Towards Light-weight and Real-time Line Segment Detection Official Tensorflow implementation of "M-LSD: Towards Light-weight and Real-time Line

NAVER/LINE Vision 357 Jan 4, 2023
Unofficial TensorFlow implementation of Protein Interface Prediction using Graph Convolutional Networks.

[TensorFlow] Protein Interface Prediction using Graph Convolutional Networks Unofficial TensorFlow implementation of Protein Interface Prediction usin

YeongHyeon Park 9 Oct 25, 2022
Tensorflow implementation of MIRNet for Low-light image enhancement

MIRNet Tensorflow implementation of the MIRNet architecture as proposed by Learning Enriched Features for Real Image Restoration and Enhancement. Lanu

Soumik Rakshit 91 Jan 6, 2023
Tensorflow python implementation of "Learning High Fidelity Depths of Dressed Humans by Watching Social Media Dance Videos"

Learning High Fidelity Depths of Dressed Humans by Watching Social Media Dance Videos This repository is the official tensorflow python implementation

Yasamin Jafarian 287 Jan 6, 2023
Tensorflow implementation of Swin Transformer model.

Swin Transformer (Tensorflow) Tensorflow reimplementation of Swin Transformer model. Based on Official Pytorch implementation. Requirements tensorflow

null 167 Jan 8, 2023