UNPKG

10.4 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright 2018 Google LLC. All Rights Reserved.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * =============================================================================
17 */
18Object.defineProperty(exports, "__esModule", { value: true });
19// We import index.ts so that the Node backend gets registered.
20require("./index");
21// tslint:disable-next-line: no-imports-from-dist
22require("@tensorflow/tfjs-core/dist/public/chained_ops/register_all_chained_ops");
23// tslint:disable-next-line: no-imports-from-dist
24require("@tensorflow/tfjs-core/dist/register_all_gradients");
25var tf = require("@tensorflow/tfjs");
26// tslint:disable-next-line:no-imports-from-dist
27var jasmine_util = require("@tensorflow/tfjs-core/dist/jasmine_util");
28var yargs_1 = require("yargs");
29Error.stackTraceLimit = Infinity;
30// tslint:disable-next-line:no-require-imports
31var jasmineCtor = require('jasmine');
32// tslint:disable-next-line:no-require-imports
33process.on('unhandledRejection', function (e) {
34 throw e;
35});
36jasmine_util.setTestEnvs([{
37 name: 'test-tensorflow',
38 backendName: 'tensorflow',
39 flags: {},
40 isDataSync: true
41 }]);
42var IGNORE_LIST = [
43 // Always ignore version tests:
44 'version version',
45 'unreliable is true due to both auto gc and string tensors',
46 'unreliable is true due to auto gc',
47 // See https://github.com/tensorflow/tfjs/issues/161
48 'depthwiseConv2D',
49 'separableConv2d',
50 'complex64 memory',
51 // See https://github.com/tensorflow/tfjs-core/pull/1270
52 'depthToSpace test-tensorflow {} throws when blocksize < 2',
53 // tslint:disable-next-line:max-line-length
54 'depthToSpace test-tensorflow {} throws when CPU backend used with data format NCHW',
55 // See https://github.com/tensorflow/tfjs/issues/806
56 'scatterND test-tensorflow {} should work for 2d',
57 'scatterND test-tensorflow {} should work for simple 1d',
58 'scatterND test-tensorflow {} should work for multiple 1d',
59 'scatterND test-tensorflow {} should sum the duplicated indices',
60 'scatterND test-tensorflow {} should work for tensorLike input',
61 // https://github.com/tensorflow/tfjs/issues/1077
62 // tslint:disable-next-line:max-line-length
63 'maxPool test-tensorflow {} x=[2,2,3] f=[2,2] s=3 p=1 default dimRoundingMode',
64 'maxPool test-tensorflow {} x=[2,2,3] f=[1,1] s=2 p=1 dimRoundingMode=floor',
65 'maxPool test-tensorflow {} x=[2,2,3] f=[2,2] s=3 p=1 dimRoundingMode=floor',
66 'maxPool test-tensorflow {} x=[2,2,3] f=[2,2] s=3 p=1 dimRoundingMode=round',
67 'maxPool test-tensorflow {} x=[2,2,3] f=[2,2] s=3 p=1 dimRoundingMode=ceil',
68 // Node backend which uses TF 2.4.0 doesn't support explicit padding
69 'avgPool test-tensorflow {} x=[3,3,1] f=[3,3] s=1 p=explicit',
70 // tslint:disable-next-line:max-line-length
71 'avgPool test-tensorflow {} x=[2,2,3] f=[2,2] s=3 p=1 default dimRoundingMode',
72 'avgPool test-tensorflow {} x=[2,2,3] f=[1,1] s=2 p=1 dimRoundingMode=floor',
73 'avgPool test-tensorflow {} x=[2,2,3] f=[2,2] s=3 p=1 dimRoundingMode=floor',
74 'avgPool test-tensorflow {} x=[2,2,3] f=[2,2] s=3 p=1 dimRoundingMode=round',
75 'avgPool test-tensorflow {} x=[2,2,3] f=[2,2] s=3 p=1 dimRoundingMode=ceil',
76 // Node backend which uses TF 2.4.0 doesn't support explicit padding
77 'avgPool test-tensorflow {} gradient x=[3,3,1] f=[3,3] s=1 p=explicit',
78 // tslint:disable-next-line:max-line-length
79 'avgPool3d test-tensorflow {} x=[1,2,2,2,1] f=[2,2,2] s=1 p=1 roundingMode=floor',
80 // Node backend which uses TF 2.4.0 doesn't support explicit padding
81 'maxPool test-tensorflow {} x=[3,3,1] f=[3,3] s=1 p=explicit',
82 'maxPoolBackprop test-tensorflow {} gradient x=[3,3,1] f=3 s=1 p=explicit',
83 // tslint:disable-next-line:max-line-length
84 'maxPool3d test-tensorflow {} x=[1,2,2,2,1] f=[2,2,2] s=1 p=1 roundingMode=floor',
85 // libtensorflow doesn't support 6D ArgMax yet.
86 'argmax test-tensorflow {} 6D, axis=0',
87 'diag test-tensorflow {} complex',
88 'diag test-tensorflow {} bool',
89 // See https://github.com/tensorflow/tfjs/issues/1891
90 'conv2d test-tensorflow {} x=[2,1,2,2] f=[1,1,1,1] s=1 d=1 p=0 NCHW',
91 'conv2d test-tensorflow {} x=[1,2,2] f=[2,2,1,1] s=1 d=1 p=explicit NCHW',
92 'conv2d test-tensorflow {} x=[1,2,2] f=[2,2,1,1] s=1 d=1 p=same NCHW',
93 'conv2d test-tensorflow {} x=[2,2,2] f=[2,2,2,1] s=1 d=1 p=same NCHW',
94 'conv2d test-tensorflow {} x=[2,1,2,2] f=[2,2,1,1] s=1 d=1 p=same NCHW',
95 'conv2d test-tensorflow {} gradient x=[1,1,3,3] f=[2,2,1,1] s=1 p=0 NCHW',
96 'conv2d test-tensorflow {} gradient x=[2,1,3,3] f=[2,2,1,1] s=1 p=0 NCHW',
97 // Node backend which uses TF 2.4.0 doesn't support explicit padding
98 'conv2dTranspose test-tensorflow {} input=3x3x1,d2=1,f=2,s=2,p=explicit',
99 // tslint:disable-next-line:max-line-length
100 'conv2dTranspose test-tensorflow {} input=8x8x8,output=4x4x8,f=8,s=1,inDepth=8,p=same vec4',
101 // tslint:disable-next-line:max-line-length
102 'conv2dTranspose test-tensorflow {} gradient input=[1,3,3,1] f=[2,2,2,1] s=[1,1] p=explicit',
103 'fused conv2d test-tensorflow {} basic in NCHW',
104 'fused conv2d test-tensorflow {} im2row in NCHW',
105 'fused conv2d test-tensorflow {} batch in NCHW',
106 'maxPoolWithArgmax',
107 'rotate',
108 // FIXME: unique NaN-handling is inconsistent between TFJS and TFPY
109 'unique test-tensorflow {} 1d tensor with NaN and Infinity',
110 // Node backend which uses TF 2.4.0 doesn't support explicit padding
111 'pool test-tensorflow {} max x=[3,3,1] f=[3,3] s=1 d=1 p=explicit',
112 // tslint:disable-next-line:max-line-length
113 'pool test-tensorflow {} max x=[3,3,1] f=[3,3] s=3 d=1 p=explicit defualt dimRoundingMode',
114 // tslint:disable-next-line:max-line-length
115 'pool test-tensorflow {} max x=[3,3,1] f=[3,3] s=3 d=1 p=explicit dimRoundingMode=floor',
116 // tslint:disable-next-line:max-line-length
117 'pool test-tensorflow {} max x=[3,3,1] f=[3,3] s=3 d=1 p=explicit dimRoundingMode=round',
118 // tslint:disable-next-line:max-line-length
119 'pool test-tensorflow {} max x=[3,3,1] f=[3,3] s=3 d=1 p=explicit dimRoundingMode=ceil',
120 // tslint:disable-next-line:max-line-length
121 'pool test-tensorflow {} avg x=[3,3,1] f=[3,3] s=3 d=1 p=explicit defualt dimRoundingMode',
122 // tslint:disable-next-line:max-line-length
123 'pool test-tensorflow {} avg x=[3,3,1] f=[3,3] s=3 d=1 p=explicit dimRoundingMode=floor',
124 // tslint:disable-next-line:max-line-length
125 'pool test-tensorflow {} avg x=[3,3,1] f=[3,3] s=3 d=1 p=explicit dimRoundingMode=round',
126 // tslint:disable-next-line:max-line-length
127 'pool test-tensorflow {} avg x=[3,3,1] f=[3,3] s=3 d=1 p=explicit dimRoundingMode=ceil',
128 // tslint:disable-next-line:max-line-length
129 'pool test-tensorflow {} max x=[2,2,3] f=[1,1] s=2 p=1 fractional outputs default rounding',
130 // Node backend which uses TF 2.4.0 doesn't support explicit padding
131 'pool test-tensorflow {} avg x=[3,3,1] f=[3,3] s=1 d=1 p=explicit',
132 // tslint:disable-next-line:max-line-length
133 'pool test-tensorflow {} avg x=[2,2,3] f=[1,1] s=2 p=1 fractional outputs default rounding',
134 // not available in tf yet.
135 'denseBincount',
136 // only available in tf addon.
137 'image.transform',
138 'sign test-tensorflow {} basic',
139 'sign test-tensorflow {} does not propagate NaNs',
140 'sign test-tensorflow {} accepts a tensor-like object',
141 // Node kernel for einsum is yet to be implemented.
142 // See: ttps://github.com/tensorflow/tfjs/issues/2349
143 'einsum',
144 'raggedTensorToTensor',
145 'searchSorted',
146 'sparseFillEmptyRows',
147 'sparseReshape',
148 'sparseSegmentMean',
149 'sparseSegmentSum',
150 'stringNGrams',
151 'stringSplit',
152 'stringToHashBucketFast',
153 'greaterEqual test-tensorflow {} should support string comparison',
154 'greater test-tensorflow {} should support string comparison',
155 'lessEqual test-tensorflow {} should support string comparison',
156 'less test-tensorflow {} should support string comparison',
157 // int32 input for the following ops not supported by TF 2.4.0.
158 'leakyrelu test-tensorflow {} int32',
159 'step kernel test-tensorflow {} with int32 tensor',
160 // upperBound and lowerBound use SearchSorted, which is unsupported
161 'upperBound',
162 'lowerBound',
163];
164if (process.platform === 'win32') {
165 // Ignore tensorboard on windows because tmp folder cleanup used in tests
166 // fails with tmp folder cleanup:
167 // https://github.com/tensorflow/tfjs/issues/1692
168 IGNORE_LIST.push('tensorboard');
169 IGNORE_LIST.push('tensorBoard');
170 // Windows has two failing tests:
171 // https://github.com/tensorflow/tfjs/issues/598
172 IGNORE_LIST.push('clip test-tensorflow {} propagates NaNs');
173 IGNORE_LIST.push('maxPool test-tensorflow {} [x=[3,3,1] f=[2,2] s=1 ignores NaNs');
174}
175var runner = new jasmineCtor();
176runner.loadConfig({ spec_files: ['src/**/*_test.ts'], random: false });
177// Also import tests from core.
178// tslint:disable-next-line: no-imports-from-dist
179require("@tensorflow/tfjs-core/dist/tests");
180if (process.env.JASMINE_SEED) {
181 runner.seed(process.env.JASMINE_SEED);
182}
183var env = jasmine.getEnv();
184var grepRegex = new RegExp(yargs_1.argv.grep);
185// Filter method that returns boolean, if a given test should return.
186env.specFilter = function (spec) {
187 // Filter based on the grep flag.
188 if (!grepRegex.test(spec.getFullName())) {
189 return false;
190 }
191 // Return false (skip the test) if the test is in the ignore list.
192 for (var i = 0; i < IGNORE_LIST.length; ++i) {
193 if (spec.getFullName().indexOf(IGNORE_LIST[i]) > -1) {
194 return false;
195 }
196 }
197 // Otherwise run the test.
198 return true;
199};
200// TODO(kreeger): Consider moving to C-code.
201console.log("Running tests against TensorFlow: " + tf.backend().binding.TF_Version);
202runner.execute();