Neural Style Transfer

2021. 10. 7. 15:31Artificial_Intelligence/Computer Vision

What is NST?

  • Style transfer란, 두 영상(content image & style image)이 주어졌을 때 그 이미지의 주된 형태는 content image와 유사하게 유지하면서 스타일만 우리가 원하는 style image와 유사하게 바꾸는 것을 말함.

Style transfer refers to changing only the style to the style image we want while keeping the main form of the image similar to the content image when two images are given.

 

  • Style Transfer, image-to-image translation, 또는 texture transfer 등으로 불리는 이 문제는 한 이미지 P를 다른 이미지 A의 스타일을 가지는 새로운 이미지 X를 생성하는 방식.

It called Style Transfer, image-to-image translation, or texture transfer, is a way to create a new image X with one image P as the style of another image A.

 Image Style Transfer Using Convolutional Neural Networks ,  Gatys et al.

 

Tensorflow_NST

 

 

방식

 Image Style Transfer Using Convolutional Neural Networks ,  Gatys et al.

 

  • Content와 style을 입력을 받아 새로운 output을 만들어 냄.
  • Pretraining 모델에서 컨텐츠와 스타일 각각의 feature map을 추출하여 저장하고,
  • Output의 feature map이 content의 feature map에서 content가 비슷해지도록, style의 feature map에서 style과 비슷해지도록, output 픽셀들을 최적화함.

 

Take Content and Style as inputs and create a new Output.
Using the pre-training model, a content feature map and a style feature map are extracted and stored. Output's feature map optimizes output pixels so that the content becomes similar on the Content feature map and style feature map becomes similar on the Style feature map.

 

 Image Style Transfer Using Convolutional Neural Networks ,  Gatys et al.

Content의 비율이 더 크면 content의 형태를 더 유지하고,

Style의 비율이 더 크면 형태를 유지하지 못하고 style쪽에 더 치우침.

 

If the proportion of content is larger, the form of content is maintained more.

If the proportion of styles is larger, it cannot maintain its shape and is more biased toward the style.

 

 

사용 결과

Content
Style

 

Output

 

응용

 

  • 포토샵에서 정교하게 만든 합성이미지 같이, 스타일 전송을 사용하여 자연스러운 합성 이미지를 제작하려고 함.
  • NST 모델에서 컨텐츠이미지와 스타일이미지를 동일한 이미지로 하고, 객체를 따서 스티커처럼 컨텐츠이미지에 추가적으로 붙여서 부드러운 이미지 합성을 하려했음.
  • 객체를 하나 따서 사진에 붙이고 크게 두가지 모델로 다른 처리방식을 사용해 돌려봄.
  • openCV로 이미지에서 객체를 검출하고 이미지로 저장하여 스티커 처럼 사용하려고 함.

 

I want to create a natural composite image using style transfer. Like the photoshop composite image.

Setting the content image and the style image as the same image in the NST model.

The object was attached to the content image like a sticker, and a smooth image synthesis was attempted.

Using openCV, an object was detected from an image, stored as an image, and used as a sticker.

The detected object was attached to the picture, and the two models were executed using different processing methods.

meeting of augustus and the sibyl > Pixit App

 

Using VGG19 model

  • loss 값에 따라 스타일 전송의 변화량이 크게 달라져서, weight를 임의로 수정하면서 학습함.

 

The change in Style Transfer varies greatly depending on the loss value.
Therefore, I learned by arbitrarily modifying weight.

 

content_weight = 2.5e-8

style_weight = 1e-6

 

  • 근데 하고 싶은 건 화풍이 아닌, 현실 이미지를 자연스럽게 합성하려고 함.
  • Magenta 모델과 VGG19 모델로 실험하였다.

 

I tried to synthesize the real image naturally, not the style of painting style.

Experiments were conducted with the Magenta model and the VGG19 model.

컨텐츠 이미지와 객체를 합쳐서 돌림
마젠타 모델을 사용한 결과

이 모델을 사용해서 돌리면 현실 사진 같지않고, 명화같은 느낌이 더 난다고 느꼈음.

  • 좌측은 이미지를 MinMax Normalization 하여 0~1 값의 float32 타입의 텐서형식으로 바꾸고, 이를 크기를 조정하여 4차원 텐서로 바꿔서 처리함. 이미지의 최대크기를 1024로 설정
  • 우측은 이미지를 똑같이 정규화 하여 바운딩 박스처리해서 정사각형으로 자르고 0-1정규화 시켜서 이를 리사이즈해서 넣음. 이미지의 최대크기를 256으로 설정. 스타일 이미지에 kernal(3,3), strides(1,1) avg_pool을 한번더 사용하여 크기를 줄여서 돌림

 

Left side result

The image was converted into a float32 type tensor type of 0-1 value by MinMax Normalization, and it was converted into a 4D tensor by resizing it. Set the maximum size of the Style image to 1024.

 

Right side result

I normalized the image equally, processed the bounding box to cut it into a square, normalized it to a value of 0-1, and resized it. Avg_pool (kernal(3,3) and strands(1,1)) were used once more for the style image to reduce the size and execute. Set the maximum size of the Style image to 1024.

객체만 따서 돌린 결과

 

VGG19 모델을 사용한 결과

  • 이미지를 array형식으로 받아서 vgg19모델에 맞게 텐서로 반환.
  • 각 이미지의 loss값을 그람행렬(Gram Matrix)로 계산.
  • 그람 행렬이란 각 특성 맵의 평균과 피쳐맵 사이의 상관관계의 정보를 담고있고, 이는 각 위치에서의 특성벡터의 외적과 평균으로 구해서 얻을 수 있음.

 

The image is received in Array form and returned to the tensor according to the vgg19 model.

Calculates the loss value of each image as a Gram matrix.

The graph matrix contains information on the correlation between the mean of each feature map and the feature map, which can be obtained by obtaining the external and average of the feature vector at each location.

728x90