* Captures a frame from the webcam and normalizes it between -1 and 1. * Returns a batched image (1-element batch) of shape [1, w, h, c].
()
| 157 | * Returns a batched image (1-element batch) of shape [1, w, h, c]. |
| 158 | */ |
| 159 | async function getImage() { |
| 160 | const img = await webcam.capture(); |
| 161 | const processedImg = |
| 162 | tf.tidy(() => img.expandDims(0).toFloat().div(127).sub(1)); |
| 163 | img.dispose(); |
| 164 | return processedImg; |
| 165 | } |
| 166 | |
| 167 | document.getElementById('train').addEventListener('click', async () => { |
| 168 | ui.trainStatus('Training...'); |