|
| 1 | +import * as tf from '@tensorflow/tfjs'; |
| 2 | +import './styles.css'; |
| 3 | + |
| 4 | +const img = new Image(); |
| 5 | +img.crossOrigin = 'anonymous'; |
| 6 | +img.src = |
| 7 | + 'https://images.unsplash.com/photo-1557800636-894a64c1696f?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1601&q=80'; |
| 8 | + |
| 9 | +img.onload = (event) => { |
| 10 | + const imgTensor = tf.browser.fromPixels(event.target); |
| 11 | + |
| 12 | + document.getElementById('app').innerHTML = ` |
| 13 | + <code>TensorFlow version: ${tf.version.tfjs}</code> |
| 14 | + <h1>Triple your tensors training data</h1> |
| 15 | + <div class="layout"> |
| 16 | + <div> |
| 17 | + <code>Original Tensor</code> |
| 18 | + <canvas id="baseCanvas"></canvas> |
| 19 | + </div> |
| 20 | + <div> |
| 21 | + <code>tf.reverse(1)</code> |
| 22 | + <canvas id="revertXCanvas"></canvas> |
| 23 | + </div> |
| 24 | + <div> |
| 25 | + <code>tf.reverse(0)</code> |
| 26 | + <canvas id="revertYCanvas"></canvas> |
| 27 | + </div> |
| 28 | + </div> |
| 29 | + `; |
| 30 | + |
| 31 | + const baseCanvas = document.getElementById('baseCanvas'); |
| 32 | + tf.browser.toPixels(imgTensor, baseCanvas); |
| 33 | + |
| 34 | + const revertXCanvas = document.getElementById('revertXCanvas'); |
| 35 | + const revertXTensor = imgTensor.reverse(1); |
| 36 | + tf.browser.toPixels(revertXTensor, revertXCanvas); |
| 37 | + |
| 38 | + const revertYCanvas = document.getElementById('revertYCanvas'); |
| 39 | + const revertYTensor = imgTensor.reverse(0); |
| 40 | + tf.browser.toPixels(revertYTensor, revertYCanvas); |
| 41 | +}; |
0 commit comments