MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / customLayerDemo

Function customLayerDemo

custom-layer/index.js:22–34  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20import {antirectifier} from './custom_layer';
21
22function 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
36function tensorToCanvas(tensor, canvas) {
37 const ctx = canvas.getContext('2d');

Callers 1

index.jsFile · 0.85

Calls 3

antirectifierFunction · 0.90
tensorToCanvasFunction · 0.85
applyMethod · 0.45

Tested by

no test coverage detected