Reputation: 1
I am trying StyleGAN2 NviLab,and I want to watch feature maps while generating, but how can I get the intermediate layer output? The model is loaded by dnnlib.tflib.network.Network and no document about this lib.
Upvotes: 0
Views: 590
Reputation: 3764
I had the exact same issue, with the exact same codebase. This is how I got intermediate outputs (TF 1.14.0):
Step 1:
Check the names of all layers, and their output shapes. This helps identify the name of the layer whose output you want:
network.print_layers()
Step 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)
layers = network.list_layers()
Step 3:
Get a reference to the tensor representing the layer's output, using the name of the layer whose output you need:
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})
Upvotes: 2