|
| 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/flagged/photo-1572349854775-e5768e1afb74?ixlib=rb-1.2.1&auto=format&fit=crop&w=1267&q=80'; |
| 8 | + |
| 9 | +img.onload = (event) => { |
| 10 | + const imgTensor = tf.browser.fromPixels(event.target); |
| 11 | + imgTensor.print(); |
| 12 | + |
| 13 | + document.getElementById('app').innerHTML = ` |
| 14 | + <code>TensorFlow version: ${tf.version.tfjs}</code> |
| 15 | + <h1>${imgTensor.shape[1]}x${imgTensor.shape[0]}</h1> |
| 16 | + <canvas id="printCanvas"></canvas> |
| 17 | + `; |
| 18 | + |
| 19 | + const printCanvas = document.getElementById('printCanvas'); |
| 20 | + tf.browser.toPixels(imgTensor, printCanvas); |
| 21 | +}; |
0 commit comments