Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add functions for custom dataset in wgan #270

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions wgan/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### For custom dataset
- Put the image dataset inside `Keras-GAN/wgan/dataset/` folder
- Update the `self.img_rows`, `self.img_cols`, `self.channels` value.
- Update the following lines inside `build_generator()` function.
```python
model.add(Dense(128 * 7 * 7, activation="relu", input_dim=self.latent_dim))
model.add(Reshape((7, 7, 128)))
```
- Change the `(X_train, _), (_, _) = mnist.load_data()` with `X_train = load_image()`
27 changes: 24 additions & 3 deletions wgan/wgan.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from __future__ import print_function, division

from keras.datasets import mnist
from keras.layers import Input, Dense, Reshape, Flatten, Dropout
from keras.layers import BatchNormalization, Activation, ZeroPadding2D
from keras.layers.advanced_activations import LeakyReLU
from keras.layers import LeakyReLU
from keras.layers.convolutional import UpSampling2D, Conv2D
from keras.models import Sequential, Model
from keras.optimizers import RMSprop
Expand All @@ -16,11 +15,33 @@

import numpy as np

# For mnist dataset
from keras.datasets import mnist

# For custom dataset
from pathlib import Path
import cv2
import glob

'''
For custom dataset, Put the image dataset inside Keras-GAN/wgan/dataset/ folder. This load_image() function will load the images
'''
def load_image(dirName='dataset'):
path = str(Path().absolute()) + "/" + dirName + "/*.jpg"

images = []
for file in glob.glob(path):
img = cv2.imread(file)
img = cv2.resize(img, (228, 228))
images.append(img)

return np.array(images)

class WGAN():
def __init__(self):
self.img_rows = 28
self.img_cols = 28
self.channels = 1
self.channels = 1 # For RGB image, channel = 3
self.img_shape = (self.img_rows, self.img_cols, self.channels)
self.latent_dim = 100

Expand Down