💡 [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 摘要。