Created
September 12, 2020 11:52
-
-
Save arielmagbanua/1bd6ec5700608102f81eb471c6effeea to your computer and use it in GitHub Desktop.
TensorFlowJs Advanced Manipulation rg blind
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// TensorPlayground.com | |
// https://images.unsplash.com/photo-1506108928571-9f4b11ba3f10?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=1350&q=80 | |
// INPUT TENSOR SHAPE: [901,1350,3] | |
(tf, aTensor) => { | |
const height = aTensor.shape[0] | |
const width = aTensor.shape[1] | |
const halfHeight = (height - 1) / 2 | |
console.log(halfHeight) | |
const [red, green, blue] = aTensor.split(3, 2) | |
// stack red and green + average | |
const rg = tf.mean(tf.stack([red, green]), 0).asType("int32") | |
// recostruct rgb | |
const rgb = tf.concat([rg, rg, blue], 2) | |
const rgbUpperHalf = rgb.slice(0, [halfHeight + 65, width, 3]) | |
const lowerSliceStart = halfHeight + 65 | |
const lowerHeightSlice = halfHeight + 1 - 65; | |
const originalLowerHalf = aTensor.slice([lowerSliceStart, 0], [lowerHeightSlice, width, 3]) | |
const tigerConcat = rgbUpperHalf.concat(originalLowerHalf, 0) | |
return tigerConcat | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment