Code Monkey home page Code Monkey logo

image-outpainting's Introduction

Keras implementation of Image OutPainting

This is an implementation of Painting Outside the Box: Image Outpainting paper from Standford University. Some changes have been made to work with 256*256 image:

  • Added Identity loss i.e from generated image to the original image
  • Removed patches from training data. (training pipeline)
  • Replaced masking with cropping. (training pipeline)
  • Added convolution layers.

Results

The model was train with 3500 scrapped beach data with agumentation totalling upto 10500 images for 25 epochs. Demo

Recursive painting

Demo

Install Requirements

sudo apt-get install curl
sudo pip3 install -r requirements.txt

Get Started

  1. Prepare Data:
    # Downloads the beach data and converts to numpy batch data
    # saves the Numpy batch data to 'data/prepared_data/'
    sh prepare_data.sh
  2. Build Model
    • To build Model from scratch you can directly run 'outpaint.ipynb'
      OR
    • You can Download my trained model and move it to 'checkpoint/' and run it.

References

image-outpainting's People

Contributors

bendangnuksung avatar dependabot[bot] 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  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  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

image-outpainting's Issues

Discriminator loss doesn't go down at all?

Isn't the code just training generator? The discriminator loss doesn't seem to be going down at all. Also there is a line .trainable = False for discriminator, I'm not super familiar with kera, but does this mean all params in discriminator are freezed? If that's the case, isn't this just training a CNN

Build Model

Hi, your trained model download link is broken. Hope you'll fix the link soon.

Why the loss for discriminator is not binary_crossentropy?

def dcrm_loss(y_true, y_pred): return -tf.reduce_mean(tf.log(tf.maximum(y_true, EPSILON)) + tf.log(tf.maximum(1. - y_pred, EPSILON)))

Here is your dcrm_loss. However, I think the correct loss for discriminator is just binary_crossentropy, which is:

-y_true*tf.reduce_mean(tf.log(tf.maximum(y_pred, EPSILON)) + (1-y_true)*tf.log(tf.maximum(1. - y_pred, EPSILON)))

ImportError: No module named keras_contrib.layers.normalization.instancenormalization

No matter what I do, every time I run outpaint.ipynb I get an error saying there's no keras_contrib module even though I see it listed using pip freeze. I looked at the issues on the keras-contrib Github page and people who have run into the same issue said they installed Python 3.7 but that hasn't been released yet. Do you have any idea why this might be happening and how to resolve it??

how should i test?

i downloaded your trained model .but i didn't see test.py , how should i test your model

Fine, I've cloned the branch and trained.... then, I did not see the promised results..

Fine, author.
May you provide some details on the training for help?
I've got a total black outpainting for the images for the images after 100+ epochs.
I'm using python 3.5
keras 2.2.0
keras-contrib 2.0.8 (the version it takes were 0.0.2 in coding)
and etc
Fine, I though the etc would not affect the result greatly...
Tensorflow 1.8.0
Cuda 9.1
Cudnn 7.0.5

Thank you for reading.

i want to change mask,a problem occured

it's my code :

 def mask_width(img):
    image = img.copy()
    height = image.shape[0]
    width = image.shape[1]
    new_width = int(width * MASK_PERCENTAGE)
    mask = np.ones([height, new_width, 3])
    missing_x = img[:, :new_width]
    missing_y = img[:, width - new_width:]
    missing_part = np.concatenate((missing_x, missing_y), axis=1)
    image = image[:, :width - new_width]
    image = image[:, new_width:]
    return image, missing_part
    
def get_masked_images(images):
    mask_images = []
    missing_images = []
    for image in images:
        mask_image, missing_image = mask_width(image)
        mask_images.append(mask_image)
        missing_images.append(missing_image)
    return np.array(mask_images), np.array(missing_images)

def get_demask_images(original_images, generated_images):
    demask_images = []
    for o_image, g_image in zip(original_images, generated_images):
        width = g_image.shape[1] // 2
        x_image = g_image[:, :width]
        y_image = g_image[:, width:]
        o_image = np.concatenate((x_image,o_image, y_image), axis=1)
        demask_images.append(o_image)
    return np.asarray(demask_images)

i also change def dcrm_loss
d_input_shape = (int(INPUT_SHAPE[0] * (MASK_PERCENTAGE * 2)), int(INPUT_SHAPE[1] * (MASK_PERCENTAGE * 2)), INPUT_SHAPE[2])

and change def gen_loss
g_input_shape = (int(INPUT_SHAPE[0] * (MASK_PERCENTAGE * 2)), int(INPUT_SHAPE[1] * (MASK_PERCENTAGE * 2)), INPUT_SHAPE[2])

and i train:
Error when checking input: expected input_2 to have shape (256, 128, 3) but got array with shape (128, 128, 3)
......
thanks for your time!

DCRM doesn't work..

In outpaint.ipynb, below line gives the following error.
CONF_GENERATED_IMAGE = DCRM(GENERATED_IMAGE)
ValueError: number of input channels does not match corresponding dimension of filter, 3 != 256

I found that the shape of GENERATED_IMAGE is (None, 3, 128, 4) based on the summary but DCRM wants (None, 256, 128, 3) as an input. Could you guess what's going on please?

I only added 2 lines on top of the outpaint.ipynb, which are
import os os.environ['KERAS_BACKEND']='tensorflow'
otherwise, I get an error on the code
DCRM = build_discriminator()
TypeError: Failed to convert object of type <class 'theano.tensor.var.TensorVariable'> to Tensor. Contents: /dense_2_target. Consider casting elements to a supported type.

summary of GEN


Layer (type) Output Shape Param #

input_2 (InputLayer) (None, 256, 128, 3) 0


conv2d_6 (Conv2D) (None, 64, 128, 3) 409664


re_lu_1 (ReLU) (None, 64, 128, 3) 0


dropout_6 (Dropout) (None, 64, 128, 3) 0


instance_normalization_1 (In (None, 64, 128, 3) 2


conv2d_7 (Conv2D) (None, 128, 64, 2) 131200


re_lu_2 (ReLU) (None, 128, 64, 2) 0


dropout_7 (Dropout) (None, 128, 64, 2) 0


instance_normalization_2 (In (None, 128, 64, 2) 2


conv2d_8 (Conv2D) (None, 256, 32, 1) 524544


re_lu_3 (ReLU) (None, 256, 32, 1) 0


dropout_8 (Dropout) (None, 256, 32, 1) 0


instance_normalization_3 (In (None, 256, 32, 1) 2


conv2d_9 (Conv2D) (None, 512, 32, 1) 2097664


re_lu_4 (ReLU) (None, 512, 32, 1) 0


dropout_9 (Dropout) (None, 512, 32, 1) 0


instance_normalization_4 (In (None, 512, 32, 1) 2


conv2d_10 (Conv2D) (None, 512, 32, 1) 4194816


re_lu_5 (ReLU) (None, 512, 32, 1) 0


dropout_10 (Dropout) (None, 512, 32, 1) 0


instance_normalization_5 (In (None, 512, 32, 1) 2


conv2d_11 (Conv2D) (None, 512, 32, 1) 4194816


re_lu_6 (ReLU) (None, 512, 32, 1) 0


dropout_11 (Dropout) (None, 512, 32, 1) 0


instance_normalization_6 (In (None, 512, 32, 1) 2


conv2d_12 (Conv2D) (None, 512, 32, 1) 4194816


re_lu_7 (ReLU) (None, 512, 32, 1) 0


dropout_12 (Dropout) (None, 512, 32, 1) 0


instance_normalization_7 (In (None, 512, 32, 1) 2


conv2d_13 (Conv2D) (None, 512, 32, 1) 4194816


re_lu_8 (ReLU) (None, 512, 32, 1) 0


dropout_13 (Dropout) (None, 512, 32, 1) 0


instance_normalization_8 (In (None, 512, 32, 1) 2


conv2d_14 (Conv2D) (None, 512, 32, 1) 4194816


re_lu_9 (ReLU) (None, 512, 32, 1) 0


dropout_14 (Dropout) (None, 512, 32, 1) 0


instance_normalization_9 (In (None, 512, 32, 1) 2


conv2d_15 (Conv2D) (None, 512, 32, 1) 4194816


re_lu_10 (ReLU) (None, 512, 32, 1) 0


dropout_15 (Dropout) (None, 512, 32, 1) 0


instance_normalization_10 (I (None, 512, 32, 1) 2


conv2d_16 (Conv2D) (None, 512, 32, 1) 4194816


re_lu_11 (ReLU) (None, 512, 32, 1) 0


dropout_16 (Dropout) (None, 512, 32, 1) 0


instance_normalization_11 (I (None, 512, 32, 1) 2


conv2d_transpose_1 (Conv2DTr (None, 256, 64, 2) 2097408


re_lu_12 (ReLU) (None, 256, 64, 2) 0


conv2d_transpose_2 (Conv2DTr (None, 128, 128, 4) 524416


re_lu_13 (ReLU) (None, 128, 128, 4) 0


conv2d_17 (Conv2D) (None, 128, 128, 4) 262272


re_lu_14 (ReLU) (None, 128, 128, 4) 0


dropout_17 (Dropout) (None, 128, 128, 4) 0


instance_normalization_12 (I (None, 128, 128, 4) 2


conv2d_18 (Conv2D) (None, 64, 128, 4) 131136


re_lu_15 (ReLU) (None, 64, 128, 4) 0


dropout_18 (Dropout) (None, 64, 128, 4) 0


instance_normalization_13 (I (None, 64, 128, 4) 2


conv2d_19 (Conv2D) (None, 3, 128, 4) 3075

Total params: 35,545,117
Trainable params: 35,545,117
Non-trainable params: 0


summary of DCRM


Layer (type) Output Shape Param #

input_1 (InputLayer) (None, 256, 128, 3) 0


conv2d_1 (Conv2D) (None, 32, 64, 2) 204832


leaky_re_lu_1 (LeakyReLU) (None, 32, 64, 2) 0


dropout_1 (Dropout) (None, 32, 64, 2) 0


conv2d_2 (Conv2D) (None, 64, 32, 1) 51264


leaky_re_lu_2 (LeakyReLU) (None, 64, 32, 1) 0


dropout_2 (Dropout) (None, 64, 32, 1) 0


conv2d_3 (Conv2D) (None, 64, 16, 1) 102464


leaky_re_lu_3 (LeakyReLU) (None, 64, 16, 1) 0


dropout_3 (Dropout) (None, 64, 16, 1) 0


conv2d_4 (Conv2D) (None, 128, 8, 1) 204928


leaky_re_lu_4 (LeakyReLU) (None, 128, 8, 1) 0


dropout_4 (Dropout) (None, 128, 8, 1) 0


conv2d_5 (Conv2D) (None, 128, 4, 1) 409728


leaky_re_lu_5 (LeakyReLU) (None, 128, 4, 1) 0


dropout_5 (Dropout) (None, 128, 4, 1) 0


flatten_1 (Flatten) (None, 512) 0


dense_1 (Dense) (None, 1024) 525312


dense_2 (Dense) (None, 1) 1025

Total params: 1,499,553
Trainable params: 1,499,553
Non-trainable params: 0


train epoch

if i set epoch=200,will the result become worse? must i set epoch=500 and the train result could be the best?

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.