print all layers output

后端 未结 2 855
清酒与你
清酒与你 2021-01-26 04:47

Given the following model, how to print all layers values ?

2条回答
  •  北海茫月
    2021-01-26 05:35

    To print layers, one needs to define the layers to output in the model configuration, using, outputs property. Using destructuring assignement on model.predict() one could retrieve the intermediate layers to output

    const input = tf.input({shape: [5]});
            const denseLayer1 = tf.layers.dense({units: 10, activation: 'relu'});
            const denseLayer2 = tf.layers.dense({units: 2, activation: 'softmax'});
            const output1 = denseLayer1.apply(input);
            const output2 = denseLayer2.apply(output1);
            const model = tf.model({inputs: input, outputs: [output1, output2]});
            const [firstLayer, secondLayer] = model.predict(tf.ones([2, 5]));
            firstLayer.print();
            secondLayer.print()
    
      
        
        
      
    
      
      
    

提交回复
热议问题