简体   繁体   English

如何使用 dnnlib.tflib.network.Network 获得中间层 output

[英]How can I get the intermediate layer output with dnnlib.tflib.network.Network

I am trying StyleGAN2 NviLab,and I want to watch feature maps while generating, but how can I get the intermediate layer output?我正在尝试StyleGAN2 NviLab,我想边生成边看特征图,但是我怎样才能得到中间层output? The model is loaded by dnnlib.tflib.network.Network and no document about this lib. model 由 dnnlib.tflib.network.Network 加载,没有关于此库的文档。

I had the exact same issue, with the exact same codebase.我有完全相同的问题,使用完全相同的代码库。 This is how I got intermediate outputs (TF 1.14.0):这就是我获得中间输出的方式(TF 1.14.0):

Step 1:步骤1:

Check the names of all layers, and their output shapes.检查所有层的名称,以及它们的 output 形状。 This helps identify the name of the layer whose output you want:这有助于识别您想要的 output 层的名称:

network.print_layers()

Step 2:第2步:

Get a list of all layers in the network.获取网络中所有层的列表。 Each element in this list is a tuple (layer name: string, layer output: tensor, layer variables)此列表中的每个元素都是一个元组(layer name: string, layer output: tensor, layer variables)

layers = network.list_layers()

Step 3:第 3 步:

Get a reference to the tensor representing the layer's output, using the name of the layer whose output you need:使用您需要的 output 的层的名称获取对代表层 output 的张量的引用:

for layer in layers:
    print(layer[0], ' ', layer[1])
    if layer[0] == REQUIRED_LAYER_NAME:
        tensor = layer[1]

Finally, run the graph:最后,运行图表:

required_output = sess.run(tensor, feed_dict={'INPUT_TENSOR_NAME': input_numpy_array})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM