Giter VIP home page Giter VIP logo

dcgan-keras's Introduction

DCGAN-Keras

Introduction

This is a relatively simple Deep Convolutional Generative Adversarial Network built in Keras. Given a dataset of images it will be able to generate new images similar to those in the dataset. It was originally built to generate landscape paintings such as the ones shown below. As a result, also contained are some scripts for collecting artwork from ArtUK and resizing images to make them work with the network. There are also examples of it being trained on Space imagery as well.

Example Outputs

Landscapes

The following images were generated at 256x192, then upscaled using the bigjpg tool which is a GAN based upscaling tool.

Mountain Lake Peninsula
Hill Bushes Grassy Mountain

Here is a selection of images generated at 128x128

128x Selection

Space Images

128x Selection

Getting Started

This section talks about how to use this model, its prerequisites and its paramaters.

Prerequisites

This model was built using the following packages and versions (earlier versions may still work):

DCGAN.py

- Python 3.6
- tensorflow/tensorflow_gpu 1.11
- Keras 2.2.4
- Pillow 5.1.0
- numpy 1.14.5
- scipy 1.1.0
- Ideally GPU/CUDA support setup with tensorflow_gpu, otherwise training will take a very long time

scrape_imgs.py

- Python 3.6
- requests 2.18.4
- bs4 0.0.1

resize_imgs.py

- Pillow 5.1.0

Parameters for DCGAN.py

List of paramaters for the DCGAN.py file:

  • --load_generator: Path to existing generator weights file
    • e.g. ../data/models/generat.h5
  • --load_discriminator: Path to existing discriminator weights file
    • e.g. ../data/models/discrim.h5
  • --data: Path to directory of images of correct dimensions, using *.[filetype] (e.g. *.png) to reference images
    • e.g. ../data/resized/paintings_256x/*.png
  • --sample: If given, will generate that many samples from existing model instead of training
    • e.g. 20
  • --sample_thresholds: The values between which a generated image must score from the discriminator
    • e.g. (0.0,0.1)
  • --batch_size: Number of images to train on at once
    • e.g. 24
  • --image_size: Size of images as tuple (height,width). Height and width must both be divisible by (2^5)
    • e.g. (192,256)
  • --epochs: Number of epochs to train for
    • e.g. 500000
  • --save_interval: How many epochs to go between saves/outputs
    • e.g. 100
  • --output_directory: Directoy to save weights and images to
    • e.g. ../data/output

Example Usage

DCGAN.py

To train a fresh model on some data, the following command template is ideal:

python DCGAN.py --data /data/images/*.png --epochs 100000 --output /data/output

Modifications can be made to image size, batch size etc. using the parameters. If your GPU doesn't have enough memory, you can change the size of the filters within the file, the image size and the batch size to better suit your GPU capability.

scrape_imgs.py

In it's current state it will download all of the images on this ArtUK page. You can modify the URL given in the file with any page or set of categories on ArtUK and it will download those instead.

resize_imgs.py

Will resize any directory of imgs to the specified size and store the new imgs in a different directory

Licensing

This project is released under the MIT license, see LICENSE.md for more details.

dcgan-keras's People

Contributors

gypsydangerous avatar mitchelljy 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

Watchers

 avatar

dcgan-keras's Issues

Quick fix for "Error while reading resource variable"

Hi,

I was getting the following error but was able to resolve it with the little addition listed below, so thought I'd point it out for anyone having troubles.

" BaseCollectiveExecutor::StartAbort Failed precondition: Error while reading resource variable _AnonymousVar101 from Container: localhost. This could mean that the variable was uninitialized. Not found: Resource localhost/_AnonymousVar101/class tensorflow::Var does not exist."

Solved with:
keras-team/keras#13550 (comment)

Thanks so much for putting the DCGAN together - great stuff.

RosourceExhaustedError

Hello,
Thank you for sharing this project. I copied the architecture of your DCGAN to Tensorflow-Keras and tried to train the model on 128 x 128 grayscale images. I get a direct ResourceExhaustedError, my GPU doesnt seem to handle this model. Even if I downgrade the Batch Size etc. So my question: On which device did u got these good looking results? Is there a way to get it running on my laptop? Or shall i give up & check for cloud computing etc?
If u got some answers I would be thankful!

Training fail

Hi

Training fail

raise ValueError('malformed node or string: ' + repr(node))
ValueError: malformed node or string: (192, 256)

D and G loss stop changing. Hyperparameters anyone?

Windows 10
All dependencies uptodate.
Arguments:
python DCGAN.py --data ./data/portrait_large_homogen_256/*.jpg --batch_size 8 --image_size (256,256) --epochs 500000 --save_interval 500 --output_directory ./data/output

Dataset consists of ~6300 jpeg art portrait taken from the wikiart dataset. All resized to 256x256 RGB.
After some epochs the losses stall.

13882 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13883 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13884 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13885 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13886 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13887 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13888 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13889 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13890 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13891 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13892 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13893 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13894 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13895 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13896 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13897 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13898 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13899 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13900 [D loss: 9.985954284667969 | D Accuracy: 37.5] [G loss: 1.192093321833454e-07]
13901 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]
13902 [D loss: 7.971192359924316 | D Accuracy: 50.0] [G loss: 1.192093321833454e-07]

Second question: I really wonder why I can run this with 256x output_size and batch_size 8 (higher not tested) on my gtx 980 4gb. And at that speed...
All other dcgan codes here on github fail with such a network.

About pre-training

Hello,
I would like to ask about the trained generator weights file and discriminator weights file in dcgan code, I did not find them in the code, could you please tell me whether they can be disclosed?

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.