【问题标题】:Reconstruct input image from feature maps for Neural Style transfer从特征图重建输入图像以进行神经风格迁移
【发布时间】:2021-01-17 20:33:08
【问题描述】:

我正在使用 VGG19 模型进行神经风格迁移。我正在尝试遵循论文:A Neural Algorithm of Artistic Style (https://arxiv.org/pdf/1508.06576.pdf) 并尝试使用每个卷积层的特征图重建图像,如下图所示。

我已经提取了卷积层的特征图,如下面的代码所示。

    vgg = VGG16(include_top = True, weights = "imagenet")
    model_layer_names = ["block1_conv1","block1_conv2","block2_conv1","block2_conv2","block3_conv1","block3_conv2","block3_conv3","block4_conv1",
                 "block4_conv2","block4_conv3","block5_conv1","block5_conv2","block5_conv3"]
    layer_ouputs = [vgg.get_layer(layer).output for layer in model_layer_names]
    viz_model = Model(inputs = vgg.input, outputs = layer_ouputs)
    feature_map_preds = viz_model.predict(style_img)

我能够将特征图绘制为图像。但我想使用特征图绘制输入图像(如上面的内容和样式表示图像),我无法将通道(64,128,256,512)转换为 3 个通道。有人可以帮我解决这个问题吗?

非常感谢任何 cmets 和帮助。

【问题讨论】:

    标签: python tensorflow keras conv-neural-network vgg-net


    【解决方案1】:

    我也遇到了同样的问题!我最终解决了这个问题: 将内容权重设置为零,将样式权重设置为某个较大的正数——我使用了 1000,但看看什么对你有用。然后使用缩放到 0 到 255 之间的白噪声数组对其进行初始化:

    input = np.random.randn(1, 256, 256, 3) * 255
    

    然后根据您要重建的样式级别,设置样式层的权重。要从 conv1(第一种风格重建)重建,请使用:

    style_layer_weights = [1, 0, 0, 0, 0]
    

    或从 conv1 和 conv2 重建(第二种风格重建),使用:

    style_layer_weights = [0.5, 0.5, 0, 0, 0]
    

    然后

    for style_feature, target_feature, weight in zip(features, target_features, weights):
        style_score += style_loss(style_feature, target_feature) * weight
    

    然后运行梯度下降,它应该会收敛到样式重建。

    【讨论】:

    • 哦,好吧...我会尝试一下...谢谢您的帮助。
    猜你喜欢
    • 2018-07-21
    • 2019-10-24
    • 2018-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-02
    • 2013-10-20
    • 2016-04-01
    相关资源
    最近更新 更多