/NST---Neural-Style-Transfer

Neural Style Transfer in keras

Primary LanguageJupyter Notebook

NST - Neural Style Transfer

Keras'ta Sinirsel Stil Aktarımı
Kaynak kodları hazır olarak sizi beklemektedir. İçerik ve stil görüntülerini, kullanmak istediğiniz VGG modelini, optimizasyon yönteminizi ve iterasyon sayısını belirledikten sonra kendi görüntünüzü elde edebilirsiniz.

Neural Style Transfer in keras
The source codes are ready for you. After determining the content and style images, the VGG model you want to use, your optimization method and the number of iterations, you can get your own image.

Stil aktarımı nedir? / What is the style transfer?

Stil aktarımı, temelinde CNN modeli kullanarak içerik görüntüsünün içeriğini ve stil görüntüsünün stilini (dokusunu) ayırarak, içerik görüntüsüne stili özelliklerinin aktarımını sağlayan ve yeni bir görüntü elde eden bir yöntemdir.

Style transfer is a method that separates the content of the content image and the style (texture) of the style image by using the CNN model on its basis, providing the transfer of style properties to the content image and obtaining a new image.

Bunu nasıl yapar? / How does it do that?

İki farklı VGG modelini ele alalım

  • VGG16
  • VGG19

Bu iki ağ modeli ile:

  • Derin katmanda elde edilen özniteliği ile içeriğini bulunur ve hedef görüntü ile arasındaki fark bulunur. Bu farka içerik kaybı denilir.
  • Modelin her bloğunda bulunan konvolüsyon katmanınlarındaki stil ve hedef görüntünün özniteliklerine bakılarak stil kaybı bulunur,
  • Hesaplanan iki kayıp değeri toplanır ve güncellenir.
  • Ardından Gradyon iniş yöntemiyle hedef görüntü güncellenerek belirlediğimiz adım sayısında işlem tekrarlanır.

Consider two different VGG models

  • VGG16
  • VGG19

With these two network models:

  • Finds the attribute and its content in the deep layer and the difference between it and the target image This difference is called the loss of content.
  • Style loss is found by looking at the style and attributes of the target image in the convolution layers in each block of the model,
  • The two calculated loss values are added up and updated.
  • Then, the target image is updated with the Gradient descent method and the process is repeated for the number of steps we have determined.

Kayıp Fonksiyonları Nasıl Hesaplanır? / How to Calculate Loss Functions?

İçerik Kaybı / Content Loss

İçerik kaybı yapılan bu uygulamada, VGG modelin son (5.) bloğunda bulunan 2. konvolüsyon aşamasındaki hedef görüntü ile içerik görüntüsü arasındaki fark hesaplanarak bulunur. Amaç hedef görüntünün ne kadar içerik görüntüsüne içerik açısından benzediğini bulmaktır.

In this application with content loss, the difference between the target image in the 2nd convolution stage and the content image in the last (5th) block of the VGG model is calculated and found. The goal is to find out how much the target image resembles the content image in terms of content.

Stil Kaybı / Style Loss

Stil kaybı, VGG modelin her bloğunda bulunan 1. konvolüsyon aşamasında hesaplanır. Lakin stil kaybını hesaplamadan evvel bir işlem daha uygulamamız gerekmektedir. Bu işlemin adı ise Gram Matrisi bulmaktır. Gram matris korelasyonu bulmakta bize yardımcı olacaktır. Gram matris 2 boyutlu görüntünün transpozesi ile çarpılmasıyla bulunur.

Style loss is calculated in the 1st convolution phase in each block of the VGG model. However, we need to apply another process before calculating the style loss. The name of this process is to find the Gram Matrix. Gram matrix will assist us in finding correlation. The gram matrix is found by multiplying the 2D image by its transpose.

Gram matrisi bulduktan sonra stil kaybını hesaplayabiliriz.

After finding the gram matrix, we can calculate the style loss.

Stil görüntüsünün gram matrisinin hedef görüntünün gram matrisinden farkı hesaplanır.

The difference of the gram matrix of the style image from the gram matrix of the target image is calculated.

Her katmanda elde edilen kayıplar küçük bir değerle güncellenir ve toplanır. Elde edilen son değer ise bizim stil kaybımızdır.

The losses obtained in each layer are updated with a small value and summed up. The last value achieved is our style loss.

Toplam Kayıp / Total Loss

Bu iki kayıp değeri (içerik ve stil) alfa ve beta değerleri ile güncellenerek toplanır.

These two loss values (content and style) are added up by updating them with alpha and beta values.

Konu hakkında yayınlanmış makalem / My published article on this subject

Dergipark Adresi

dergipark

İletişim / Contact

contact