我按照本教程进行操作,并使用了Github页面上的ipynb笔记本在Google合作实验室中生成了Deepdream图片。本教程使用Inception5h网络。此模型中的12层通常用于生成图像。
每层包含大约500个单独的要素,可以识别不同的图案。可以在图层中选择特定特征,从而产生不同的结果。我已经在第6层'mixed4a:0'中生成了每个特征的图像。我现在想做的就是混合使用这些功能。
选择特定的层是这样的:
layer_tensor = model.layer_tensors[5]
# selects layer 6 out of 12
我可以选择以下一系列功能:
layer_tensor = model.layer_tensors[5][:,:,:,0:3]
# selects feature 0 to 2 from layer 6
我要尝试的是选择特定功能,而不是一系列功能。我尝试了几项显然行不通的事情。
layer_tensor = model.layer_tensors[5][:,:,:,0,2,4]
layer_tensor = model.layer_tensors[5][:,:,:,0:2:4]
layer_tensor = model.layer_tensors[5][:,:,:,[0,2,4]]
layer_tensor = model.layer_tensors[5][:,:,:,[0:2:4]]
layer_tensor = model.layer_tensors[5][:,:,:,(0,2,4)]
为了弄清楚“ layer_tensor”是哪种对象/事物/数据结构,我尝试使用不同的参数进行打印:
layer_tensor = model.layer_tensors[5]
# prints Tensor("mixed4a:0", shape=(?, ?, ?, 508), dtype=float32, device=/device:CPU:0)
# "mixed4a:0" is the layer name. 508 in 'shape' is the number of features in the layer
layer_tensor = model.layer_tensors[5][:,:,:,0:100]
# prints: Tensor("strided_slice_127:0", shape=(?, ?, ?, 100), dtype=float32)
layer_tensor = model.layer_tensors[5][:,:,:,0]
# prints: Tensor("strided_slice_128:0", shape=(?, ?, ?), dtype=float32)
我是Tensorflow和神经网络的新手。有谁知道如何选择不同的功能,而不仅仅是一系列功能?提前致谢!
要运行代码,请将“ DeepDream_using_tensorflow.ipynb”文件加载到Google Colaboratory中。选择带有GPU后端的Python3运行时。将文件“ download.py”和“ inception5h.py”上传到运行时,它应该可以正常工作。
您可以使用tf.gather通过以下方式实现所需的功能。
# don't forget to have a look over the deep_dream_final_output.html file to see the processed outputs.
indices = [1,3,5]
layer_tensor = tf.transpose(
tf.gather(
tf.transpose(model.layer_tensors[10], [3,0,1,2]), indices
),
[1,2,3,0])
print(layer_tensor)
img_result = recursive_optimize(layer_tensor=layer_tensor, image=image,
num_iterations=10, step_size=3.0, rescale_factor=0.7,
num_repeats=4, blend=0.2)
它看起来很复杂,但是接下来要做的只是。
layer_tensor
st的最后一个轴(即要切片的轴)移到第一个轴(因为这样做使切片变得容易得多)tf.gather
。我们采用了1,3,5功能。它可能是索引列表希望很清楚。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句