Issue
I am looking at tensorflow.js CNN example from tfjs.
The testing repo can be found here: testing repo.
Is there any way I can get outputs from each layer?
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);
});
}
Above is the prediction method from the tfjs example, but only the last layer is printed. How can I get outputs from each layer (including conv, max pooling and fully connect layers) in a prediction?
Solution
To get all inner layers, you can use the property layers
of models. Once you get the layers you can use the properties input
and output
of each layer to define a new model or use the apply method.
Similar questions have been asked here and there
Answered By - edkeveked
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.