()
| 20 | import {antirectifier} from './custom_layer'; |
| 21 | |
| 22 | function customLayerDemo() { |
| 23 | let imgElement = document.getElementById('cat'); |
| 24 | // Layer expects first dimension to be batch, therefore expandDims. |
| 25 | const img = tf.browser.fromPixels(imgElement).toFloat().expandDims(0); |
| 26 | const layer = antirectifier(); |
| 27 | const [posTensor, negTensor] = tf.split(layer.apply(img), 2, 3); |
| 28 | const posCanvas = document.createElement('canvas'); |
| 29 | tensorToCanvas(posTensor, posCanvas); |
| 30 | document.getElementById('output_image_1').appendChild(posCanvas); |
| 31 | const negCanvas = document.createElement('canvas'); |
| 32 | tensorToCanvas(negTensor, negCanvas); |
| 33 | document.getElementById('output_image_2').appendChild(negCanvas); |
| 34 | } |
| 35 | |
| 36 | function tensorToCanvas(tensor, canvas) { |
| 37 | const ctx = canvas.getContext('2d'); |
no test coverage detected