Unofficial PyTorch implementation of the Adaptive Convolution architecture for image style transfer

Overview

AdaConv

Unofficial PyTorch implementation of the Adaptive Convolution architecture for image style transfer from "Adaptive Convolutions for Structure-Aware Style Transfer". Disclaimer: I have not trained the model the full number of iterations yet, this is still a work in progress.

Direct link to the adaconv module.

Direct link to the kernel predictor module.

Data

Trained with MS COCO train2017 dataset for content images and WikiArt train dataset for style images. By default the content images should be placed in ./data/MSCOCO/train2017 and the style images in ./data/WikiArt/train. You can change these directories by passing arguments when running the script: python .\train.py --content= --style= or by changing the default value in /lib/lightning/datamodule.py

Architecture (from the original paper):

https://raw.githubusercontent.com/RElbers/ada-conv-pytorch/master/imgs/arch_01.png

https://raw.githubusercontent.com/RElbers/ada-conv-pytorch/master/imgs/arch_02.png

Preliminary results after training 45k iterations:

https://raw.githubusercontent.com/RElbers/ada-conv-pytorch/master/imgs/preliminary_results.jpg

Comments
  • On the implementation of pointwise convolution

    On the implementation of pointwise convolution

    Thanks for the authors' hard work of this code repository.

    I have noticed that in current implementation, the pointwise convolution is also generated and viewed as group convolution (https://github.com/RElbers/ada-conv-pytorch/blob/5d0578ee8a8baf7ce06e129a933be2f2812145b3/lib/adaconv/kernel_predictor.py#L23). For example, with input channel C_in and output channel C_out, the generated pointwise convolution is with size C_out x C_in/N_g x 1 x 1. However, according my understandig I wonder if the pointwise convolution should have the same size as a normal convolution kernel with size C_out x C_in x 1 x1 ?

    Looking forward to your respose. Thanks a lot.

    opened by FanghaiZhao 3
  • Bias before pointwise conv

    Bias before pointwise conv

    https://github.com/RElbers/ada-conv-pytorch/blob/bb3bab5820b2fb668e9a590269d0cb827437fdfd/lib/nn/adaconv/adaconv.py#L44

    In the paper the bias is added after the pointwise cov. Is there a reason why we do it before here?

    opened by ariG23498 2
  • Improved speed with batch adaconv?

    Improved speed with batch adaconv?

    Thanks for publishing this code! I've been tinkering around with AdaConv for months, and it's super helpful seeing somebody else's interpretation!

    Something I've implemented in my code you might consider is applying the kernel convolutions in one go, by stacking all the channels together. Example:

        def forward(self, style_encoding: torch.Tensor, predicted: torch.Tensor, thumb_stats=None):
            N, c, h, w = predicted.size()
            depthwise = self.depthwise_kernel_conv(style_encoding)
            depthwise = depthwise.view(N*self.c_out, self.c_in // self.n_groups, 5, 5)
            s_d = self.pointwise_avg_pool(style_encoding)
            pointwise_kn = self.pw_cn_kn(s_d).view(N*self.c_out, self.c_out // self.n_groups, 1, 1)
            pointwise_bias = self.pw_cn_bias(s_d).view(N*self.c_out)
    
            if self.norm:
                predicted = F.instance_norm(predicted)
    
            predicted = predicted.view(1,N*C,h,w)
            content_out = nn.functional.conv2d(
                    nn.functional.conv2d(self.pad(predicted),
                                         weight=depthwise,
                                         stride=1,
                                         groups=self.batch_groups
                                         ),
                    stride=1,
                    weight=pointwise_kn,
                    bias=pointwise_bias,
                    groups=self.batch_groups)
            content_out = content_out.permute([1, 0, 2, 3]).view(N,C,h,w)
            return content_out
    

    I believe this achieves the same results without iteration.

    opened by JackMcCoy 1
  • ValueError: test_size=8 should be either positive and smaller than the number of samples 0 or a float in the (0, 1) range

    ValueError: test_size=8 should be either positive and smaller than the number of samples 0 or a float in the (0, 1) range

    Hello, I am glad to see your article, I was very inspired, but when I run the code you provided, it appeared ValueError: test_size=8 should be either positive and smaller than the number of samples 0 or a float in the (0, 1) range

    Can you help me solve this problem?

    opened by yanmingqiang 1
  • AdaConv with StyleGAN

    AdaConv with StyleGAN

    Thanks for the authors' of this repo hard work.

    I have a question about implementation of styleGAN2 with adaConv. Hope, somebody can help me understand how it is supposed to be implemented. StyleGAN2 takes style as a 1d vector, but adaconv requires the style to be an image (2d vector). Does the reshape of 1d style to an image is done at the beginning with replacement of Linear layers with Conv2d or layers aren't changed except for demodulation part, before which reshape is done every time?

    opened by dariabaranovskaya 0
Owner
null
Simple Tensorflow implementation of "Adaptive Convolutions for Structure-Aware Style Transfer" (CVPR 2021)

AdaConv — Simple TensorFlow Implementation [Paper] : Adaptive Convolutions for Structure-Aware Style Transfer (CVPR 2021) Note This repository does no

Junho Kim 26 Nov 18, 2022
An implementation of Video Frame Interpolation via Adaptive Separable Convolution using PyTorch

This work has now been superseded by: https://github.com/sniklaus/revisiting-sepconv sepconv-slomo This is a reference implementation of Video Frame I

Simon Niklaus 984 Dec 16, 2022
PyTorch implementation of the R2Plus1D convolution based ResNet architecture described in the paper "A Closer Look at Spatiotemporal Convolutions for Action Recognition"

R2Plus1D-PyTorch PyTorch implementation of the R2Plus1D convolution based ResNet architecture described in the paper "A Closer Look at Spatiotemporal

Irhum Shafkat 342 Dec 16, 2022
Official PyTorch implementation of "ArtFlow: Unbiased Image Style Transfer via Reversible Neural Flows"

ArtFlow Official PyTorch implementation of the paper: ArtFlow: Unbiased Image Style Transfer via Reversible Neural Flows Jie An*, Siyu Huang*, Yibing

null 123 Dec 27, 2022
Fast Neural Style for Image Style Transform by Pytorch

FastNeuralStyle by Pytorch Fast Neural Style for Image Style Transform by Pytorch This is famous Fast Neural Style of Paper Perceptual Losses for Real

Bengxy 81 Sep 3, 2022
(CVPR 2021) PAConv: Position Adaptive Convolution with Dynamic Kernel Assembling on Point Clouds

PAConv: Position Adaptive Convolution with Dynamic Kernel Assembling on Point Clouds by Mutian Xu*, Runyu Ding*, Hengshuang Zhao, and Xiaojuan Qi. Int

CVMI Lab 228 Dec 25, 2022
Adaptive Graph Convolution for Point Cloud Analysis

Adaptive Graph Convolution for Point Cloud Analysis This repository contains the implementation of AdaptConv for point cloud analysis. Adaptive Graph

null 64 Dec 21, 2022
PyTorch implementation of neural style transfer algorithm

neural-style-pt This is a PyTorch implementation of the paper A Neural Algorithm of Artistic Style by Leon A. Gatys, Alexander S. Ecker, and Matthias

null 770 Jan 2, 2023
Pytorch implementation of Nueral Style transfer

Nueral Style Transfer Pytorch implementation of Nueral style transfer algorithm , it is used to apply artistic styles to content images . Content is t

Abhinav 9 Oct 15, 2022
Official PyTorch implementation of Retrieve in Style: Unsupervised Facial Feature Transfer and Retrieval.

Retrieve in Style: Unsupervised Facial Feature Transfer and Retrieval PyTorch This is the PyTorch implementation of Retrieve in Style: Unsupervised Fa

null 60 Oct 12, 2022
PyTorch implementation of MuseMorphose, a Transformer-based model for music style transfer.

MuseMorphose This repository contains the official implementation of the following paper: Shih-Lun Wu, Yi-Hsuan Yang MuseMorphose: Full-Song and Fine-

Yating Music, Taiwan AI Labs 142 Jan 8, 2023
PyTorch implementation of paper: AdaAttN: Revisit Attention Mechanism in Arbitrary Neural Style Transfer, ICCV 2021.

AdaAttN: Revisit Attention Mechanism in Arbitrary Neural Style Transfer [Paper] [PyTorch Implementation] [Paddle Implementation] Overview This reposit

null 148 Dec 30, 2022
Implementation of Neural Style Transfer in Pytorch

PytorchNeuralStyleTransfer Code to run Neural Style Transfer from our paper Image Style Transfer Using Convolutional Neural Networks. Also includes co

Leon Gatys 396 Dec 1, 2022
Pytorch implementation of the paper "Enhancing Content Preservation in Text Style Transfer Using Reverse Attention and Conditional Layer Normalization"

Pytorch implementation of the paper "Enhancing Content Preservation in Text Style Transfer Using Reverse Attention and Conditional Layer Normalization"

Dongkyu Lee 4 Sep 18, 2022
Two-Stage Peer-Regularized Feature Recombination for Arbitrary Image Style Transfer

Two-Stage Peer-Regularized Feature Recombination for Arbitrary Image Style Transfer Paper on arXiv Public PyTorch implementation of two-stage peer-reg

NNAISENSE 38 Oct 14, 2022
This script runs neural style transfer against the provided content image.

Neural Style Transfer Content Style Output Description: This script runs neural style transfer against the provided content image. The content image m

Martynas Subonis 0 Nov 25, 2021
U-2-Net: U Square Net - Modified for paired image training of style transfer

U2-Net: U Square Net Modified for paired image training of style transfer This is an unofficial repo making use of the code which was made available b

Doron Adler 43 Oct 3, 2022
Unofficial implementation of MLP-Mixer: An all-MLP Architecture for Vision

MLP-Mixer: An all-MLP Architecture for Vision This repo contains PyTorch implementation of MLP-Mixer: An all-MLP Architecture for Vision. Usage : impo

Rishikesh (ऋषिकेश) 175 Dec 23, 2022
Unofficial implementation of Perceiver IO: A General Architecture for Structured Inputs & Outputs

Perceiver IO Unofficial implementation of Perceiver IO: A General Architecture for Structured Inputs & Outputs Usage import torch from src.perceiver.

Timur Ganiev 111 Nov 15, 2022