Giter Club home page Giter Club logo

image_completion_tf2's Introduction

Globally and Locally Consistent Image Completion

This is a Tensorflow2 Keras implementation of "Globally and Locally Consistent Image Completion".

Install python libraries

pip install pipenv
cd image_completion_keras
pipenv install

Prepare dataset

Please download appropriate image dataset and put it under the "data" folder and "test" folder. For example, please put the images as follows.

data
└── place365
    ├── Places365_00000001.jpg
    ├── Places365_00000002.jpg
    ├── Places365_00000003.jpg
    ├── Places365_00000004.jpg
    ├── Places365_00000005.jpg
    ├── Places365_00000006.jpg
    ├── Places365_00000007.jpg
    ├── Places365_00000008.jpg
    ...
test
└── place365_test
    ├── Places365_test_00000001.jpg
    ├── Places365_test_00000002.jpg
    ├── Places365_test_00000003.jpg
    ├── Places365_test_00000004.jpg
    ├── Places365_test_00000005.jpg
    ├── Places365_test_00000006.jpg
    ├── Places365_test_00000007.jpg
    ├── Places365_test_00000008.jpg
    ...

Train

pipenv shell
python train.py

Test

pipenv shell
python test.py

Result

result

image_completion_tf2's People

Contributors

neka-nat 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

image_completion_tf2's Issues

Can't training the model on GPU

Hello, I can train your model on CPU with the following configuration:CUDA8.0 Tensorflow(1.6.0) Keras (2.1.5) .
But when I install Tensorflow-gpu(1.6.0) instead of Tensorflow(1.6.0), the program does not work ,even if I tried Tensorflow-gpu1.5.0 to 1.0.0. My GPU is NVIDIA 1080.
Could you please find the error and tell me about your configuration of CUDA ,Tensorflow and so on,which is not showing in yout 'requirements.txt'.
Thanks !

Test.py

Hi, neka-nat,

I use Tensorflow-gpu (2.3.0) and keras (2.4.0).
When I run the test.py, I met the error as follows.

ValueError: in user code:

ValueError: Layer sequential_1 expects 1 inputs, but it received 2 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, 256, 256, 3) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(None, 256, 256, 1) dtype=float32>]

Please give me some advice, thanks!

where did you use the joint loss?

thanks for your work. I am running your code and have some questions.
where did you use the joint loss in your code? And I notice the weight for discrimitor loss is 0.0004 in the original paper. where did you set the parameter?
thanks, any help appreciated!

predict the test pic

Hi, neka-nat, Have you wrote code for testing ? If so , can you upload it ?

I have finished the training for master branch, I try to use "preds = com_model.predict(test_img)" to test my pictures after each training epoch, test_img.shape=(1,256,256,3).
But the test results are too bad which is totally different from the result of training. Give me some help please. How to predict images with arbitrary mask shape.

which branch should I choose?

Hello, I find you have three branches in this project, and you last submit your code in the anim branch.
Can you tell me the difference between these three branches if you are in rest?
Thanks a lot

ValueError: Layer sequential expects 1 inputs, but it received 2 input tensors.

Hi,

When I'm trying to run the test script it gives the following error:

ValueError: Layer sequential expects 1 inputs, but it received 2 input tensors. Inputs received: [<tf.Tensor 'IteratorGetNext:0' shape=(None, 128, 128, 3) dtype=float32>, <tf.Tensor 'IteratorGetNext:1' shape=(None, 128, 128, 1) dtype=float32>]

I don't understand where it comes from, since the cmp_model.predict([inputs, masks]) works fine in the train file. I have made no alteration to the code. I hope you can help me!

Test different size of images

@neka-nat hello, in the original paper, Computational times with different resolution of the input image are tested(such as 512x512,768x768 and 1024x1024), how can I train the model with (256,256,3) then use the model to test images with arbitrary shape ?

I have tried such as change input_shape to (None, None, 3) ,But it can't work. Only can change to (512,512,3), so the model only can deal with images with shape of (512,512,3)
Can you give me some advice ?

train.py

Hello, I am a new deep learning person and there is a mistake in train.py but I don't know what is wrong with it. "Local variable 'inputs' referenced before assignment" Check the inputs: they are clearly defined.

Computer available memory is reduced from 14G to 100M until the program is killed

Hello,I trained the cmp_model Tc = 18 times and d_model Td=2 times, then after the all_module trained 40 times ,the program was killed with the following error, and I find my computer available memory is reduced from 14G to 100M until the program is killed:
terminate called after throwing an instance of 'std::bad_alloc'
what(): std::bad_alloc
Abandoned (core dumped)

test.py

Hi neka-nat.
I put the required pictures where they are needed. I trained my model and ı have generator.h5, discriminator.h5 .
But my test.py only shows model summary. Can u help me please?
My code output is:

WARNING:tensorflow:No training configuration found in save file: the model was not compiled. Compile it manually.
Model: "sequential"


Layer (type) Output Shape Param #

conv2d (Conv2D) (None, 256, 256, 64) 4864


batch_normalization (BatchNo (None, 256, 256, 64) 256


activation (Activation) (None, 256, 256, 64) 0


conv2d_1 (Conv2D) (None, 128, 128, 128) 73856


batch_normalization_1 (Batch (None, 128, 128, 128) 512


activation_1 (Activation) (None, 128, 128, 128) 0


conv2d_2 (Conv2D) (None, 128, 128, 128) 147584


batch_normalization_2 (Batch (None, 128, 128, 128) 512


activation_2 (Activation) (None, 128, 128, 128) 0


conv2d_3 (Conv2D) (None, 64, 64, 256) 295168


batch_normalization_3 (Batch (None, 64, 64, 256) 1024


activation_3 (Activation) (None, 64, 64, 256) 0


conv2d_4 (Conv2D) (None, 64, 64, 256) 590080


batch_normalization_4 (Batch (None, 64, 64, 256) 1024


activation_4 (Activation) (None, 64, 64, 256) 0


conv2d_5 (Conv2D) (None, 64, 64, 256) 590080


batch_normalization_5 (Batch (None, 64, 64, 256) 1024


activation_5 (Activation) (None, 64, 64, 256) 0


conv2d_6 (Conv2D) (None, 64, 64, 256) 590080


batch_normalization_6 (Batch (None, 64, 64, 256) 1024


activation_6 (Activation) (None, 64, 64, 256) 0


conv2d_7 (Conv2D) (None, 64, 64, 256) 590080


batch_normalization_7 (Batch (None, 64, 64, 256) 1024


activation_7 (Activation) (None, 64, 64, 256) 0


conv2d_8 (Conv2D) (None, 64, 64, 256) 590080


batch_normalization_8 (Batch (None, 64, 64, 256) 1024


activation_8 (Activation) (None, 64, 64, 256) 0


conv2d_9 (Conv2D) (None, 64, 64, 256) 590080


batch_normalization_9 (Batch (None, 64, 64, 256) 1024


activation_9 (Activation) (None, 64, 64, 256) 0


conv2d_10 (Conv2D) (None, 64, 64, 256) 590080


batch_normalization_10 (Batc (None, 64, 64, 256) 1024


activation_10 (Activation) (None, 64, 64, 256) 0


conv2d_11 (Conv2D) (None, 64, 64, 256) 590080


batch_normalization_11 (Batc (None, 64, 64, 256) 1024


activation_11 (Activation) (None, 64, 64, 256) 0


conv2d_transpose (Conv2DTran (None, 128, 128, 128) 524416


batch_normalization_12 (Batc (None, 128, 128, 128) 512


activation_12 (Activation) (None, 128, 128, 128) 0


conv2d_12 (Conv2D) (None, 128, 128, 128) 147584


batch_normalization_13 (Batc (None, 128, 128, 128) 512


activation_13 (Activation) (None, 128, 128, 128) 0


conv2d_transpose_1 (Conv2DTr (None, 256, 256, 64) 131136


batch_normalization_14 (Batc (None, 256, 256, 64) 256


activation_14 (Activation) (None, 256, 256, 64) 0


conv2d_13 (Conv2D) (None, 256, 256, 32) 18464


batch_normalization_15 (Batc (None, 256, 256, 32) 128


activation_15 (Activation) (None, 256, 256, 32) 0


conv2d_14 (Conv2D) (None, 256, 256, 3) 867


batch_normalization_16 (Batc (None, 256, 256, 3) 12


activation_16 (Activation) (None, 256, 256, 3) 0

Total params: 6,076,495
Trainable params: 6,070,537
Non-trainable params: 5,958


A keras question about bulid network

#hello neka-nat.
In the train.py line 98 and 99. your code is
'''
d_container = Container([org_img, in_pts], discriminator([org_img, in_pts]))
d_model = Model([org_img, in_pts], d_container([org_img, in_pts]))
'''
in line 76 you create discriminator.'discriminator = model_discriminator(input_shape, local_shape)'
can you tell me the difference between discriminator and d_model?

I am confused about why you such design discriminator and d_model. Please tell me if you are free.
Thanks

I cant load G-discriminator

hello,neka-nat!
I am just a bignner. My GPU is low, so i need to load G-discriminator to continue traning. But i can't load G-discriminator like before,It may be caused by the code in line 101,93 of 'mode.py'.I tried some methods that didn't work,So,how do you do it?
Looking forward to your answers..

data preprocess

Do we need to normalize the training images into the range of (-1,1) before feed them into the network?

Why d_container.trainable is set to False in the train.py?

Thanks a lot for your contribution. When learning the code in the train.py, I find d_container.trainable is set to False. It means that the discriminator does not need to be trained? However, it seems that d_model is trained through "d_loss_real = d_model.train_on_batch([inputs, points], valid)". Can you tell me the reason? Thank you very much! I am looking forward for your response.

question

hello,and I have a question,how can I get the datasets,

Set "d_container.trainable = True" after training all_model

Thank you for the great work. Don't you think d_container.trainable should be set to True after training all_model.
Something like this:

d_container.trainable = True 
all_model.compile(loss=['mse', 'binary_crossentropy'], loss_weights=[1.0, alpha], optimizer=optimizer) 

error on Keras 2.2.2 merge

I get this error on Keras 2.2.2.
Any idea how to replace the merge?

  File "train.py", line 160, in <module>
    main()
  File "train.py", line 156, in main
    example_gan()
  File "train.py", line 84, in example_gan
    in_img = merge([org_img, mask],mode=lambda x: x[0] * (1 - x[1]),output_shape=input_shape)
TypeError: 'module' object is not callable```

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.