PyTorch-Multi-Style-Transfer Run-on-Ainize(Eng,Kor)
PyTorch-Multi-Style-TransferRun-on-Ainize(Eng,Kor)
Overview

Photo 1 - Picture converted Multi Styles by PyTorch-Multi-Style-Transfer.
The last Substack article was examined by Cycle-GAN and Pix2Pix Image-to-Image translation implemented by GAN(Generative Adversial Nets).
The model to be introduced today will be used to identify MSG-Net(Multi-style Generative Network) in vision and image style transfer fields such as Cycle-GAN and Pix2pix.
Based on the model of this paper, MSG-Net model was implemented in PyTorch-Multi-Style-Transfer.
In the link below, the pre-trained model of the above code provides run-on-ainized-pytorch-multi-style-transfer that allows you to run and check some options without any other preferences.
Model Architecture
Abstract
Despite the rapid progress in style transfer, existing approaches using feed-forward generative network for multi-style or arbitrary-style transfer are usually compromised of image quality and model flexibility. We find it is fundamentally difficult to achieve comprehensive style modeling using 1-dimensional style embedding. Motivated by this, we introduce CoMatch Layer that learns to match the second order feature statistics with the target styles. With the CoMatch Layer, we build a Multi-style Generative Network (MSG-Net), which achieves real-time performance. We also employ an specific strategy of upsampled convolution which avoids checkerboard artifacts caused by fractionally-strided convolution. Our method has achieved superior image quality comparing to state-of-the-art approaches. The proposed MSG-Net as a general approach for real-time style transfer is compatible with most existing techniques including content-style interpolation, color-preserving, spatial control and brush stroke size control. MSG-Net is the first to achieve real-time brush-size control in a purely feed-forward manner for style transfer.
Network Structure

Photo 2 - MSG-Net Structure
CoMatch Layer
As the first contribution of the paper, we introduce anCoMatch Layer which embeds style with a 2D representation and learns to match the second-order Gram Matrix of the style targets inherently during the training. The CoMatch Layer is differentiable and end to-end learnable with existing generative network architectures without additional supervision. The proposed CoMatch Layer enables multi-style generation from a single feed-forward network.
Multi style Generative Network (MSG-Net)
The second contribution of this paper is building Multi style Generative Network (MSG-Net) with the CoMatch Layer and a novel Upsample Convolution. The MSG-Net as a feed-forward network runs in real-time after training. Generative networks typically have a decoder part recovering the image details from downsampled representations. Learning Fractionally-Strided convolution [ref 3] typically brings checkerboard artifacts. For improving the image quality, we employ a strategy we call upsampled convolution, which successfully avoids the checkerboard artifacts by applying an integer stride convolution and outputs an upsampled feature map. In addition, we extend the Bottleneck architecture [ref 4] to an UpsamplingResidual Block, which reduces computational complexity without losing style versatility by preserving larger number of channels. Passing identity all the way through the generative network enables the network to extend deeper and converge faster. The experimental results show that MSG-Net has achieved superior image fidelity and test speed compared to previous work.
Reference
[1] https://arxiv.org/pdf/1703.06953v2.pdf
[2] https://github.com/zhanghang1989/PyTorch-Multi-Style-Transfer
[3] J. Long, E. Shelhamer, and T. Darrell. Fully convolutional networks for semantic segmentation. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 3431–3440, 2015. 2, 4, 5, 6
[4] K. He, X. Zhang, S. Ren, and J. Sun. Deep residual learning for image recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 770–778, 2016. 2, 4
———————————————————————
개요

사진 1 - 사진을 PyTorch-Multi-Style-Transfer로 Style 변환시킨 사진
지난번 Substack 기고문엔 GAN(Generative Adversarial Nets)으로 구현한 Cycle-GAN, Pix2Pix Image-to-Image translation을 알아보았다.
오늘 소개할 모델은 Cycle-GAN, Pix2pix 와 같은 vision, Image Style transfer분야의 MSG-Net(Multi-style Generative Network)을 알아볼 것이다.
그리고 본 논문의 모델을 기반으로PyTorch-Multi-Style-Transfer에선 MSG-Net 모델을 구현하였다. 그리고 각 옵션에 따라 최소 400개에서 최대 3000개의 데이터를 바탕으로 모델을 훈련하고 평가하였다 (pretrained된 file은 git을 참조하면 다운받을 수 있다).
그리고 아래 링크에서 위 코드의 pretrained model로 일부 옵션들을 별 다른 환경설정 없이 바로 실행시키고 확인할 수 있는 run-on-ainized-pytorch-multi-style-transfer가 제공되어 있다.
모델 아키텍처
추상화
Style-Transfer에서 멀티 스타일 또는 임의의 스타일 전송을 위한 Feed-Forward Generative Net을 사용하는 기존 접근방식은 일반적으로 이미지 품질과 모델 유연성이 손상되기 쉽다.
또한 1차원 style embbeding을 이용한 포괄적 스타일 모델링은 근본적으로 어렵다는 것을 발견하였다.
이러한 문제를 CoMatch Layer는 Second Order Feature 통계와 타켓 스타일 매칭법 학습을 통해 해결한다. CoMatch Layer를 이용하여 Real-Time performance를 구현하는 Multi-style Generative Network (MSG-Net)를 구축한다.
또한, 부분적으로 striding된 컨볼루션에 의해 야기되는 checkerboard artifacts를 회피하는 업샘플링된 컨볼루션의 특정 전략을 사용한다.
본 방법은 최신 Style-Transfer만큼 우수한 화질이 구현하였다. 실시간 스타일 전송을 위한 일반적인 접근 방법으로 제안된 MSG-Net은 콘텐츠 스타일 보간, 색상 보존, 공간 제어 및 브러시 스트로크 크기 제어를 포함한 대부분의 기존 기술과 호환됩니다. MSG-Net은 Style-Transfer를 위해 순전히 Feed-Forward 방식으로 실시간 브러시 크기 제어를 달성한 최초의 모델이다.
네트워크 구조

사진 2 - MSG-Net 구조
코매치 층 ( CoMatch Layer )
본 논문의 첫 번째 공헌으로, 2D 표현을 사용하여 스타일을 내장하고 훈련 중에 본질적으로 스타일 목표의 2차 그램 매트릭스와 일치하는 것을 배우는 CoMatch Layer를 소개한다. CoMatch Layer는 차별화 가능하며 별도의 supervison이 없이 기존 생성 네트워크 아키텍처와 함께 끝에서 끝까지 학습할 수 있다. 제안된 CoMatch Layer는 Single feed forward 네트워크에서 Multi style의 생성을 가능하게 한다.
멀티 스타일 생성 네트워크( Multi style Generative Network ,MSG-Net )
본 논문의 두 번째 공헌은 CoMatch Layer와 새로운 Upsample Convolution을 이용하여 Multi Style Generative Network (MSG-Net)를 구축하는 것이다. Feed forward 네트워크로서의 MSG-Net은 훈련 후 실시간으로 실행된다. 생성 네트워크는 일반적으로 down sample 된 표현으로부터 이미지 세부사항을 복구하는 디코더를 갖는다. Fractionally-Strided 컨볼루션 [참조 3]을 배우면 일반적으로 체커 보드 아티팩트가 제공됩니다. 이미지 품질을 향상시키기 위해, 우리는 Up sampling된 컨볼루션이라고 불리는 전략을 사용하는데, 이것은 정수 Stride 컨볼루션을 적용하여 체커보드 아티팩트를 성공적으로 피하고 상향 샘플링된 특징 맵을 출력한다. 또한, Bottleneck 아키텍처 [참조4]를 Up sampling Residual Block으로 확장하여 더 많은 수의 채널을 보존함으로써 스타일 다기능성을 잃지 않고 계산 복잡성을 줄입니다. 생성 네트워크를 통해 정체성을 전달하면 네트워크가 더 깊이 확장되고 더 빨리 수렴할 수 있습니다.
이러한 구조를 갖고 실험을 한 결과 MSG-Net은 기존 연구와 비교하여 우수한 영상 충실도와 테스트 속도를 달성하였다고 한다. 실제로 Run-On-Ainize를 해봤을 때, 최신 코드는 아니지만 생각 이상으로 빠른 속도로 코드가 수행되는 것을 볼 수 있다.
참고문헌
[1] https://arxiv.org/pdf/1703.06953v2.pdf
[2] https://github.com/zhanghang1989/PyTorch-Multi-Style-Transfer
[3] J. Long, E. Shelhamer, and T. Darrell. Fully convolutional networks for semantic segmentation. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 3431–3440, 2015. 2, 4, 5, 6
[4] K. He, X. Zhang, S. Ren, and J. Sun. Deep residual learning for image recognition. In Proceedings of the IEEE Conference on Computer Vision and Pattern Recognition, pages 770–778, 2016. 2, 4