TensorFlow implementation of "Learning from Simulated and Unsupervised Images through Adversarial Training"

Overview

Simulated+Unsupervised (S+U) Learning in TensorFlow

TensorFlow implementation of Learning from Simulated and Unsupervised Images through Adversarial Training.

model

Requirements

Usage

To generate synthetic dataset:

  1. Run UnityEyes with changing resolution to 640x480 and Camera parameters to [0, 0, 20, 40].
  2. Move generated images and json files into data/gaze/UnityEyes.

The data directory should looks like:

data
├── gaze
│   ├── MPIIGaze
│   │   └── Data
│   │       └── Normalized
│   │           ├── p00
│   │           ├── p01
│   │           └── ...
│   └── UnityEyes # contains images of UnityEyes
│       ├── 1.jpg
│       ├── 1.json
│       ├── 2.jpg
│       ├── 2.json
│       └── ...
├── __init__.py
├── gaze_data.py
├── hand_data.py
└── utils.py

To train a model (samples will be generated in samples directory):

$ python main.py
$ tensorboard --logdir=logs --host=0.0.0.0

To refine all synthetic images with a pretrained model:

$ python main.py --is_train=False --synthetic_image_dir="./data/gaze/UnityEyes/"

Training results

Differences with the paper

  • Used Adam and Stochatstic Gradient Descent optimizer.
  • Only used 83K (14% of 1.2M used by the paper) synthetic images from UnityEyes.
  • Manually choose hyperparameters for B and lambda because those are not specified in the paper.

Experiments #1

For these synthetic images,

UnityEyes_sample

Result of lambda=1.0 with optimizer=sgd after 8,000 steps.

$ python main.py --reg_scale=1.0 --optimizer=sgd

Refined_sample_with_lambd=1.0

Result of lambda=0.5 with optimizer=sgd after 8,000 steps.

$ python main.py --reg_scale=0.5 --optimizer=sgd

Refined_sample_with_lambd=1.0

Training loss of discriminator and refiner when lambda is 1.0 (green) and 0.5 (yellow).

loss

Experiments #2

For these synthetic images,

UnityEyes_sample

Result of lambda=1.0 with optimizer=adam after 4,000 steps.

$ python main.py --reg_scale=1.0 --optimizer=adam

Refined_sample_with_lambd=1.0

Result of lambda=0.5 with optimizer=adam after 4,000 steps.

$ python main.py --reg_scale=0.5 --optimizer=adam

Refined_sample_with_lambd=0.5

Result of lambda=0.1 with optimizer=adam after 4,000 steps.

$ python main.py --reg_scale=0.1 --optimizer=adam

Refined_sample_with_lambd=0.1

Training loss of discriminator and refiner when lambda is 1.0 (blue), 0.5 (purple) and 0.1 (green).

loss

Author

Taehoon Kim / @carpedm20

Comments
  • Fix for reuse that caused issues

    Fix for reuse that caused issues

    reuse variable was being unused. This actually caused some issues when the program was run, causing tensorflow to crash.

    Again, this fix may be incorrect. Please merge with caution.

    Kwang

    opened by kmyi 9
  • TypeError: zeros_initializer() takes at least 1 argument

    TypeError: zeros_initializer() takes at least 1 argument

    I got this error below when running the main.py script. I am using tensorflow 0.12.1. Can somebody help my out. Thanks a lot.

    [!] Found images in data/gaze/UnityEyes. [*] # of synthetic data: 7373, # of cropped_data: 7373 [*] Finished preprocessing synthetic gaze data. [*] Save samples images in data/gaze /usr/local/lib/python2.7/dist-packages/numpy/core/fromnumeric.py:2699: VisibleDeprecationWarning: rank is deprecated; use the ndim attribute or function instead. To find the rank of a matrix see numpy.linalg.matrix_rank. VisibleDeprecationWarning) Traceback (most recent call last): File "main.py", line 29, in tf.app.run(main=main, argv=[sys.argv[0]] + unparsed) File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/platform/app.py", line 43, in run sys.exit(main(sys.argv[:1] + flags_passthrough)) File "main.py", line 17, in main trainer = Trainer(config, rng) File "/home/w00378682/Documents/Detection/simulated-unsupervised-tensorflow/trainer.py", line 37, in init self.model = Model(config, self.data_loader) File "/home/w00378682/Documents/Detection/simulated-unsupervised-tensorflow/model.py", line 27, in init self._build_model() File "/home/w00378682/Documents/Detection/simulated-unsupervised-tensorflow/model.py", line 111, in _build_model self.R_x = self._build_refiner(self.normalized_x) File "/home/w00378682/Documents/Detection/simulated-unsupervised-tensorflow/model.py", line 294, in _build_refiner layer = repeat(layer, 4, resnet_block, scope="resnet") File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 177, in func_with_args return func(*args, **current_args) File "/home/w00378682/Documents/Detection/simulated-unsupervised-tensorflow/layers.py", line 47, in repeat outputs = slim.repeat(inputs, repetitions, layer, **kargv) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/layers/python/layers/layers.py", line 1670, in repeat outputs = layer(outputs, *args, **kwargs) File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 177, in func_with_args return func(*args, **current_args) File "/home/w00378682/Documents/Detection/simulated-unsupervised-tensorflow/layers.py", line 37, in resnet_block padding=padding, activation_fn=tf.nn.relu, scope="conv1") File "/usr/local/lib/python2.7/dist-packages/tensorflow/contrib/framework/python/ops/arg_scope.py", line 177, in func_with_args return func(*args, **current_args) File "/home/w00378682/Documents/Detection/simulated-unsupervised-tensorflow/layers.py", line 61, in conv2d biases_initializer=tf.zeros_initializer(dtype=tf.float32), scope=scope, **kargv) TypeError: zeros_initializer() takes at least 1 argument (1 given)

    I found the tf.zero_initializer() function should take another argument named shape, but I have no idea what the shape argument should be set. Besides, when I removed the dtype=tf.float32 argument, errors appeared in other parts.

    opened by Soledad89 2
  • Add conv layer, as in article

    Add conv layer, as in article

    In the article, it is mentioned that there is a 3x3 conv layer before the resnet blocks, in the refiner. I thought it might help to add this layer as well.

    opened by alex-mocanu 1
  • Local Adversarial loss

    Local Adversarial loss

    Hi,

    In the paper the authors mentioned about local adversarial loss and the fact that the discriminator is a fully convolutional, however I couldn't find that part in your code. Could you point me to that.

    Thanks

    opened by islamtashfiq 1
  • Where is output folder?

    Where is output folder?

    I tried to refine all images. python2 main.py --is_train=False --synthetic_image_dir="./data/gaze/UnityEyes/" --log_dir="./logs/*******/

    But, in output folder, it didn't contain refined images. Where are refined files?Do I have to designate output folder?

    opened by KentaroOtomo 0
  • SimGAN input

    SimGAN input

    @carpedm20 hello, I'm a beginner in image processing. Could you plz tell me the input of simGan is a patch of a synthetic image or a whole synthetic image? If the input of simGan is a patch of a synthetic image, what is the patch size? Thank you very much!

    opened by luochuwei 0
  • The value of coordinate in .json file

    The value of coordinate in .json file

    I used 640×480 UnityEyes image data, and check the size of output data is 55×35. Next, I want to correct the value of coordinate in .json files.
    I read gaze_data.py, but I only checked correction of coordinate point in crop part. Will .json file be modified to 55x35 when the output image is refined?

    opened by KentaroOtomo 1
  • activation_fn in refiner and discriminator is default None.

    activation_fn in refiner and discriminator is default None.

    In layers.py

    def conv2d(inputs, num_outputs, kernel_size, stride,
               layer_dict={}, activation_fn=None,
               #weights_initializer=tf.random_normal_initializer(0, 0.001),
               weights_initializer=tf.contrib.layers.xavier_initializer(),
               scope=None, name="", **kargv):
      outputs = slim.conv2d(
          inputs, num_outputs, kernel_size,
          stride, activation_fn=activation_fn, 
          weights_initializer=weights_initializer,
          biases_initializer=tf.zeros_initializer(dtype=tf.float32), scope=scope, **kargv)
      if name:
        scope = "{}/{}".format(name, scope)
      _update_dict(layer_dict, scope, outputs)
      return outputs
    

    and in model.py

      def _build_refiner(self, layer):
        with tf.variable_scope("refiner") as sc:
          layer = conv2d(layer, 64, 3, 1, scope="conv_1")
          layer = repeat(layer, 4, resnet_block, scope="resnet")
          layer = conv2d(layer, 1, 1, 1, 
                         activation_fn=None, scope="conv_2")
          output = tanh(layer, name="tanh")
          self.refiner_vars = tf.contrib.framework.get_variables(sc)
        return output 
    
      def _build_discrim(self, layer, name, reuse=False):
        with tf.variable_scope("discriminator", reuse=reuse) as sc:
          layer = conv2d(layer, 96, 3, 2, scope="conv_1", name=name)
          layer = conv2d(layer, 64, 3, 2, scope="conv_2", name=name)
          layer = max_pool2d(layer, 3, 1, scope="max_1", name=name)
          layer = conv2d(layer, 32, 3, 1, scope="conv_3", name=name)
          layer = conv2d(layer, 32, 1, 1, scope="conv_4", name=name)
          logits = conv2d(layer, 2, 1, 1, scope="conv_5", name=name)
          output = tf.nn.softmax(logits, name="softmax")
          self.discrim_vars = tf.contrib.framework.get_variables(sc)
        return output, logits
    
    

    Activation is None in most convolution layers. Is this OK? I think that gradients do not propagate properly.

    opened by shimacos37 1
  • Does anyone have a collection of refined photos I could use?

    Does anyone have a collection of refined photos I could use?

    I'd like to run the refined photos through a CGI vs. photo CNN and see the results. Does anyone have an already generated set of refined photos by any chance I could use?

    opened by wendyli 1
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