Giter Site home page Giter Site logo

leehomyc / faster-high-res-neural-inpainting Goto Github PK

View Code? Open in Web Editor NEW
1.3K 48.0 213.0 37.13 MB

High-Resolution Image Inpainting using Multi-Scale Neural Patch Synthesis

Home Page: http://www.harryyang.org/inpainting

License: MIT License

Lua 100.00%
deep-learning deep-learning-papers machine-learning

faster-high-res-neural-inpainting's Introduction

High-Resolution Image Inpainting using Multi-Scale Neural Patch Synthesis

[update 10/10/2017] Example of photo editing using inpainting at the project website.

[update 9/30/2017] We shared the inpainting result of 200 ImageNet images and 100 Paris StreetView Images at the project website.

[update 9/16/2017] We increase the speed of original version by 6x (30s/image on GPU).

[update 9/16/2017] All raw images of the paper and supplementary material (including input, output and intermediate results) are available at the project website.

teaser

[Faster Inpainting Updates]:

  1. We remove layer 12 of vgg in texture optimization.
  2. In texture optimization, we have three scales and 100 iterations at each scale. Now it only computes the nearest patch at the first iteration of each scale, and re-use the nearest index in later iterations.

This greatly increases the speed at the cost of very subtle inpainting quality.

This is the code for High-Resolution Image Inpainting using Multi-Scale Neural Patch Synthesis. Given an image, we use the content and texture network to jointly infer the missing region. This repository contains the pre-trained model for the content network and the joint optimization code, including the demo to run example images. The code is adapted from the Context Encoders and CNNMRF. Please contact Harry Yang for questions regarding the paper or the code. Note that the code is for research purpose only.

Demo

(The code may give better results when supplying 32 different images (a batch) as input to the content network rather than using one single image as input. This may be due to the mismatch of the training and testing coefficients in batch normalization.)

  git clone https://github.com/leehomyc/High-Res-Neural-Inpainting.git
  • Download the pre-trained models for the content and texture networks and put them under the folder models/.

  • Run the Demo

  cd High-Res-Neural-Inpainting
  # This will use the trained model to generate the output of the content network
  th run_content_network.lua
  # This will use the trained model to run texture optimization
  th run_texture_optimization.lua
  # This will generate the final result
  th blend.lua

Citation

If you find this code useful for your research, please cite:

@InProceedings{Yang_2017_CVPR,
author = {Yang, Chao and Lu, Xin and Lin, Zhe and Shechtman, Eli and Wang, Oliver and Li, Hao},
title = {High-Resolution Image Inpainting Using Multi-Scale Neural Patch Synthesis},
booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
month = {July},
year = {2017}
}

faster-high-res-neural-inpainting's People

Contributors

leehomyc avatar merofeev 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  avatar  avatar  avatar  avatar

faster-high-res-neural-inpainting's Issues

I'm sorry to bother you,but I have some questions

@leehomyc
Hi,

I'm very confused about pretrained network VGG-19 which seems to apply on classfication,how does it work in image inpainting?There are hundreds of excellent networks.Why we just choose this one?the way we use the pretrained model is that we use the pretrained model and put the incomplete picture as model input,croping it to 224,and as a result,getting a coarse result?

I would very appreciate if you could help me,thank you!

Thanks,

Issue While Running run_texture_optimization.lua

Getting this error if i ran run_texture_optimization.lua
/torch/install/share/lua/5.1/loadcaffe/ffi.lua:10: bad argument #1 to 'load' (string expected, got nil)
stack traceback:
[C]: in function 'error'
/users/rajat.a/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'require'
run_texture_optimization.lua:70: in main chunk
[C]: in function 'dofile'
...at.a/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: at 0x00405d50

would be helpful if resolved

数据集

你好,想问一下,使用的数据集是什么呢,是成对的数据吗(就是有空缺图片跟完整图像一一对应)

Train content network.

Is there code to train the content network? Or could you point us to how to train the content network?

How to realize local texture loss

I am amazing about the technology about the local texture loss , when I read your paper ,I try to realize the local texture loss with CNNMRF ,but failed. Could you point it in your code? I will read it carefully.
Do you need more GPU-memory for your code to train than context-encoder?

wrong of running th run_texture_optimization.lua

thank you for providing your code.
When I run th run_texture_optimization.lua, it shows that it has something wrong of
init.lua: 724: bad argument #2 to "new"((number has no integer representation))

does anyone encounter the same problem? Thanks

Does texture network contain holistic content constraint?

Hi,I have read your new paper,which is clear than the first.
However,through your paper,I found a question.
Does texture network contain holistic content constraint?The content network,which have been trained,contains l2 loss and adversarial loss.But there is an another holistic content constraint in your joint loss function(Equation 1).I don't understand.Is there an extra holistic content constraint in texture network,which is different from the content loss in content network.By the way,does the Equation 1 only belong to the texture network?
Thank you very much.

实在看不懂论文里面的x到底是什么...

大佬你好,你们所写论文里面的x到底是什么?怎么迭代实现超分辨率的?网上查找到的资料,与你们发在CVPR上的图不一致,这个迭代该怎么理解?还望不吝赐教!

Recontructed output obtained for a Paris image is not as clear

Hi,

The final reconstructed output for a Paris test image as mentioned in the paper >https://arxiv.org/pdf/1611.09969v2.pdf

is given below
capture

However, the output that we received for the same test image is as below:
result_0016

I used the same models as mentioned : https://drive.google.com/open?id=0BxYj-YwDqh45XzZVTXF1dnJXY28

Could you please let me know the reason for the same?

Also, i tested the source code for couple of images from ImageNet. That was also not reconstructed as expected.
Please find the results as attached here:
result_0026
result_0027
result_0028
result_0024

Kindly let me know your opinion on the same.

Thank you.

how to create mask.png?

hi, how can i change the mask location used in blend,lua?
ex: i want to make the square mask to mask the top left of the image instead of the center?
can u help

get exception when run th blend.lua

/root/torch/install/bin/luajit: inconsistent tensor size, expected r_ [4 x 512 x 512], t [4 x 512 x 512] and src [3 x 512 x 512] to have the same number of elements, but got 1048576, 1048576 and 786432 elements respectively at /root/torch/pkg/torch/lib/TH/generic/THTensorMath.c:902
stack traceback:
[C]: at 0x7fa61a805110
[C]: in function 'cmul'
blend.lua:8: in main chunk
[C]: in function 'dofile'
/root/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: at 0x004064f0

Not able to download the content models

Apparently the dropbox account you have as a download server in your bash script is suspended. I get this error when I try to run ./models/download_content_models.sh:

--2017-02-21 12:30:56-- https://www.dropbox.com/s/skco1wdeeq699z1/imagenet_inpaintCenter.t7?dl=0 Resolving www.dropbox.com (www.dropbox.com)... 162.125.1.1 Connecting to www.dropbox.com (www.dropbox.com)|162.125.1.1|:443... connected. HTTP request sent, awaiting response... 429 Too Many Requests 2017-02-21 12:30:56 ERROR 429: Too Many Requests.

Handling Inapinting for Non Center Region

Hey!

Thanks for the code. I was trying to play around with this and had a query. I wanted to know how to inpaint images when the region of interest is not a square at the centre of the image but something which is quite arbitrary. For example, patch inpainting a detected object or a person in any part of image (espcially non center ones). Is there a way to do it here?

Thanks !

Unknown image x in the paper

Hello, thanks for your work. In Content Network, we will use holistic content loss Ec(h(x, R), f(x0)), but how we get the unknown image x? And what the relationship between x and f(x0), does it have a function about x and f(x0)? What kind of difference between f(x0) and h(x, R)?
Thanks!

attempt to call method 'cl'[...]

$ th run_texture_optimization.lua

torch/install/bin/luajit: /e/Ne/High-Res-Neural-Inpainting/mylib/mrf.lua:52: attempt to call method 'cl' (a nil value)

why are matrix values being changed here?

Hi, I noticed that in run_content_network.lua, these two lines have been used:

    output[output:gt(1)]=1
    output[output:lt(-1)]=-1

I was wondering what is the reason behind this?

About the texture network code

Hello! I have read your article and the code. There are some questions i would like to consult you: 1.Does the content loss in the texture network code file (transfer_CNNMRF_wrapper) not mean the content loss of the content network? 2.What exactly way does the patchmatch use to search for the nearest patch? I printed target_feature_map, found that 18 kinds of convolution image were divided into 1933+493=2426,patches totally, and then sampled these patches, the number of sampling patches is equal to the previous each convolution image is divided into, I didn't see the point of distinguishing the hole inside and the hole outside in the code, and is it different from the article? 3. Does the patchmatch look for the closest patch in the image input's feature map of the middle layer at each scale? The input is the image being hollowed out . Does the result of each iteration return as the image input and then continue to look for the closest patch from the image input's feature map of the middle layer ? 4. I print the output of the net at the first scale . It's a convolution image of 5121616. How can change it into an optimal output image x? Does the optimal output image of the first scale x return as the image named fake of and continue to enter the texture network? If this is not the case, then where is the x to be sent to initialization the next scale? 5.I print the net and find it only use ten convolution layers different from the VGG sixteen convolution layers. And it doesn't use fully-connected layers. This is why.
Wish to receive your reply. Thank you.

I have problems with running the code with input images of 256*256.

I have several images whose sizes are 256*256. I don't want to resize it to 512*512 as they
will get blurry. Then I come to realize that the following code is hard, just specially for 512*512.

target_image[{{},{117,232},{117,396}}]:copy(target_image[{{},{1,116},{117,396}}])
target_image[{{},{233,280},{117,396}}]:copy(target_image[{{},{69,116},{117,396}}])
target_image[{{},{281,396},{117,396}}]:copy(target_image[{{},{397,512},{117,396}}])

Would you please give the corresponding numbers for 256*256.

Bilinear Interpolation

In the paper, you said," Since Context Encoder only works with 128128 images and when
the input is larger, we directly upsample the 128
128 output to 512*512 using bilinear interpolation."
But when I use bilinear interpolation, I find the image blurring.

TensorFlow Implementation

Thanks for your excellent work! I wonder if there is any TensorFlow Implementation, or others in Python?

Error while running commands

I am trying to run the command :
th run_content_network.lua

And I am getting an error message :

/Users/arqam/torch/install/bin/luajit: /Users/arqam/torch/install/share/lua/5.1/trepl/init.lua:389: module 'cudnn' not found:No LuaRocks module found for cudnn no field package.preload['cudnn'] no file '/Users/arqam/.luarocks/share/lua/5.1/cudnn.lua' no file '/Users/arqam/.luarocks/share/lua/5.1/cudnn/init.lua' no file '/Users/arqam/torch/install/share/lua/5.1/cudnn.lua' no file '/Users/arqam/torch/install/share/lua/5.1/cudnn/init.lua' no file './cudnn.lua' no file '/Users/arqam/torch/install/share/luajit-2.1.0-beta1/cudnn.lua' no file '/usr/local/share/lua/5.1/cudnn.lua' no file '/usr/local/share/lua/5.1/cudnn/init.lua' no file '/Users/arqam/.luarocks/lib/lua/5.1/cudnn.so' no file '/Users/arqam/torch/install/lib/lua/5.1/cudnn.so' no file './cudnn.so' no file '/usr/local/lib/lua/5.1/cudnn.so' no file '/usr/local/lib/lua/5.1/loadall.so' stack traceback: [C]: in function 'error' /Users/arqam/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'require' run_content_network.lua:6: in main chunk [C]: in function 'dofile' ...rqam/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk [C]: at 0x0108248a10

I did as said in the previous step, so what could be the possible reason for this error?

So if I need to install cudnn the how to do that, and do we need server GPUs to run as when I google I found that.
I don't have that and want to run the code in my macbook so is it possible anyway that I can do that?

You should refreash your citation.

See http://openaccess.thecvf.com/CVPR2017.py

@InProceedings{Yang_2017_CVPR,
author = {Yang, Chao and Lu, Xin and Lin, Zhe and Shechtman, Eli and Wang, Oliver and Li, Hao},
title = {High-Resolution Image Inpainting Using Multi-Scale Neural Patch Synthesis},
booktitle = {The IEEE Conference on Computer Vision and Pattern Recognition (CVPR)},
month = {July},
year = {2017}
} 

Neuron trained with Human face data fails to execute in this code

Hi,
By referring the below link:
#24
I trained train.lua with human face data in context encoder https://github.com/pathak22/context-encoder

The trained model, when tested, executes in context encoder.
However the same trained model fails to execute in Faster-High-Res-Neural-Inpainting source code.
When i run the command: th run_content_network.lua,
I get the below error log:

Found Environment variable CUDNN_PATH = /home/test/cudnn-8.0-linux-x64-v5.0-ga/cuda/lib64/libcudnn.so.5.0.5{
gpu : 1
model_file : "models/inpaintCenterHumanFaceNoRetrain_500_net_G.t7"
overlapPred : 4
fineSize : 128
}
/home/test/torch/install/bin/luajit: /home/test/torch/install/share/lua/5.1/nn/Container.lua:67:
In 1 module of nn.Sequential:
In 1 module of nn.Sequential:
/home/test/torch/install/share/lua/5.1/nn/THNN.lua:110: bad argument #3 to 'v' (cannot convert 'struct THDoubleTensor *' to 'struct THFloatTensor *')
stack traceback:
[C]: in function 'v'
/home/test/torch/install/share/lua/5.1/nn/THNN.lua:110: in function 'SpatialConvolutionMM_updateOutput'
...ya/torch/install/share/lua/5.1/nn/SpatialConvolution.lua:79: in function <...ya/torch/install/share/lua/5.1/nn/SpatialConvolution.lua:76>
[C]: in function 'xpcall'
/home/test/torch/install/share/lua/5.1/nn/Container.lua:63: in function 'rethrowErrors'
/home/test/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function </home/test/torch/install/share/lua/5.1/nn/Sequential.lua:41>
[C]: in function 'xpcall'
/home/test/torch/install/share/lua/5.1/nn/Container.lua:63: in function 'rethrowErrors'
/home/test/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
run_content_network.lua:41: in main chunk
[C]: in function 'dofile'
...est/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: at 0x00405d50

WARNING: If you see a stack trace below, it doesn't point to the place where this error occurred. Please use only the one above.
stack traceback:
[C]: in function 'error'
/home/test/torch/install/share/lua/5.1/nn/Container.lua:67: in function 'rethrowErrors'
/home/test/torch/install/share/lua/5.1/nn/Sequential.lua:44: in function 'forward'
run_content_network.lua:41: in main chunk
[C]: in function 'dofile'
...est/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: at 0x00405d50

I referred the link torch/nn#981
to resolve this issue.
However its not resolved yet.
I was wondering when the model is executing in context encoder, what could be the reason for this error in Faster-High-Res-Neural-Inpainting
Could you help me regarding the same?

wrong when running "th run_content_network.lua"

This is the stack info:
/root/torch/install/bin/luajit: /root/torch/install/share/lua/5.1/trepl/init
lua:389: module 'cudnn' not found:No LuaRocks module found for cudnn
no field package.preload['cudnn']
no file '/root/.luarocks/share/lua/5.1/cudnn.lua'
no file '/root/.luarocks/share/lua/5.1/cudnn/init.lua'
no file '/root/torch/install/share/lua/5.1/cudnn.lua'
no file '/root/torch/install/share/lua/5.1/cudnn/init.lua'
no file './cudnn.lua'
no file '/root/torch/install/share/luajit-2.1.0-beta1/cudnn.lua'
no file '/usr/local/share/lua/5.1/cudnn.lua'
no file '/usr/local/share/lua/5.1/cudnn/init.lua'
no file '/root/.luarocks/lib/lua/5.1/cudnn.so'
no file '/root/torch/install/lib/lua/5.1/cudnn.so'
no file '/root/torch/install/lib/cudnn.so'
no file './cudnn.so'
no file '/usr/local/lib/lua/5.1/cudnn.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'error'
/root/torch/install/share/lua/5.1/trepl/init.lua:389: in function 'r
quire'
run_content_network.lua:6: in main chunk
[C]: in function 'dofile'
/root/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in ma
n chunk
[C]: at 0x00406670

Hole size is 180x180?

Your paper mentioned that the holes for a 512x512 image are 256x256. However, the demo in this repository has hole sizes of 180x180. Is there a version where the holes are 256x256?

nvcc fatal : Unsupported gpu architecture 'compute_75'

I have encountered the following problem when i tried to execute luarocks install cudnn

CMake Error at /usr/local/Cellar/cmake/3.13.2/share/cmake/Modules/FindCUDA.cmake:696 (message):
Specify CUDA_TOOLKIT_ROOT_DIR
Call Stack (most recent call first):
CMakeLists.txt:7 (FIND_PACKAGE)

The problem was solved by installing cuda from https://developer.nvidia.com
But when i run this command for second time, a new problem has arisen.

nvcc fatal : Unsupported gpu architecture 'compute_75'
nvcc fatal : Unsupported gpu architecture 'compute_75'
CMake Error at THC_generated_THCReduceApplyUtils.cu.o.Release.cmake:219 (message):
Error generating
/tmp/luarocks_cutorch-scm-1-2575/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCReduceApplyUtils.cu.o

CMake Error at THC_generated_THCBlas.cu.o.Release.cmake:219 (message):
Error generating
/tmp/luarocks_cutorch-scm-1-2575/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCBlas.cu.o

nvcc fatal : Unsupported gpu architecture 'compute_75'
CMake Error at THC_generated_THCSleep.cu.o.Release.cmake:219 (message):
Error generating
/tmp/luarocks_cutorch-scm-1-2575/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCSleep.cu.o

make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCReduceApplyUtils.cu.o] Error 1
make[2]: *** Waiting for unfinished jobs....
nvcc fatal : Unsupported gpu architecture 'compute_75'
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCBlas.cu.o] Error 1
CMake Error at THC_generated_THCTensorCopy.cu.o.Release.cmake:219 (message):
Error generating
/tmp/luarocks_cutorch-scm-1-2575/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCTensorCopy.cu.o

make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCSleep.cu.o] Error 1
nvcc fatal : Unsupported gpu architecture 'compute_75'
CMake Error at THC_generated_THCStorageCopy.cu.o.Release.cmake:219 (message):
Error generating
/tmp/luarocks_cutorch-scm-1-2575/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCStorageCopy.cu.o

make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensorCopy.cu.o] Error 1
nvcc fatal : Unsupported gpu architecture 'compute_75'
nvcc fatal : Unsupported gpu architecture 'compute_75'
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCStorageCopy.cu.o] Error 1
CMake Error at THC_generated_THCStorage.cu.o.Release.cmake:219 (message):
Error generating
/tmp/luarocks_cutorch-scm-1-2575/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCStorage.cu.o

CMake Error at THC_generated_THCHalf.cu.o.Release.cmake:219 (message):
Error generating
/tmp/luarocks_cutorch-scm-1-2575/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCHalf.cu.o

nvcc fatal : Unsupported gpu architecture 'compute_75'
CMake Error at THC_generated_THCTensor.cu.o.Release.cmake:219 (message):
Error generating
/tmp/luarocks_cutorch-scm-1-2575/cutorch/build/lib/THC/CMakeFiles/THC.dir//./THC_generated_THCTensor.cu.o

make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCHalf.cu.o] Error 1
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCStorage.cu.o] Error 1
make[2]: *** [lib/THC/CMakeFiles/THC.dir/THC_generated_THCTensor.cu.o] Error 1
make[1]: *** [lib/THC/CMakeFiles/THC.dir/all] Error 2
make: *** [all] Error 2

Error: Failed installing dependency: https://raw.githubusercontent.com/torch/rocks/master/cutorch-scm-1.rockspec - Build error: Failed building.

How can i solve this problem?

How to create the the tensor mask?

Hii, thanks alot for sharing yr work, it s really intresting
I m trying to inpaint other locations in image rather than the centre, but i m stuck in the step of blend as i want to create a tensor mask corresponding to the region i inpianted so can u plz tell me how to create the tensor mask
I appriate yr help, 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.