gpt4 book ai didi

javascript - tensorflowjs 如何在 cnn 预测中获取内层输出

转载 作者:行者123 更新时间:2023-11-29 15:14:15 25 4
gpt4 key购买 nike

我正在查看 tfjs 中的 tensorflow.js CNN 示例.

可在此处找到测试库:testing repo .

有什么方法可以从每一层获得输出吗?

 async showPredictions() {
const testExamples = 1;
// const testExamples = 100;
const batch = this.data.nextTestBatch(testExamples);

tf.tidy(() => {
const output: any = this.model.predict(batch.xs.reshape([-1, 28, 28, 1]));

output.print();
const axis = 1;
const labels = Array.from(batch.labels.argMax(axis).dataSync());
const predictions = Array.from(output.argMax(axis).dataSync());

// ui.showTestResults(batch, predictions, labels);
});
}

上面是tfjs例子中的预测方法,但是只打印了最后一层。如何在预测中获得每一层(包括转换层、最大池化层和全连接层)的输出?

最佳答案

要获取所有内层,可以使用模型的属性layers。获得图层后,您可以使用每个图层的属性 inputoutput 来定义新模型或使用 apply方法。

有人问过类似的问题herethere

关于javascript - tensorflowjs 如何在 cnn 预测中获取内层输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50942677/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com