💡 [REQUEST] - Neural Style Transfer: change layers to compute style/content

未關閉
#3,732 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 2 天內回覆

還沒有人認領這個 Issue。

評估

難度
1/5
預估耗時
1 小時以內
新手友好度
55/100
Issue 類型
文件
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
python

研究方向

從連結的 Neural Style Transfer 教學課程及其中對目標深度層的定義開始。比較教學課程中的連續層名稱與文章中分組的 VGG 層,然後驗證文件中記載的風格層與內容層選擇是否與引用的論文一致,並產生教學課程預期的行為。

由索引模型根據 Issue 內容生成。

描述

core
🚀 Describe the improvement or the new tutorial

I tried using code from Neural Style Transfer tutorial to apply a van Gogh style to my photo, and results were way poorer copared to what I've seen on DeepArt.io.

Luckily, I found what's the issue, and how to improve quality.

Original paper states:

Thus, the visually
most appealing images are usually created by matching the
style representation up to high layers in the network, which
is why for all images shown we match the style features
in layers ‘conv1_1’, ‘conv2_1’, ‘conv3_1’, ‘conv4_1’ and
‘conv5_1’ of the network.

and also:

The images shown in Fig 3
were synthesised by matching the content representation
on layer ‘conv4_2’ and the style representation on layers
‘conv1_1’, ‘conv2_1’, ‘conv3_1’, ‘conv4_1’ and ‘conv5_1’

In the tutorial, layer conv_4 is used for content and layers from conv_1 to conv_5 for style.:

# desired depth layers to compute style/content losses :
content_layers_default = ['conv_4']
style_layers_default = ['conv_1', 'conv_2', 'conv_3', 'conv_4', 'conv_5']

At first glance everything looks fine, but indexing patterns are different: in the article (and original VGG model) layers were split into groups between poolings, and in the tutorial a continuous numbering is used.

Article Tutorial
conv1_1 conv_1
conv1_2 conv_2
--- ---
conv2_1 conv_3
conv2_2 conv_4
--- ---
conv3_1 conv_5
conv3_2 conv_6
conv3_3 conv_7
conv3_4 conv_8
--- ---
conv4_1 conv_9
conv4_2 conv_10
conv4_3 conv_11
conv4_4 conv_12
--- ---
conv5_1 conv_13
conv5_2 conv_14
conv5_3 conv_15
conv5_4 conv_16

So layers conv_1, conv_3, conv_5, conv_9 and conv_13 should be used for style and layer conv_10 for content.

That produces way better results.

Suggested change
# desired depth layers to compute style/content losses :
content_layers_default = ['conv_10']
style_layers_default = ['conv_1', 'conv_3', 'conv_5', 'conv_9', 'conv_13']
Existing tutorials on this topic

https://docs.pytorch.org/tutorials/advanced/neural_style_tutorial.html

Additional context

Another suggestion to improve quality: #3731

cc @albanD @jbschlosser

主要語言
Python
星號
9.5k
分支
4.5k
平均合併
1 天 20 小時
30 天內合併 PR
2

環境準備

在 Codespaces 中開啟

在瀏覽器裡用你自己的 GitHub 帳號啟動這個專案的開發容器。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

pytorch/tutorials 的其他 Issue

查看 pytorch/tutorials 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。