打印所有图层输出

编程入门 行业动态 更新时间:2024-10-07 10:18:31
本文介绍了打印所有图层输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

给定以下模型,如何打印所有图层值?

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

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 output = denseLayer2.apply(denseLayer1.apply(input));
    const model = tf.model({inputs: input, outputs: output});
    model.predict(tf.ones([2, 5])).print();
    
    
 

<html>
  <head>
    <!-- Load TensorFlow.js -->
    <script src="https://cdn.jsdelivr/npm/@tensorflow/tfjs@0.12.0"> </script>
  </head>

  <body>
  </body>
</html>

推荐答案

要打印图层,需要在模型配置中定义要输出的图层,使用 outputs 属性.在 model.predict() 上使用解构赋值可以检索中间层以输出

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()

<html>
  <head>
    <!-- Load TensorFlow.js -->
    <script src="https://cdn.jsdelivr/npm/@tensorflow/tfjs@0.12.0"> </script>
  </head>

  <body>
  </body>
</html>

这篇关于打印所有图层输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-05-01 00:54:02,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1402421.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:图层

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!