UNPKG

5.25 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");
21var tf = require("@tensorflow/tfjs");
22// tslint:disable-next-line:no-imports-from-dist
23var jasmine_util = require("@tensorflow/tfjs-core/dist/jasmine_util");
24var yargs_1 = require("yargs");
25Error.stackTraceLimit = Infinity;
26// tslint:disable-next-line:no-require-imports
27var jasmineCtor = require('jasmine');
28// tslint:disable-next-line:no-require-imports
29process.on('unhandledRejection', function (e) {
30 throw e;
31});
32jasmine_util.setTestEnvs([{
33 name: 'test-tensorflow',
34 backendName: 'tensorflow',
35 flags: {},
36 isDataSync: true
37 }]);
38var IGNORE_LIST = [
39 // Always ignore version tests:
40 'version version',
41 'unreliable is true due to both auto gc and string tensors',
42 'unreliable is true due to auto gc',
43 // See https://github.com/tensorflow/tfjs/issues/161
44 'depthwiseConv2D',
45 'separableConv2d',
46 'complex64 memory',
47 // See https://github.com/tensorflow/tfjs-core/pull/1270
48 'depthToSpace test-tensorflow {} throws when blocksize < 2',
49 // tslint:disable-next-line:max-line-length
50 'depthToSpace test-tensorflow {} throws when CPU backend used with data format NCHW',
51 // See https://github.com/tensorflow/tfjs/issues/806
52 'scatterND test-tensorflow {} should work for 2d',
53 'scatterND test-tensorflow {} should work for simple 1d',
54 'scatterND test-tensorflow {} should work for multiple 1d',
55 'scatterND test-tensorflow {} should sum the duplicated indices',
56 'scatterND test-tensorflow {} should work for tensorLike input',
57 // https://github.com/tensorflow/tfjs/issues/1077
58 'maxPool test-tensorflow {} x=[2,2,3] f=[1,1] s=2 p=1 dimRoundingMode=floor',
59 'avgPool test-tensorflow {} x=[2,2,3] f=[1,1] s=2 p=1 dimRoundingMode=floor',
60 // tslint:disable-next-line:max-line-length
61 'avgPool3d test-tensorflow {} x=[1,2,2,2,1] f=[2,2,2] s=1 p=1 roundingMode=floor',
62 // tslint:disable-next-line:max-line-length
63 'maxPool3d test-tensorflow {} x=[1,2,2,2,1] f=[2,2,2] s=1 p=1 roundingMode=floor',
64 // libtensorflow doesn't support 6D ArgMax yet.
65 'argmax test-tensorflow {} 6D, axis=0', 'diag test-tensorflow {} complex',
66 'diag test-tensorflow {} bool',
67 // See https://github.com/tensorflow/tfjs/issues/1891
68 'conv2d test-tensorflow {} x=[2,1,2,2] f=[1,1,1,1] s=1 d=1 p=0 NCHW',
69 'conv2d test-tensorflow {} x=[1,2,2] f=[2,2,1,1] s=1 d=1 p=explicit NCHW',
70 'conv2d test-tensorflow {} x=[1,2,2] f=[2,2,1,1] s=1 d=1 p=same NCHW',
71 'conv2d test-tensorflow {} x=[2,2,2] f=[2,2,2,1] s=1 d=1 p=same NCHW',
72 'conv2d test-tensorflow {} x=[2,1,2,2] f=[2,2,1,1] s=1 d=1 p=same NCHW',
73 'conv2d test-tensorflow {} gradient x=[1,1,3,3] f=[2,2,1,1] s=1 p=0 NCHW',
74 'conv2d test-tensorflow {} gradient x=[2,1,3,3] f=[2,2,1,1] s=1 p=0 NCHW',
75 'maxPoolWithArgmax', 'rotate', 'flipLeftRight'
76];
77if (process.platform === 'win32') {
78 // Ignore tensorboard on windows because tmp folder cleanup used in tests
79 // fails with tmp folder cleanup:
80 // https://github.com/tensorflow/tfjs/issues/1692
81 IGNORE_LIST.push('tensorboard');
82 IGNORE_LIST.push('tensorBoard');
83 // Windows has two failing tests:
84 // https://github.com/tensorflow/tfjs/issues/598
85 IGNORE_LIST.push('clip test-tensorflow {} propagates NaNs');
86 IGNORE_LIST.push('maxPool test-tensorflow {} [x=[3,3,1] f=[2,2] s=1 ignores NaNs');
87}
88var runner = new jasmineCtor();
89runner.loadConfig({ spec_files: ['src/**/*_test.ts'], random: false });
90// Also import tests from core.
91// tslint:disable-next-line: no-imports-from-dist
92require("@tensorflow/tfjs-core/dist/tests");
93if (process.env.JASMINE_SEED) {
94 runner.seed(process.env.JASMINE_SEED);
95}
96var env = jasmine.getEnv();
97var grepRegex = new RegExp(yargs_1.argv.grep);
98// Filter method that returns boolean, if a given test should return.
99env.specFilter = function (spec) {
100 // Filter based on the grep flag.
101 if (!grepRegex.test(spec.getFullName())) {
102 return false;
103 }
104 // Return false (skip the test) if the test is in the ignore list.
105 for (var i = 0; i < IGNORE_LIST.length; ++i) {
106 if (spec.getFullName().indexOf(IGNORE_LIST[i]) > -1) {
107 return false;
108 }
109 }
110 // Otherwise run the test.
111 return true;
112};
113// TODO(kreeger): Consider moving to C-code.
114console.log("Running tests against TensorFlow: " + tf.backend().binding.TF_Version);
115runner.execute();