1
$\begingroup$

I have made a DCGAN which I am trying to train on custom dataset of only 1200 images. I have tried to gather more, but even gathering these 1200 was hard enough. If you are wondering I used Google Chromes extension "Fakun Batch Download Image" to gather my dataset.

TRAINING DETAILS: In training procedure I am simultaneously updating parameters of both, Generator, and Discriminator network. I've read that it works much better then training only one player ( Discriminator ) for K steps and then other ( Generator ) for one.

QUESTION: Should I perform maybe some kind of transformation on all of those images and then merge transformed images with the initial ones, or something similar?

$\endgroup$
  • $\begingroup$ What kind of images are you using. Surely if they are images people may have resources to increase your number of instances. $\endgroup$ – JahKnows Feb 8 '18 at 7:29
  • 1
    $\begingroup$ Hahah I am sort of embarrassed to say. I've created a Dragon Ball Z character dataset . My aim is to generate new DBZ characters based on the ones that already exist. $\endgroup$ – Stefan Radonjic Feb 8 '18 at 10:38
  • $\begingroup$ That sounds pretty dope. I have some suggestions give me a moment. What are the sizes of the images? And will they be in color. These two factors will increase the complexity of the problem and may lead to poor results with insufficient data. $\endgroup$ – JahKnows Feb 8 '18 at 10:42
  • $\begingroup$ Images are 64x64 and yes they are in color. You think i should convert them to Gray-scale? $\endgroup$ – Stefan Radonjic Feb 8 '18 at 11:43
  • $\begingroup$ If you convert them to greyscale then you will reduce your problem's complexity by a factor of 3. That would make things way better. $\endgroup$ – JahKnows Feb 8 '18 at 11:48
2
$\begingroup$

Extending a small dataset comprised of images

A deep learning algorithm will learn a mapping function from your input space to your outputs. The variations in your input images will be learned within this function. Thus, you will want to consider this fact when you augment your dataset. The distribution of your input features should be concise as to what you plan to model.

You are thus left balancing between adding data and adding variability to your input space. For example, it might not be worth it to rotate by 180 degrees when trying to generate Dragon Ball characters. Their heads should not be where their feet are. You would want your network to understand that the bottom of the image should contain some strange space boots, and the top exotic haircuts or bald heads.

Augmenting images

Here are some useful transformations that you can use to get more data

  • Apply transformations (rotations, translations)
  • Mirror the image
  • Add distortions
  • Change zoom factor
  • Add blurring thus to better generalize the input data
  • Invert colors (skew, add brightness, etc.)

In Keras

In Keras you can use the ImageDataGenerator functions.

import numpy as np
from keras.datasets import mnist
from keras.preprocessing.image import ImageDataGenerator
import matplotlib.pyplot as plt
%matplotlib inline

# load data
(X_train, y_train), (X_test, y_test) = mnist.load_data()
X_train = X_train.astype('float32')

# set up your data generator
datagen = ImageDataGenerator(
   featurewise_center=True,
   featurewise_std_normalization=True,
   rotation_range=60,
   width_shift_range=0.2,
   height_shift_range=0.2,
   shear_range=0.2,
   zoom_range=0.2,
   horizontal_flip=True,
   vertical_flip = True)

# Fit the generator using your data
datagen.fit(X_train.reshape((len(X_train), 28, 28, 1)))

# let's look at some generated images
image = X_train[5]

plt.figure(figsize=(12,12))
plt.subplot(4, 4, 1)
plt.imshow(image.reshape((28,28)),  cmap='gray')
for j in range(15):
   augmented = datagen.random_transform(image.reshape((28,28,1)))
    plt.subplot(4, 4, j+2)
    plt.imshow(augmented.reshape((28,28)),  cmap='gray')
plt.tight_layout()
plt.show()
| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.