Giter VIP home page Giter VIP logo

deep-exemplar-based-colorization's Introduction

Deep Exemplar-based Colorization

This is the implementation of paper Deep Exemplar-based Colorization by Mingming He*, Dongdong Chen*, Jing Liao, Pedro V. Sander and Lu Yuan in ACM Transactions on Graphics (SIGGRAPH 2018) (*indicates equal contribution).

Introduction

Deep Exemplar-based Colorization is the first deep learning approach for exemplar-based local colorization. Given a reference color image, our convolutional neural network directly maps a grayscale image to an output colorized image.

image

The proposed network consists of two sub-networks, Similarity Sub-net which computes the semantic similarities between the reference and the target, and Colorization Sub-net which selects, propagates and predicts the chrominances channels of the target.

The input includes a grayscale target image, a color reference image and bidirectional mapping functions. We use Deep Image Analogy as default to generate bidirectional mapping functions. It is applicable to replace with other dense correspondence estimation algorithms.

The code of the part Color Reference Recommendation is now released. Please refere to Gray-Image-Retrieval for more details.

For more results, please refer to our Supplementary.

(Update) If you would to compile on Linux, please try this repository: https://github.com/ncianeo/Deep-Exemplar-based-Colorization/tree/linux-docker-cv-caffe-build, thank ncianeo for solving this issue.

License

© Microsoft, 2017. Licensed under a MIT license.

Getting Started

Prerequisites

  • Similarity Sub-net:

    • Windows (64bit)
    • NVIDIA GPU (CUDA 8.0 & CuDNN 5)
    • Visual Studio 2013
  • Colorization Sub-net:

    • Pytorch & the 3rd party Python libraries (OpenCV, scikit-learn and scikit-image)

Build

Similarity Sub-net is implemented in C++ combined with CUDA and requires compiling in Visual Studio as follows:

  • Build Caffe at first. Just follow the tutorial here.
  • Edit similarity_combo.vcxproj under similarity_subnet\windows\similarity_combo\ to make the CUDA version in it match yours.
  • Open solution Caffe and add similarity_combo.vcxproj.
  • Build project similarity_combo.
  • (Optional) If you use Deep Image Analogy, please add deep_image_analogy.vcxproj under similarity_subnet\windows\deep_image_analogy\ and build it.

Download Models

You need to download models before running a demo.

Demo

We prepare an example under the folder demo\ with:

(1) Input data folder example\ including two parts:

  • A folder input\ with the input images (grayscale target images and color reference images) inside.
  • A file pairs.txt to specify a target, a reference and a flag (1 as default) as an example in each line, e.g.,
    in1.jpg ref1.jpg 1
    in2.jpg ref2.jpg 1
    ...
    

(2) Executable script run.bat including three commands:

  • (Optional) A command to generate bidirectional mapping functions using Deep Image Analogy:

    deep_image_analogy.exe [MODEL_DIR] [INPUT_ROOT_DIR] [START_LINE_ID] [END_LINE_ID] [GPU_ID]
    e.g., exe\deep_image_analogy.exe models\deep_image_analogy\ example\ 0 2 0
    

    (Note if you use other algorithms for bidirectional mapping functions, please generate flow files referring to the format of those by Deep Image Analogy and put them to the folder example\flow\.)

  • A command to generate similarity maps for colorization (Similarity Subnet):

    similarity_combo.exe [MODEL_DIR] [INPUT_ROOT_DIR] [START_LINE_ID] [END_LINE_ID] [GPU_ID]
    e.g., exe\similarity_combo.exe models\similarity_subnet\ example\ 0 2 0
    
  • A command to do colorization with our pretrained model (Colorization Subnet):

    python test.py --short_size [SHORT_EDGE_SIZE] --test_model [MODEL_FILE] --data_root [INPUT_ROOT_DIR] --out_dir [OUTPUT_DIR] --gpu_id [GPU_ID]
    e.g., python ..\colorization_subnet\test.py --short_size 256 --test_model models\colorization_subnet\example_net.pth --data_root example\ --out_dir example\res\ --gpu_id 0
    

Run

We provide pre-built executable files in folder demo\exe\, please try them.

Tips

Our test input images are resized to w x h (min(w, h)=256) considering the cost of computing bidirectional mapping functions by Deep Image Analogy. But we also support higher resolution input images.

Citation

If you find Deep Exemplar-based Colorization helpful for your research, please consider citing:

@article{he2018deep,
  title={Deep exemplar-based colorization},
  author={He, Mingming and Chen, Dongdong and Liao, Jing and Sander, Pedro V and Yuan, Lu},
  journal={ACM Transactions on Graphics (TOG)},
  volume={37},
  number={4},
  pages={47},
  year={2018},
  publisher={ACM}
}

deep-exemplar-based-colorization's People

Contributors

hmmlillian 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

deep-exemplar-based-colorization's Issues

Inquiry on input format

Hi, from the demo, it seems that the input needs to be images with fixed height and weight.

Since I want to explore if this model can be used as a downstream model for some preprocessed inputs, I wonder if it is possible to pass in only some selected samples from source image/reference, and the selected samples are with variable length. [ dimension of the samples are (length, 3) ]

(-215:Assertion failed) !_src.empty() in function 'cvtColor'

Hi, I tried to run the demo, but I encountered an error:

Traceback (most recent call last):
  File "../colorization_subnet/test.py", line 60, in <module>
    for iter, data in enumerate(data_loader):
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 521, in __next__
    data = self._next_data()
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 1203, in _next_data
    return self._process_data(data)
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/dataloader.py", line 1229, in _process_data
    data.reraise()
  File "/usr/local/lib/python3.6/dist-packages/torch/_utils.py", line 434, in reraise
    raise exception
cv2.error: Caught error in DataLoader worker process 0.
Original Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/worker.py", line 287, in _worker_loop
    data = fetcher.fetch(index)
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 49, in fetch
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/usr/local/lib/python3.6/dist-packages/torch/utils/data/_utils/fetch.py", line 49, in <listcomp>
    data = [self.dataset[idx] for idx in possibly_batched_index]
  File "/src/app/colorization_subnet/lib/TestDataset.py", line 117, in __getitem__
    errs, warp_ba, warp_aba = combo5_loader(combo_path, w, h)
  File "/src/app/colorization_subnet/lib/TestDataset.py", line 52, in combo5_loader
    img_data_ndarray = cv2.cvtColor(img_data_ndarray, cv2.COLOR_BGR2RGB)
cv2.error: OpenCV(3.4.8) /io/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

I print out the intermediate variables, and found out that

file_bytes: [89 80 69 ... 62 10 10]
file_bytes.shape: (127386,)
img_data_ndarray: None # img_data_ndarray = cv2.imdecode(file_bytes, cv2.IMREAD_COLOR)

I did some research but did not find a workable solution.

Could you please suggest on this? Thank you so much!!

what is combo file? How to get it

I run the pytorch part and get this error:

FileNotFoundError: [Errno 2] No such file or directory: 'data/combo_new/1_1r.combo'

I would appreciate if you could help me on this matter,thx

Python 3.5

Is it possible to compile for Python 3.5? I'm getting errors that relate to python27.lib but I have Caffe compiled for Python 3.5.

Reduce model size

  • At present, the VGG network and the color network model are large. I want to control the total model size saved within 10M. Is there a good solution?
  • #41 Can you help me answer this question?

migrate to pytorch or keras

caffe is outdated dinosaur, nobody use it.

Also your windows build does not work.

I suggest you to migrate this and future projects to pytorch or keras , which are user friendly.

Need to change caffe source code for correct running

For some reasons, I cannot use docker. Recently, I use this https://github.com/ncianeo/Deep-Exemplar-based-Colorization/tree/linux-docker-cv-caffe-build repo and have successfully run it under linux 18.04 without docker.
However, I have to change the source code of your supplied caffe. Otherwise, there will be segmentation fault, for both deepanalogy and similarity_net. The reason of segfault for deepanalogy is the force_backward param in its prototxt. And the reason for similarity_net is the following code in caffe/src/caffe/net.cpp, funtion AppendParam().

    has_params_lr_.push_back(param_spec->has_lr_mult());
    has_params_decay_.push_back(param_spec->has_decay_mult());
    params_lr_.push_back(param_spec->lr_mult());
    params_weight_decay_.push_back(param_spec->decay_mult());

Do you know the reason? Or could you please show your env?

Infrared image colorization

  • At present, the test gray-scale image colorization effect is very good, but when I use infrared image colorization, it has no effect. How can I improve it?

Deep Image Analogy for Colorization

Hello, i could not understand how did you use Deep Image Analogy for colorization. I examined your colorization_subnet/test.py code and did not find anything for Image Anology. Could you please explain the correlation between colorization and Deep Image Analogy ?

Thanks,
Best Regards.

some details about similarity subnet

I am trying to train the grey-VGG-19 in the paper ,but using pytorch. Could you please tell me some details about training it?
1.which dataset do you use to trian the VGG-19?
2.How did you transfer the dataset from RGB to Lab ?
3.The bidirectional map function just need to be used after the VGG-19 net ,am I right?
4.which Loss function/optimizer did you use in VGG-19 when training VGG-19?
sorry to both you...

Is there the Linux version of the code?

The project is very awesome and it would be more convenient for testing if there would be the Linux version of the code. I know the Colorization Subnet is based on Pytorch, which is easily used on Linux, so I hope I can get the Linux version of the Similarity SubNet if possible. Thank you very much.

Some question about similarity_combo?

Thank u for your job. it helps a lot. I have ran the Deep-Image-Analogy on linux sucessfully. but i met some problems when do as your advises like

@TruePhone The Similarity SubNet (and Deep Image Analogy if you use it to build correspondence) is implemented in C++. It should be easy to transplant to Linux. Deep Image Analogy already has a Linux version (https://github.com/msracver/Deep-Image-Analogy/tree/linux) and our Similarity SubNet is actually built based on it. You may copy the source code from Deep-Exemplar-based-Colorization/similarity_subnet/windows/similarity_combo/ to msracver/Deep-Image-Analogy/tree/linux and slightly modify it on Linux.

but when i compile, it missing some files.h like windows.h . sorry, i am not familiar with c++ in windows. can u give me some advises to get similarity_combo file in linux?

Is it possible to running on CUDA 10.2?

It seems my 2080ti driver not compatible with CUDA 8 anymore (mine is CUDA 10.2). I tried to build Caffe with 10.2 but it kept sending this error:
Severity Code Description Project File Line Suppression State
Error MSB3721 The command ""C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2;\bin\nvcc.exe" -gencode=arch=compute_35,code="sm_35,compute_35" -gencode=arch=compute_52,code="sm_52,compute_52" --use-local-env -ccbin "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.26.28801\bin\HostX86\x64" -x cu -I"C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\NugetPackages\lmdb-v120-clean.0.9.14.0\build\native....\lib\native\include" -I"C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\NugetPackages\LevelDB-vc120.1.2.0.0\build\native../..//build/native/include/" -I"C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\NugetPackages\protobuf-v120.2.6.1\build\native../..//build/native/include/" -I"C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\NugetPackages\glog.0.3.3.0\build\native../..//build/native/include/" -I"C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\NugetPackages\gflags.2.1.2.1\build\native../..///build/native/include/" -I"C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\NugetPackages\boost.1.59.0.0\build\native....\lib\native\include\" -I"C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\NugetPackages\hdf5-v120-complete.1.8.15.2\build\native....\lib\native\include" -I"C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\NugetPackages\OpenBLAS.0.2.14.1\build\native....\lib\native\include" -I"C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\NugetPackages\OpenCV.2.4.10\build\native../../build/native/include/" -I"C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\similarity_subnet\windows\libcaffe\....\src\" -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2" -I\include -I"C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v10.2" -I\include -G -lineinfo --keep-dir C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\similarity_subnet\windows..\Build\Int\libcaffe\x64\Debug -maxrregcount=0 --machine 64 --compile -cudart static -Xcudafe "--diag_suppress=exception_spec_override_incompat --diag_suppress=useless_using_declaration --diag_suppress=field_without_dll_interface" -D_SCL_SECURE_NO_WARNINGS -DGFLAGS_DLL_DECL= -g -DHAS_LMDB -DHAS_HDF5 -DHAS_OPENBLAS -DHAS_OPENCV -D_DEBUG -D_SCL_SECURE_NO_WARNINGS -DUSE_OPENCV -DUSE_LEVELDB -DUSE_LMDB -DUSE_CUDNN -D_UNICODE -DUNICODE -Xcompiler "/EHsc /W1 /nologo /Od /FdC:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\similarity_subnet\windows..\Build\Int\libcaffe\x64\Debug\libcaffe.pdb /FS /Zi /RTC1 /MDd " -o C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\similarity_subnet\windows..\Build\Int\libcaffe\x64\Debug\absval_layer.cu.obj "C:\Tools\AI\VideoProduction\Deep-Exemplar-based-Colorization-master\similarity_subnet\src\caffe\layers\absval_layer.cu"" exited with code 1. libcaffe C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\BuildCustomizations\CUDA 10.2.targets 764

Is there any way to fix this issue?
Thank you!

Check failed: error == cudaSuccess (2 vs. 0) out of memory

When i try to run your model sometimes it successfully runs but then when i try with other image i get this ("Check failed: error == cudaSuccess (2 vs. 0) out of memory") error. Do you have any idea about this? Is it possible that depends on image size?

I have 4 GB GPU
GeForce GTX 950M
Windows10

How to Get Reference Image about ImageNet 10k subset?

您好,
我想请教一下关于test data那里,我们没有像训练数据reference匹配时的类别信息,不能按照类别去寻找reference,需要将每个图片与ImageNet中所有数据去对比 然后找最相近的数据嘛?

Average run time.

Could you please tell me how long does it take to color a photo? 7-8 minute per photo for me.

Color Transfer

Hello, I did not get where is the exact point that color transfer happens in your code. I mean /colorization_subnet/test.py . Could you please explain to me?

Best regards.

Training code

Hello, could you release the training code and the training details? Thank you!

The meaning of theta parameter in the paper

Hi! It's an impressive work.
I am trying to understand the implemented method. In particular, how is the theta parameter used in the Colorization Sub-Network. Formula 3 or Figure 4 in the paper do not give a detailed description.

About Flow and Combo files

I have two questions. I would be glad if you answer.

(1) Could you please explain what exactly are flow and combo files. What do they contain ?
(2) I got
Check failed: status == CUDNN_STATUS_SUCCESS (4 vs. 0) CUDNN_STATUS_INTERNAL_ERROR
What might be the reason of this error ?

python = 3.6.7
pytorch = 1.0.0 (cuda 8, cudnn 5.1)
torchvision = 0.2.1

Thank you so much.

Could you please add the baidu cloud drive link?

I am sorry that I can not download the model from Dropbox, the speed is very slow, even I use the VPN,
So could you please give the download link of the Baidu cloud drive ?
Thank you very much!

Help for the (optional) bidirectional mapping generation

Hello,

I'm newbie on deep learning and working with obsolete hardware that today unsupported by main framework. But because I'm really want to use your project, and have no money today to upgrade my hardware, I have hack the caffe version to allow me to build it with CUDA 6.5 and sm_13 (yes sm_13). For that i've just hack the math_functions.xxx files to use cublas v1 (not the current v2).

My second problem is the memory. Because my hardware is limited in memory, I've to load the two classifiers models on host/cpu not on gpu (out of memory error) and just add some memory copy to allow me to use the current GPU code of the two projects (norm / blend / patchmatch and others ...). There's no problem for now.

The similarity_combo exe build fine, work fine on the example provided, and product correct combo files with the provided bidirectionnal mapping files (flow files in demo directory).

My problem comes with the deep_image_similarity exe. And especially on the deconv (gradient descent) part. Because my change, I use the Cuda-L-BFGS in cpu mode and I've just modifiy the custom cost_function to generate diff on cpu, no gpu. But there's a problem because each iteration provide same values. All seem correct for me, but I suspect that the cost function do not update correctly at :

m_classifier->net_->BackwardFromTo(m_id1, m_id2 + 1); in Deconv.cpp

Let me see you the log in debug mode : http://s000.tinyupload.com/index.php?file_id=87185167689484967287

Any idea maybe ? Thank you very much for your time.

请问您近期是否有打算将similarity_subnet迁移到基于python语言的框架呢?

  1. 我们拜读了本论文,并模仿您的开发环境,成功使用了您提供的网络模型和预编译的exe文件,且获得了良好的效果。

  2. 但由于能力有限,且基于C++的caffe框架对开发环境及开发技术的苛刻要求,我们无法基于您的网络尝试修改和训练。(似乎当前版本的代码并未提供训练函数及相关损失、参数、及训练方法等)

  3. 请问您近期是否有打算发布一版基于python语言框架的《Deep Exemplar-based Colorization*》的实现的可训练版本呢?

如果您能在百忙之中抽空答复,我们将感激不尽

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.