Skip to content

Commit

Permalink
Remove all unused variables and enable lint rule (tensorflow#26)
Browse files Browse the repository at this point in the history
* remove all unused variables and enable lint rule

* revert benchmarks deletion

* further reduce unused vars using tsconfig settings
  • Loading branch information
dsmilkov authored and Nikhil Thorat committed Aug 11, 2017
1 parent 450ec20 commit f213377
Show file tree
Hide file tree
Showing 92 changed files with 84 additions and 194 deletions.
1 change: 0 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"dist/": true,
"**/bundle.js": true
},
"tslint.configFile": "tslint.json",
"tslint.enable": true,
"tslint.run": "onType",
"editor.tabSize": 2,
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"command": "npm",
"taskName": "lint",
"type": "shell",
"suppressTaskName": true,
"args": [ "run", "lint"],
"problemMatcher": {
"base": "$tslint5",
"owner": "tslint-type-checked",
"fileLocation": "absolute"
}
}
Expand Down
3 changes: 1 addition & 2 deletions demos/benchmarks/conv_transpose_gpu_benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ export const BENCHMARK_TEST: BenchmarkTest = (size: number) => {
gpgpu, program, xTex, wTex, null, resultTex, resultTexRC);
}

const y = gpgpu.downloadMatrixFromTexture(
resultTex, resultTexRC[0], resultTexRC[1]);
gpgpu.downloadMatrixFromTexture(resultTex, resultTexRC[0], resultTexRC[1]);

const end = performance.now();

Expand Down
1 change: 0 additions & 1 deletion demos/benchmarks/logsumexp_gpu_benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ limitations under the License.

import {GPGPUContext} from '../../src/math/webgl/gpgpu_context';
import {LogSumExpProgram} from '../../src/math/webgl/logsumexp_gpu';
import * as test_util from '../../src/test_util';
import * as gpgpu_math from '../../src/math/webgl/gpgpu_math';
import {Scalar, Array2D, initializeGPU} from '../../src/math/ndarray';
import {TextureManager} from '../../src/math/webgl/texture_manager';
Expand Down
2 changes: 0 additions & 2 deletions demos/benchmarks/math-benchmark-run-groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ import * as conv_gpu_benchmark from './conv_gpu_benchmark';
import * as conv_transpose_gpu_benchmark from './conv_transpose_gpu_benchmark';
import * as logsumexp_cpu_benchmark from './logsumexp_cpu_benchmark';
import * as logsumexp_gpu_benchmark from './logsumexp_gpu_benchmark';
import * as max_pool_backprop_gpu_benchmark from './max_pool_backprop_gpu_benchmark';
import * as max_pool_gpu_benchmark from './max_pool_gpu_benchmark';
import * as mulmat_cpu_benchmark from './mulmat_cpu_benchmark';
import * as mulmat_gpu_benchmark from './mulmat_gpu_benchmark';
import * as tex_util_benchmark from './tex_util_benchmark';

export const BENCHMARK_RUN_GROUPS: BenchmarkRunGroup[] = [
{
Expand Down
3 changes: 1 addition & 2 deletions demos/benchmarks/math-benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@ limitations under the License.
import '../demo-header';
import '../demo-footer';

// tslint:disable-next-line:no-unused-variable
import {PolymerElement, PolymerHTMLElement} from '../polymer-spec';
import {BenchmarkRunGroup} from './benchmark';

import {BENCHMARK_RUN_GROUPS} from './math-benchmark-run-groups';

// tslint:disable-next-line:variable-name
export let MathBenchmarkPolymer = PolymerElement(
export let MathBenchmarkPolymer: new () => PolymerHTMLElement = PolymerElement(
{is: 'math-benchmark', properties: {benchmarkRunGroupNames: Array}});

export class MathBenchmark extends MathBenchmarkPolymer {
Expand Down
6 changes: 2 additions & 4 deletions demos/benchmarks/mulmat_gpu_benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export const BENCHMARK_TEST: BenchmarkTest = (size: number) => {
for (let i = 0; i < OP_RUNS; i++) {
gpgpu_math.runProgram(binary);
}

const actual = gpgpu.downloadMatrixFromTexture(resultTexture, size, size);
gpgpu.downloadMatrixFromTexture(resultTexture, size, size);
const avgTime = (performance.now() - start) / OP_RUNS;

gpgpu.deleteMatrixTexture(aTexture);
Expand Down Expand Up @@ -83,8 +82,7 @@ export const BENCHMARK_TEST_PACKED: BenchmarkTest = (size: number) => {
gpgpu, program, aTexture, bTexture, resultTexture, [size, size]);
}

const actual =
gpgpu.downloadMatrixFromPackedTexture(resultTexture, size, size);
gpgpu.downloadMatrixFromPackedTexture(resultTexture, size, size);
const avgTime = (performance.now() - start) / OP_RUNS;

gpgpu.deleteMatrixTexture(aTexture);
Expand Down
1 change: 0 additions & 1 deletion demos/benchmarks/tex_util_benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import * as gpgpu_util from '../../src/math/webgl/gpgpu_util';
import * as tex_util from '../../src/math/webgl/tex_util';
import * as webgl_util from '../../src/math/webgl/webgl_util';
import * as test_util from '../../src/test_util';
Expand Down
7 changes: 4 additions & 3 deletions demos/homepage/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,18 @@ import {NDArrayMathGPU} from '../deeplearnjs';
import {ActivationFunction, ColorMode, CPPN} from '../nn-art/cppn';

function isSafari() {
const ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari') != -1) {
const ua = navigator.userAgent.toLowerCase();
if (ua.indexOf('safari') !== -1) {
if (ua.indexOf('chrome') > -1) {
return false;
} else {
return true;
}
}
return false;
}
function isMobile() {
// tslint:disable-next-line:no-any
const a = navigator.userAgent||navigator.vendor||(window as any).opera;
return /(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i.test(a)||/1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0,4));
}
Expand Down Expand Up @@ -56,7 +58,6 @@ if (enableCPPN) {
}

function startCPPN() {
const MAX_Z_SCALE = 400;
const DEFAULT_Z_SCALE = 1;
const NUM_NEURONS = 30;
const DEFAULT_NUM_LAYERS = 2;
Expand Down
9 changes: 2 additions & 7 deletions demos/imagenet/imagenet-demo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ limitations under the License.

import '../demo-header';
import '../demo-footer';
import {Array3D, gpgpu_util, GPGPUContext, NDArray, NDArrayMathCPU, NDArrayMathGPU} from '../deeplearnjs';
import * as imagenet_classes from '../models/imagenet_classes';
import {gpgpu_util, GPGPUContext, NDArrayMathCPU, NDArrayMathGPU} from '../deeplearnjs';
import * as imagenet_util from '../models/imagenet_util';
import {SqueezeNet} from '../models/squeezenet';
// tslint:disable-next-line:no-unused-variable
import {PolymerElement, PolymerHTMLElement} from '../polymer-spec';

// tslint:disable-next-line:variable-name
export const ImagenetDemoPolymer = PolymerElement({
export const ImagenetDemoPolymer: new () => PolymerHTMLElement = PolymerElement({
is: 'imagenet-demo',
properties: {
layerNames: Array,
Expand All @@ -39,14 +37,11 @@ export const ImagenetDemoPolymer = PolymerElement({
* http://localhost:5432
*/

const NUM_CLASSES = 1000;
const IMAGE_SIZE = 227;
const TOP_K_CLASSES = 5;

const INPUT_NAMES = ['cat', 'dog1', 'dog2', 'beerbottle', 'piano', 'saxophone'];
export class ImagenetDemo extends ImagenetDemoPolymer {
private variables: {[varName: string]: NDArray};

private math: NDArrayMathGPU;
private mathCPU: NDArrayMathCPU;
private gl: WebGLRenderingContext;
Expand Down
11 changes: 3 additions & 8 deletions demos/mnist/mnist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,14 @@ reader.getAllVariables().then(vars => {
xhr.onload = () => {
const data = JSON.parse(xhr.responseText) as SampleData;
const math = new NDArrayMathGPU();
const evalMethod = buildModelMathAPI(math, data, vars);
const [input, probs] = buildModelLayersAPI(data, vars);
const [input2, probs2] = buildModelGraphAPI(data, vars);
const sess = new Session(input.node.graph, math);

math.scope(() => {
let numCorrect = 0;
for (let i = 0; i < data.images.length; i++) {
const inputData = Array1D.new(data.images[i]);
const probsVal = sess.eval(probs, [{tensor: input, data: inputData}]);
const probsVal2 =
sess.eval(probs2, [{tensor: input2, data: inputData}]);
const probsVal3 = evalMethod(inputData);
if (data.labels[i] === probsVal.get()) {
numCorrect++;
}
Expand All @@ -49,7 +44,7 @@ reader.getAllVariables().then(vars => {
xhr.send();
});

interface SampleData {
export interface SampleData {
images: number[][];
labels: number[];
}
Expand All @@ -61,7 +56,7 @@ interface SampleData {
* math.scope() so that NDArrays created by intermediate math commands are
* automatically cleaned up.
*/
function buildModelMathAPI(
export function buildModelMathAPI(
math: NDArrayMath, data: SampleData,
vars: {[varName: string]: NDArray}): (x: Array1D) => Scalar {
const hidden1W = vars['hidden1/weights'] as Array2D;
Expand Down Expand Up @@ -90,7 +85,7 @@ function buildModelMathAPI(
* Users do not need to worry about GPU-related memory leaks, other than their
* input data.
*/
function buildModelGraphAPI(
export function buildModelGraphAPI(
data: SampleData, vars: {[varName: string]: NDArray}): Tensor[] {
const g = new Graph();
// TODO: Support batching.
Expand Down
1 change: 0 additions & 1 deletion demos/model-builder/layer_builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@ export class Convolution2DLayerBuilder implements LayerBuilder {
addLayer(
g: Graph, network: Tensor, inputShape: number[], index: number,
weights: LayerWeightsDict|null): Tensor {
const inputShape3d = inputShape as [number, number, number];
const wShape: [number, number, number, number] =
[this.fieldSize, this.fieldSize, inputShape[2], this.outputDepth];
let w: Array4D;
Expand Down
6 changes: 3 additions & 3 deletions demos/model-builder/model-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

// tslint:disable-next-line:no-unused-variable
import '../ndarray-image-visualizer';
import '../ndarray-logits-visualizer';
import './model-layer';
import '../demo-header';
import '../demo-footer';

import {PolymerElement, PolymerHTMLElement} from '../polymer-spec';

import {Array1D, Array3D, DataStats, FeedEntry, Graph, GraphRunner, GraphRunnerEventObserver, InCPUMemoryShuffledInputProviderBuilder, InMemoryDataset, MetricReduction, NDArray, NDArrayMath, NDArrayMathCPU, NDArrayMathGPU, Optimizer, Scalar, Session, SGDOptimizer, Tensor, util} from '../deeplearnjs';
import {NDArrayImageVisualizer} from '../ndarray-image-visualizer';
import {NDArrayLogitsVisualizer} from '../ndarray-logits-visualizer';
import {PolymerElement, PolymerHTMLElement} from '../polymer-spec';
import * as xhr_dataset from '../xhr-dataset';
import {XhrDataset, XhrDatasetConfig} from '../xhr-dataset';

Expand Down Expand Up @@ -59,7 +59,7 @@ const IMAGE_DATA_INDEX = 0;
const LABEL_DATA_INDEX = 1;

// tslint:disable-next-line:variable-name
export let ModelBuilderPolymer = PolymerElement({
export let ModelBuilderPolymer: new () => PolymerHTMLElement = PolymerElement({
is: 'model-builder',
properties: {
inputShapeDisplay: String,
Expand Down
3 changes: 1 addition & 2 deletions demos/model-builder/model-layer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ limitations under the License.
==============================================================================*/

import {Graph, Tensor} from '../deeplearnjs';
// tslint:disable-next-line:no-unused-variable
import {PolymerElement, PolymerHTMLElement} from '../polymer-spec';

import * as layer_builder from './layer_builder';
Expand All @@ -23,7 +22,7 @@ import {ModelBuilder} from './model-builder';
import * as model_builder_util from './model_builder_util';

// tslint:disable-next-line:variable-name
export let ModelLayerPolymer = PolymerElement({
export let ModelLayerPolymer: new () => PolymerHTMLElement = PolymerElement({
is: 'model-layer',
properties: {
layerName: String,
Expand Down
1 change: 0 additions & 1 deletion demos/models/squeezenet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import * as imagenet_classes from './imagenet_classes';
import * as imagenet_util from './imagenet_util';

const IMAGE_SIZE = 227;
const NUM_CLASSES = 1000;
const GOOGLE_CLOUD_STORAGE_DIR =
'https://storage.googleapis.com/learnjs-data/checkpoint_zoo/';

Expand Down
4 changes: 1 addition & 3 deletions demos/ndarray-image-visualizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

// tslint:disable-next-line:no-unused-variable
import {Array3D} from '../src/math/ndarray';

import {PolymerElement, PolymerHTMLElement} from './polymer-spec';

// tslint:disable-next-line
export let NDArrayImageVisualizerPolymer =
export let NDArrayImageVisualizerPolymer: new () => PolymerHTMLElement =
PolymerElement({is: 'ndarray-image-visualizer', properties: {}});

export class NDArrayImageVisualizer extends NDArrayImageVisualizerPolymer {
Expand Down
4 changes: 1 addition & 3 deletions demos/ndarray-logits-visualizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

// tslint:disable-next-line:no-unused-variable
import {NDArrayMathCPU} from '../src/math/math_cpu';
import {Array1D} from '../src/math/ndarray';

import {PolymerElement, PolymerHTMLElement} from './polymer-spec';

const TOP_K = 3;

// tslint:disable-next-line
export let NDArrayLogitsVisualizerPolymer =
export let NDArrayLogitsVisualizerPolymer: new () => PolymerHTMLElement =
PolymerElement({is: 'ndarray-logits-visualizer', properties: {}});

export class NDArrayLogitsVisualizer extends NDArrayLogitsVisualizerPolymer {
Expand Down
4 changes: 1 addition & 3 deletions demos/nn-art/cppn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import {Array1D, Array2D, gpgpu_util, GPGPUContext, NDArrayMathGPU, Scalar, webgl_util} from '../deeplearnjs';
import {Array2D, gpgpu_util, GPGPUContext, NDArrayMathGPU, webgl_util} from '../deeplearnjs';

import * as nn_art_util from './nn_art_util';

Expand Down Expand Up @@ -62,8 +62,6 @@ export class CPPN {

private colorModeNames: ColorMode[] =
['rgb', 'rgba', 'hsv', 'hsva', 'yuv', 'yuva', 'bw'];
private activationFunctionNames: ActivationFunction[] =
['tanh', 'sin', 'relu', 'step'];

private selectedColorModeName: ColorMode;
private selectedActivationFunctionName: ActivationFunction;
Expand Down
14 changes: 3 additions & 11 deletions demos/nn-art/nn-art.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,18 @@ limitations under the License.
==============================================================================*/
import '../demo-header';
import '../demo-footer';

import {Array1D, Array2D, gpgpu_util, GPGPUContext, NDArrayMathGPU, Scalar, webgl_util} from '../deeplearnjs';
// tslint:disable-next-line:no-unused-variable
import {PolymerElement, PolymerHTMLElement} from '../polymer-spec';

import {ActivationFunction, ColorMode, CPPN} from './cppn';
import * as nn_art_util from './nn_art_util';

const CANVAS_UPSCALE_FACTOR = 3;

const NUM_IMAGE_SPACE_VARIABLES = 3; // x, y, r
const NUM_LATENT_VARIABLES = 2;

const MAX_NUM_LAYERS = 7;
const MAT_WIDTH = 30;
// Standard deviations for gaussian weight initialization.
const WEIGHTS_STDEV = .6;

// tslint:disable-next-line:variable-name
const NNArtPolymer = PolymerElement({is: 'nn-art', properties: {}});
const NNArtPolymer: new () => PolymerHTMLElement = PolymerElement({
is: 'nn-art', properties: {}
});

class NNArt extends NNArtPolymer {
private cppn: CPPN;
Expand Down
2 changes: 1 addition & 1 deletion demos/xhr-dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ limitations under the License.
==============================================================================*/

import {InMemoryDataset} from '../src/dataset';
import {Array1D, NDArray} from '../src/math/ndarray';
import {NDArray} from '../src/math/ndarray';
import * as util from '../src/util';

const PARSING_IMAGE_CANVAS_HEIGHT_PX = 1000;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"karma-typescript": "~3.0.4",
"polymer-bundler": "~3.0.1",
"tsify": "~3.0.1",
"tslint": "~5.5.0",
"tslint": "~5.6.0",
"typedoc": "~0.7.2",
"typescript": "2.3.4",
"watchify": "~3.9.0"
Expand Down
1 change: 0 additions & 1 deletion src/dataset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import {NDArrayMath} from './math/math';
import {NDArray} from './math/ndarray';
import * as util from './util';

Expand Down
1 change: 0 additions & 1 deletion src/graph_layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ limitations under the License.

import {Graph, Tensor} from './graph';
import {Initializer, VarianceScalingInitializer, ZerosInitializer} from './initializers';
import {NDArray} from './math/ndarray';

/**
* A layers sugar class around the graph that initializes variables
Expand Down
4 changes: 1 addition & 3 deletions src/graph_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@ See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

import * as dataset from './dataset';
import {Graph, Tensor} from './graph';
import {Tensor} from './graph';
import {InputProvider} from './input_provider';
import {NDArrayMath} from './math/math';
import {NDArrayMathCPU} from './math/math_cpu';
import {NDArray, Scalar} from './math/ndarray';
import {Optimizer} from './optimizer';
import {CostReduction, FeedEntry, Session} from './session';
Expand Down
Loading

0 comments on commit f213377

Please sign in to comment.