From 2587dfdbd1347d3b43f5ae5d9b73f2a6439e1e54 Mon Sep 17 00:00:00 2001 From: Ann Yuan Date: Wed, 29 Apr 2020 06:50:04 -0400 Subject: [PATCH] add test --- tfjs-core/src/ops/conv2d_test.ts | 33 ++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/tfjs-core/src/ops/conv2d_test.ts b/tfjs-core/src/ops/conv2d_test.ts index b74f97cd0e5..bec5ec5b077 100644 --- a/tfjs-core/src/ops/conv2d_test.ts +++ b/tfjs-core/src/ops/conv2d_test.ts @@ -360,25 +360,30 @@ describeWithFlags('conv2d', ALL_ENVS, () => { const pad = 'same'; const stride: [number, number] = [2, 2]; - const inputs = generateCaseInputs( - 1 * xSize * xSize * inputDepth, - fSize * fSize * inputDepth * outputDepth); - const x = tf.tensor4d(inputs.input, inputShape); - const w = - tf.tensor4d(inputs.filter, [fSize, fSize, inputDepth, outputDepth]); + // TODO(annxingyuan): Make this test work with large inputs using + // generateCaseInputs https://github.com/tensorflow/tfjs/issues/3143 + const inputData = []; + for (let i = 0; i < xSize * xSize * inputDepth; i++) { + inputData.push(i % 5); + } + + const wData = []; + for (let i = 0; i < fSize * fSize * inputDepth * outputDepth; i++) { + wData.push(i % 5); + } + + const x = tf.tensor4d(inputData, inputShape); + const w = tf.tensor4d(wData, [fSize, fSize, inputDepth, outputDepth]); const result = tf.conv2d(x, w, stride, pad); expect(result.shape).toEqual([1, 4, 4, 4]); expectArraysClose( await result.data(), new Float32Array([ - 57771, 58554, 59337, 60120, 66357, 67302, 68247, 69192, - 74943, 76050, 77157, 78264, 49071, 49890, 50709, 51528, - 126459, 128538, 130617, 132696, 135045, 137286, 139527, 141768, - 143631, 146034, 148437, 150840, 89679, 91362, 93045, 94728, - 195147, 198522, 201897, 205272, 203733, 207270, 210807, 214344, - 212319, 216018, 219717, 223416, 130287, 132834, 135381, 137928, - 105798, 108696, 111594, 114492, 109578, 112584, 115590, 118596, - 113358, 116472, 119586, 122700, 64502, 66632, 68762, 70892 + 104, 125, 126, 102, 133, 126, 104, 57, 137, 102, 57, 112, 64, + 40, 76, 92, 116, 53, 110, 142, 50, 104, 133, 137, 104, 125, + 126, 102, 83, 88, 78, 33, 133, 126, 104, 57, 137, 102, 57, + 112, 116, 53, 110, 142, 37, 76, 100, 99, 33, 68, 83, 88, + 70, 83, 76, 64, 92, 88, 64, 40, 51, 44, 27, 50 ])); });