Image morphing without reference points by applying warp maps and optimizing over them.

Overview

Differentiable Morphing

Image morphing without reference points by applying warp maps and optimizing over them.

Differentiable Morphing is machine learning algorithm that can morph any two images without reference points. It called "differentiable morphing" because neural network here is not used in traditional data to label mapping sense, but as an easy way to solve optimization problem where one image is mapped to another via warp maps that are found by gradient descent. So after maps are found there is no need for the network itself.

Results

example 1 example 2 example 3

Dependencies

Tensorflow 2.1.3 and above.

Usage

Install proper dependencies:

pip install -r requirements.txt

Use the program:

morph.py -s images/img_1.jpg -t images/img_2.jpg

-s Source file
-t Target file

Unnecessary parameters:
-e Number of epochs to train maps on training stage
-a Addition map multiplier
-m Multiplication map multiplier
-w Warp map multiplier
-add_first If true add map would be applied to the source image before mult map. (might work better in some cases)

Idea

Suppose we want to produce one image from another in a way that we use as much useful information as possible, so if two given images share any similarities between them we make use of these similarities.

toy_example

After several trials I found out that the best way to achieve such effect is to use following formula.

formula

Here "Mult map" removes unnecessary parts of an image and shifts color balance, "Add map" creates new colors that are not present in original image and "Warp map" distort an image in some way to reproduce shifting, rotation and scaling of objects. W operation is dense_image_warp method that present in tensorflow and usually used for optical flow estimation tasks.

All maps are found by gradient descent using very simple convolution network. Now, by applying alpha scaling parameter to every map we will get smooth transition from one image to another without any loss of useful data (at least for the given toy example).

transition

Thoughts

Notice that all maps produced generate somewhat meaningful interpolation without any understanding of what exactly present in the images. That means that warp operation might be very useful in images processing tasks. In some sense warp operation might be thought as long range convolution, because it can "grab" data from any point of an image and reshape it in some useful way. Therefore it might be beneficial to use warp operation in classification tasks and might allow networks be less susceptible to small perturbations of the data. But especially, it should be beneficial to use in generation task. It should be much easier to produce new data by combining and perturbating several examples of known data points than to learn a function that represents all data points at ones.

Comments
  • ERROR: Could not find a version that satisfies the requirement numpy==1.23.1

    ERROR: Could not find a version that satisfies the requirement numpy==1.23.1

    Running the colab project fails at a number of points, starting with this error:

    ERROR: Could not find a version that satisfies the requirement numpy==1.23.1

    Unfortunately don't have enough time to troubleshoot this one myself - Anyone else experience this or know a fix, or know what I'm doing wrong? - I am very new to colaboratory

    opened by wyliefoxxx 2
  • Colab notebook

    Colab notebook

    I made a quick colab notebook that implements this code. If you want to merge this, the link in the readme will need to change to refer to the copy in your repo.

    opened by chigozienri 2
  • Added resizing feature to preserve original image aspect ratio

    Added resizing feature to preserve original image aspect ratio

    Purpose of Pull Request

    This pull request includes the resizing function calls that preserves the original aspect ratio of the input image and outputs the resulting video frames accordingly.

    This feature is best shown by the following visual example:

    before_lena after_lena morph

    opened by cardboardcode 1
  • :hammer: Closes #15.

    :hammer: Closes #15.

    Purpose of Pull Request

    This pull request is to fix Issue #15 automatically when running pip3 install -r requirements.txt.

    Each dependencies' versions has also been verified and specified within the edited requirements.txt.

    opened by cardboardcode 1
  • ModuleNotFoundError: No module named 'tqdm'

    ModuleNotFoundError: No module named 'tqdm'

    Issue Description

    After setting up the virtualenv, the following error was printed to terminal when running python3 morph.py -s images/image_1.png -t images/image_2.png

    Traceback (most recent call last):
      File "./morph.py", line 8, in <module>
        from tqdm import tqdm
    ModuleNotFoundError: No module named 'tqdm'
    

    Environment

    • Ubuntu 20.04 Focal Fossa
    • Nvidia Geforce GTX 1060

    Steps to Reproduce

    Follow the steps below to reproduce the error described above:

    virtualenv -p python3 venv
    source venv/bin/activate
    pip3 install -r requirements.txt
    python3 morph.py -s images/image_1.png -t images/image_2.png
    

    Others

    This issue has been resolved. See below for the solution. Posting this issue to simply publish the solution.

    opened by cardboardcode 1
  • Fix for issue #10

    Fix for issue #10

    The following changes have been done:

    1. Fixed issue #10
    2. Removed print statements and added tqdm for progress bars
    3. Added arguments for changing FPS and STEPS
    opened by tanseersaji 1
  • video output black

    video output black

    Latest try:

    python morph.py -s images/img_1.jpg -t images/img_2.jpg

    2021-01-12 17:23:25.848313: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN)to use the following CPU instructions in performance-critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA

    To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.

    2021-01-12 17:23:25.869795: I tensorflow/core/platform/profile_utils/cpu_utils.cc:104] CPU Frequency: 3600000000 Hz

    2021-01-12 17:23:25.870428: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x557665775f10 initialized for platform Host (this does not guarantee that XLA will be used). Devices:

    2021-01-12 17:23:25.870473: I tensorflow/compiler/xla/service/service.cc:176] StreamExecutor device (0): Host, Default Version

    Epoch 100, Loss: 0.07585608214139938

    Epoch 200, Loss: 0.056177154183387756

    Epoch 300, Loss: 0.047623421996831894

    Epoch 400, Loss: 0.04261484742164612

    Epoch 500, Loss: 0.03922488912940025

    Epoch 600, Loss: 0.036724839359521866

    Epoch 700, Loss: 0.03478630632162094

    Epoch 800, Loss: 0.03322023153305054

    Epoch 900, Loss: 0.031917549669742584

    Epoch 1000, Loss: 0.030810609459877014

    Image #10 produced.

    Image #20 produced.

    Image #30 produced.

    Image #40 produced.

    Image #50 produced.

    Image #60 produced.

    Image #70 produced.

    Image #80 produced.

    Image #90 produced.

    Image #100 produced.

    Result video saved.

    So far it looks promising but in the morph folder the video is just 630 kb and black when trying to play. 2 pictures maps.jpg +result.jpg look better see https://i.imgur.com/BbhNnsZ.jpg and https://i.imgur.com/6pYS0gw.jpg . Seems like i am coming closer but have no idea why the video is not created

    opened by Colliwomple 1
  • Full dependencies list

    Full dependencies list

    Hello. Just made your code work on my computer. Tensorflow isn't the only dependency requiered, you may want to update your readme. You also need tensorflow-add_ons and cv2.

    They can all be install through this command

    pip3 install tensorflow tensorflow_addons opencv-python
    

    This would make your code more accesible. Cheers!

    opened by karen-pal 1
  • Optimal parameters

    Optimal parameters

    Which parameters were used to generate car morph from example? How many epochs is needed to generate that result?

    I'm newbie in neural networks so sorry for possible stupid question

    opened by cranx 1
  • Memory usage scales linearly

    Memory usage scales linearly

    While running use_wrap_maps method, the script uses memory proportional to the number of steps. Making it difficult to generate higher resolution images and higher number of frames.

    opened by tanseersaji 0
  • Need to mention CUDA 11.3 lib as a requirement if running on RTX for missing cudart64_110.dll error

    Need to mention CUDA 11.3 lib as a requirement if running on RTX for missing cudart64_110.dll error

    Hello. I needed to install the CUDA 11.3 library to fix the following error message for my RTX 3080ti "Could not load dynamic library 'cudart64_110.dll'"

    It's on the tensorflow page that you need NVidia libraries https://www.tensorflow.org/install/pip#windows-native but this may not be obvious to those that are installing it for the first time just via pip.

    Thanks.

    opened by hstercode 0
  • Docker image provided

    Docker image provided

    Hi developers,

    Thanks for your codes. I ran into a problem for few days. Due to the limitations of my research zone, all dependencies can only download from anaconda and then ship to my conda environment. There exists numerous problems during env construction.

    Would you mind providing the docker image so that we can build the env properly. I will appreciate your help with this situation.

    opened by hbyacademic 3
  • morph.py give just errors

    morph.py give just errors

    Hi Executing just morph.py -s images/xxx.jpg -t images/xxx.jpg [-e 1000 -a 0.8 -m 0.8 -w 0.3] gives me just "command not found. "Executing : ./morph.py -s images/trump.jpg -t images/pence.jpg [-e 1000 -a 0.8 -m 0.8 -w 0.3] gives me this: ./morph.py: line 1: import: command not found ./morph.py: line 2: import: command not found ./morph.py: line 3: import: command not found ./morph.py: line 4: import: command not found ./morph.py: line 5: import: command not found ./morph.py: line 8: TRAIN_EPOCHS: command not found ./morph.py: line 10: im_sz: command not found ./morph.py: line 11: mp_sz: command not found ./morph.py: line 13: warp_scale: command not found ./morph.py: line 14: mult_scale: command not found ./morph.py: line 15: add_scale: command not found ./morph.py: line 16: add_first: command not found ./morph.py: line 19: @tf.function: command not found ./morph.py: line 20: syntax error near unexpected token (' ./morph.py: line 20:def warp(origins, targets, preds_org, preds_trg):' So it doesent work for me in Ubuntu 20.04 with tensorflow 2.4.0

    One step further i tried : DiffMorph$ python3 morph.py -s images/xxx.jpg -t images/xxx.jpg [-e 1000 -a 0.8 -m 0.8 -w 0.3] 2021-01-09 16:47:46.888345: W tensorflow/stream_executor/platform/default/dso_loader.cc:60] Could not load dynamic library 'libcudart.so.11.0'; dlerror: libcudart.so.11.0: cannot open shared object file: No such file or directory 2021-01-09 16:47:46.888361: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine. Traceback (most recent call last): File "morph.py", line 4, in import cv2 ModuleNotFoundError: No module named 'cv2'

    Have no idea whats wrong here !

    opened by Colliwomple 5
Owner
Alex K
Russian self-taught programmer. Interested in art, procedural generation and generative AI.
Alex K
Code for Iso-Points: Optimizing Neural Implicit Surfaces with Hybrid Representations

Implementation for Iso-Points (CVPR 2021) Official code for paper Iso-Points: Optimizing Neural Implicit Surfaces with Hybrid Representations paper |

Yifan Wang 66 Nov 8, 2022
PyTorch implementation of CVPR 2020 paper (Reference-Based Sketch Image Colorization using Augmented-Self Reference and Dense Semantic Correspondence) and pre-trained model on ImageNet dataset

Reference-Based-Sketch-Image-Colorization-ImageNet This is a PyTorch implementation of CVPR 2020 paper (Reference-Based Sketch Image Colorization usin

Yuzhi ZHAO 11 Jul 28, 2022
This repository contains numerical implementation for the paper Intertemporal Pricing under Reference Effects: Integrating Reference Effects and Consumer Heterogeneity.

This repository contains numerical implementation for the paper Intertemporal Pricing under Reference Effects: Integrating Reference Effects and Consumer Heterogeneity.

Hansheng Jiang 6 Nov 18, 2022
Code for ACL'2021 paper WARP 🌀 Word-level Adversarial ReProgramming

Code for ACL'2021 paper WARP ?? Word-level Adversarial ReProgramming. Outperforming `GPT-3` on SuperGLUE Few-Shot text classification.

YerevaNN 75 Nov 6, 2022
SparseML is a libraries for applying sparsification recipes to neural networks with a few lines of code, enabling faster and smaller models

SparseML is a toolkit that includes APIs, CLIs, scripts and libraries that apply state-of-the-art sparsification algorithms such as pruning and quantization to any neural network. General, recipe-driven approaches built around these algorithms enable the simplification of creating faster and smaller models for the ML performance community at large.

Neural Magic 1.5k Dec 30, 2022
Face2webtoon - Despite its importance, there are few previous works applying I2I translation to webtoon.

Despite its importance, there are few previous works applying I2I translation to webtoon. I collected dataset from naver webtoon 연애혁명 and tried to transfer human faces to webtoon domain.

이상윤 64 Oct 19, 2022
Fuzzification helps developers protect the released, binary-only software from attackers who are capable of applying state-of-the-art fuzzing techniques

About Fuzzification Fuzzification helps developers protect the released, binary-only software from attackers who are capable of applying state-of-the-

gts3.org (SSLab@Gatech) 55 Oct 25, 2022
Optimizing DR with hard negatives and achieving SOTA first-stage retrieval performance on TREC DL Track (SIGIR 2021 Full Paper).

Optimizing Dense Retrieval Model Training with Hard Negatives Jingtao Zhan, Jiaxin Mao, Yiqun Liu, Jiafeng Guo, Min Zhang, Shaoping Ma This repo provi

Jingtao Zhan 99 Dec 27, 2022
⚡️Optimizing einsum functions in NumPy, Tensorflow, Dask, and more with contraction order optimization.

Optimized Einsum Optimized Einsum: A tensor contraction order optimizer Optimized einsum can significantly reduce the overall execution time of einsum

Daniel Smith 653 Dec 30, 2022
PHOTONAI is a high level python API for designing and optimizing machine learning pipelines.

PHOTONAI is a high level python API for designing and optimizing machine learning pipelines. We've created a system in which you can easily select and

Medical Machine Learning Lab - University of Münster 57 Nov 12, 2022
Adversarial Color Enhancement: Generating Unrestricted Adversarial Images by Optimizing a Color Filter

ACE Please find the preliminary version published at BMVC 2020 in the folder BMVC_version, and its extended journal version in Journal_version. Datase

null 28 Dec 25, 2022
Minimal PyTorch implementation of Generative Latent Optimization from the paper "Optimizing the Latent Space of Generative Networks"

Minimal PyTorch implementation of Generative Latent Optimization This is a reimplementation of the paper Piotr Bojanowski, Armand Joulin, David Lopez-

Thomas Neumann 117 Nov 27, 2022
Feed forward VQGAN-CLIP model, where the goal is to eliminate the need for optimizing the latent space of VQGAN for each input prompt

Feed forward VQGAN-CLIP model, where the goal is to eliminate the need for optimizing the latent space of VQGAN for each input prompt. This is done by

Mehdi Cherti 135 Dec 30, 2022
The implementation of "Optimizing Shoulder to Shoulder: A Coordinated Sub-Band Fusion Model for Real-Time Full-Band Speech Enhancement"

SF-Net for fullband SE This is the repo of the manuscript "Optimizing Shoulder to Shoulder: A Coordinated Sub-Band Fusion Model for Real-Time Full-Ban

Guochen Yu 36 Dec 2, 2022
This project uses Template Matching technique for object detecting by detection of template image over base image.

Object Detection Project Using OpenCV This project uses Template Matching technique for object detecting by detection the template image over base ima

Pratham Bhatnagar 7 May 29, 2022
This project uses Template Matching technique for object detecting by detection of template image over base image

Object Detection Project Using OpenCV This project uses Template Matching technique for object detecting by detection the template image over base ima

Pratham Bhatnagar 4 Nov 16, 2021
Range Image-based LiDAR Localization for Autonomous Vehicles Using Mesh Maps

Range Image-based 3D LiDAR Localization This repo contains the code for our ICRA2021 paper: Range Image-based LiDAR Localization for Autonomous Vehicl

Photogrammetry & Robotics Bonn 208 Dec 15, 2022