├── .gitignore ├── .npmignore ├── .travis.yml ├── LICENSE ├── README.md ├── build ├── commonjs │ ├── common │ │ ├── convLayer.d.ts │ │ ├── convLayer.js │ │ ├── convLayer.js.map │ │ ├── extractConvParamsFactory.d.ts │ │ ├── extractConvParamsFactory.js │ │ ├── extractConvParamsFactory.js.map │ │ ├── extractFCParamsFactory.d.ts │ │ ├── extractFCParamsFactory.js │ │ ├── extractFCParamsFactory.js.map │ │ ├── extractSeparableConvParamsFactory.d.ts │ │ ├── extractSeparableConvParamsFactory.js │ │ ├── extractSeparableConvParamsFactory.js.map │ │ ├── index.d.ts │ │ ├── index.js │ │ ├── index.js.map │ │ ├── types.d.ts │ │ ├── types.js │ │ └── types.js.map │ ├── index.d.ts │ ├── index.js │ ├── index.js.map │ └── tinyYolov2 │ │ ├── TinyYolov2.d.ts │ │ ├── TinyYolov2.js │ │ ├── TinyYolov2.js.map │ │ ├── TinyYolov2LossFunction.d.ts │ │ ├── TinyYolov2LossFunction.js │ │ ├── TinyYolov2LossFunction.js.map │ │ ├── TinyYolov2Options.d.ts │ │ ├── TinyYolov2Options.js │ │ ├── TinyYolov2Options.js.map │ │ ├── TinyYolov2Trainable.d.ts │ │ ├── TinyYolov2Trainable.js │ │ ├── TinyYolov2Trainable.js.map │ │ ├── config.d.ts │ │ ├── config.js │ │ ├── config.js.map │ │ ├── const.d.ts │ │ ├── const.js │ │ ├── const.js.map │ │ ├── convWithBatchNorm.d.ts │ │ ├── convWithBatchNorm.js │ │ ├── convWithBatchNorm.js.map │ │ ├── depthwiseSeparableConv.d.ts │ │ ├── depthwiseSeparableConv.js │ │ ├── depthwiseSeparableConv.js.map │ │ ├── extractParams.d.ts │ │ ├── extractParams.js │ │ ├── extractParams.js.map │ │ ├── extractParamsFromWeigthMap.d.ts │ │ ├── extractParamsFromWeigthMap.js │ │ ├── extractParamsFromWeigthMap.js.map │ │ ├── getDefaultBackwardOptions.d.ts │ │ ├── getDefaultBackwardOptions.js │ │ ├── getDefaultBackwardOptions.js.map │ │ ├── index.d.ts │ │ ├── index.js │ │ ├── index.js.map │ │ ├── leaky.d.ts │ │ ├── leaky.js │ │ ├── leaky.js.map │ │ ├── types.d.ts │ │ ├── types.js │ │ └── types.js.map └── es6 │ ├── common │ ├── convLayer.d.ts │ ├── convLayer.js │ ├── convLayer.js.map │ ├── extractConvParamsFactory.d.ts │ ├── extractConvParamsFactory.js │ ├── extractConvParamsFactory.js.map │ ├── extractFCParamsFactory.d.ts │ ├── extractFCParamsFactory.js │ ├── extractFCParamsFactory.js.map │ ├── extractSeparableConvParamsFactory.d.ts │ ├── extractSeparableConvParamsFactory.js │ ├── extractSeparableConvParamsFactory.js.map │ ├── index.d.ts │ ├── index.js │ ├── index.js.map │ ├── types.d.ts │ ├── types.js │ └── types.js.map │ ├── index.d.ts │ ├── index.js │ ├── index.js.map │ └── tinyYolov2 │ ├── TinyYolov2.d.ts │ ├── TinyYolov2.js │ ├── TinyYolov2.js.map │ ├── TinyYolov2LossFunction.d.ts │ ├── TinyYolov2LossFunction.js │ ├── TinyYolov2LossFunction.js.map │ ├── TinyYolov2Options.d.ts │ ├── TinyYolov2Options.js │ ├── TinyYolov2Options.js.map │ ├── TinyYolov2Trainable.d.ts │ ├── TinyYolov2Trainable.js │ ├── TinyYolov2Trainable.js.map │ ├── config.d.ts │ ├── config.js │ ├── config.js.map │ ├── const.d.ts │ ├── const.js │ ├── const.js.map │ ├── convWithBatchNorm.d.ts │ ├── convWithBatchNorm.js │ ├── convWithBatchNorm.js.map │ ├── depthwiseSeparableConv.d.ts │ ├── depthwiseSeparableConv.js │ ├── depthwiseSeparableConv.js.map │ ├── extractParams.d.ts │ ├── extractParams.js │ ├── extractParams.js.map │ ├── extractParamsFromWeigthMap.d.ts │ ├── extractParamsFromWeigthMap.js │ ├── extractParamsFromWeigthMap.js.map │ ├── getDefaultBackwardOptions.d.ts │ ├── getDefaultBackwardOptions.js │ ├── getDefaultBackwardOptions.js.map │ ├── index.d.ts │ ├── index.js │ ├── index.js.map │ ├── leaky.d.ts │ ├── leaky.js │ ├── leaky.js.map │ ├── types.d.ts │ ├── types.js │ └── types.js.map ├── dist ├── tiny-yolov2.js ├── tiny-yolov2.js.map └── tiny-yolov2.min.js ├── examples ├── package-lock.json ├── package.json ├── public │ ├── commons.js │ ├── github_link_icon.png │ ├── images │ │ ├── face_detection │ │ │ ├── 1.jpg │ │ │ ├── 2.jpg │ │ │ ├── 3.jpg │ │ │ ├── 4.jpg │ │ │ └── 5.jpg │ │ └── object_detection │ │ │ ├── 1.jpg │ │ │ ├── 2.jpg │ │ │ ├── 3.jpg │ │ │ ├── 4.jpg │ │ │ ├── 5.jpg │ │ │ └── 6.jpg │ ├── menu_icon.png │ └── styles.css ├── server.js └── views │ ├── cocoObjectDetection.html │ ├── faceDetection.html │ └── vocObjectDetection.html ├── karma.conf.js ├── models ├── coco_model-shard1 ├── coco_model-shard2 ├── coco_model-shard3 ├── coco_model-weights_manifest.json ├── coco_model_config.json ├── face_detection_model-shard1 ├── face_detection_model-weights_manifest.json ├── face_detection_model_config.json ├── voc_model-shard1 ├── voc_model-shard2 ├── voc_model-shard3 ├── voc_model-shard4 ├── voc_model-weights_manifest.json └── voc_model_config.json ├── package-lock.json ├── package.json ├── rollup.config.js ├── src ├── common │ ├── convLayer.ts │ ├── extractConvParamsFactory.ts │ ├── extractFCParamsFactory.ts │ ├── extractSeparableConvParamsFactory.ts │ ├── index.ts │ └── types.ts ├── index.ts └── tinyYolov2 │ ├── TinyYolov2.ts │ ├── TinyYolov2LossFunction.ts │ ├── TinyYolov2Options.ts │ ├── TinyYolov2Trainable.ts │ ├── config.ts │ ├── const.ts │ ├── convWithBatchNorm.ts │ ├── depthwiseSeparableConv.ts │ ├── extractParams.ts │ ├── extractParamsFromWeigthMap.ts │ ├── getDefaultBackwardOptions.ts │ ├── index.ts │ ├── leaky.ts │ └── types.ts ├── test ├── TinyYolov2LossFunction.test.ts └── utils.ts ├── train ├── face │ ├── initWeights.html │ ├── test.html │ ├── train.html │ ├── verify.html │ └── verify_debug.html ├── js │ ├── createLossReporter.js │ └── randomCrop.js ├── package-lock.json ├── package.json ├── serveFaceDetection.js ├── serveVoc.js └── voc │ ├── initWeights.html │ ├── trainVoc.html │ └── verifyVoc.html ├── tsconfig.es6.json ├── tsconfig.json └── tsconfig.test.json /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .rpt2_cache 3 | .env* 4 | tmp 5 | proto 6 | weights_uncompressed 7 | weights_unused 8 | _tfjs-image-recognition-base 9 | tfjs-image-recognition-base -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .rpt2_cache 3 | .env* 4 | 5 | tmp 6 | proto 7 | weights_uncompressed 8 | weights_unused 9 | _tfjs-image-recognition-base 10 | tfjs-image-recognition-base 11 | 12 | examples 13 | models 14 | train 15 | test 16 | tools 17 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: required 2 | language: node_js 3 | node_js: 4 | - "10" 5 | before_script: 6 | - npm install 7 | - npm run build 8 | - sudo chown root /opt/google/chrome/chrome-sandbox 9 | - sudo chmod 4755 /opt/google/chrome/chrome-sandbox 10 | - export CHROME_BIN=chromium-browser 11 | - export DISPLAY=:99.0 12 | - sh -e /etc/init.d/xvfb start 13 | script: 14 | - npm run test-travis -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Vincent Mühler 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /build/commonjs/common/convLayer.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { ConvParams } from './types'; 3 | export declare function convLayer(x: tf.Tensor4D, params: ConvParams, padding?: 'valid' | 'same', withRelu?: boolean): tf.Tensor4D; 4 | -------------------------------------------------------------------------------- /build/commonjs/common/convLayer.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tf = require("@tensorflow/tfjs-core"); 4 | function convLayer(x, params, padding, withRelu) { 5 | if (padding === void 0) { padding = 'same'; } 6 | if (withRelu === void 0) { withRelu = false; } 7 | return tf.tidy(function () { 8 | var out = tf.add(tf.conv2d(x, params.filters, [1, 1], padding), params.bias); 9 | return withRelu ? tf.relu(out) : out; 10 | }); 11 | } 12 | exports.convLayer = convLayer; 13 | //# sourceMappingURL=convLayer.js.map -------------------------------------------------------------------------------- /build/commonjs/common/convLayer.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"convLayer.js","sourceRoot":"","sources":["../../../src/common/convLayer.ts"],"names":[],"mappings":";;AAAA,0CAA4C;AAI5C,mBACE,CAAc,EACd,MAAkB,EAClB,OAAkC,EAClC,QAAyB;IADzB,wBAAA,EAAA,gBAAkC;IAClC,yBAAA,EAAA,gBAAyB;IAEzB,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAM,GAAG,GAAG,EAAE,CAAC,GAAG,CAChB,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,EAC7C,MAAM,CAAC,IAAI,CACG,CAAA;QAEhB,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;IACtC,CAAC,CAAC,CAAA;AACJ,CAAC;AAdD,8BAcC"} -------------------------------------------------------------------------------- /build/commonjs/common/extractConvParamsFactory.d.ts: -------------------------------------------------------------------------------- 1 | import { ExtractWeightsFunction, ParamMapping } from 'tfjs-image-recognition-base'; 2 | import { ConvParams } from './types'; 3 | export declare function extractConvParamsFactory(extractWeights: ExtractWeightsFunction, paramMappings: ParamMapping[]): (channelsIn: number, channelsOut: number, filterSize: number, mappedPrefix: string) => ConvParams; 4 | -------------------------------------------------------------------------------- /build/commonjs/common/extractConvParamsFactory.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tf = require("@tensorflow/tfjs-core"); 4 | function extractConvParamsFactory(extractWeights, paramMappings) { 5 | return function (channelsIn, channelsOut, filterSize, mappedPrefix) { 6 | var filters = tf.tensor4d(extractWeights(channelsIn * channelsOut * filterSize * filterSize), [filterSize, filterSize, channelsIn, channelsOut]); 7 | var bias = tf.tensor1d(extractWeights(channelsOut)); 8 | paramMappings.push({ paramPath: mappedPrefix + "/filters" }, { paramPath: mappedPrefix + "/bias" }); 9 | return { filters: filters, bias: bias }; 10 | }; 11 | } 12 | exports.extractConvParamsFactory = extractConvParamsFactory; 13 | //# sourceMappingURL=extractConvParamsFactory.js.map -------------------------------------------------------------------------------- /build/commonjs/common/extractConvParamsFactory.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extractConvParamsFactory.js","sourceRoot":"","sources":["../../../src/common/extractConvParamsFactory.ts"],"names":[],"mappings":";;AAAA,0CAA4C;AAK5C,kCACE,cAAsC,EACtC,aAA6B;IAG7B,OAAO,UACL,UAAkB,EAClB,WAAmB,EACnB,UAAkB,EAClB,YAAoB;QAGpB,IAAM,OAAO,GAAG,EAAE,CAAC,QAAQ,CACzB,cAAc,CAAC,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,CAAC,EAClE,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,CAAC,CAClD,CAAA;QACD,IAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,CAAA;QAErD,aAAa,CAAC,IAAI,CAChB,EAAE,SAAS,EAAK,YAAY,aAAU,EAAE,EACxC,EAAE,SAAS,EAAK,YAAY,UAAO,EAAE,CACtC,CAAA;QAED,OAAO,EAAE,OAAO,SAAA,EAAE,IAAI,MAAA,EAAE,CAAA;IAC1B,CAAC,CAAA;AAEH,CAAC;AA1BD,4DA0BC"} -------------------------------------------------------------------------------- /build/commonjs/common/extractFCParamsFactory.d.ts: -------------------------------------------------------------------------------- 1 | import { ExtractWeightsFunction, ParamMapping } from 'tfjs-image-recognition-base'; 2 | import { FCParams } from './types'; 3 | export declare function extractFCParamsFactory(extractWeights: ExtractWeightsFunction, paramMappings: ParamMapping[]): (channelsIn: number, channelsOut: number, mappedPrefix: string) => FCParams; 4 | -------------------------------------------------------------------------------- /build/commonjs/common/extractFCParamsFactory.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tf = require("@tensorflow/tfjs-core"); 4 | function extractFCParamsFactory(extractWeights, paramMappings) { 5 | return function (channelsIn, channelsOut, mappedPrefix) { 6 | var fc_weights = tf.tensor2d(extractWeights(channelsIn * channelsOut), [channelsIn, channelsOut]); 7 | var fc_bias = tf.tensor1d(extractWeights(channelsOut)); 8 | paramMappings.push({ paramPath: mappedPrefix + "/weights" }, { paramPath: mappedPrefix + "/bias" }); 9 | return { 10 | weights: fc_weights, 11 | bias: fc_bias 12 | }; 13 | }; 14 | } 15 | exports.extractFCParamsFactory = extractFCParamsFactory; 16 | //# sourceMappingURL=extractFCParamsFactory.js.map -------------------------------------------------------------------------------- /build/commonjs/common/extractFCParamsFactory.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extractFCParamsFactory.js","sourceRoot":"","sources":["../../../src/common/extractFCParamsFactory.ts"],"names":[],"mappings":";;AAAA,0CAA4C;AAM5C,gCACE,cAAsC,EACtC,aAA6B;IAG7B,OAAO,UACL,UAAkB,EAClB,WAAmB,EACnB,YAAoB;QAGpB,IAAM,UAAU,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,UAAU,GAAG,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAA;QACnG,IAAM,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,CAAA;QAExD,aAAa,CAAC,IAAI,CAChB,EAAE,SAAS,EAAK,YAAY,aAAU,EAAE,EACxC,EAAE,SAAS,EAAK,YAAY,UAAO,EAAE,CACtC,CAAA;QAED,OAAO;YACL,OAAO,EAAE,UAAU;YACnB,IAAI,EAAE,OAAO;SACd,CAAA;IACH,CAAC,CAAA;AAEH,CAAC;AAzBD,wDAyBC"} -------------------------------------------------------------------------------- /build/commonjs/common/extractSeparableConvParamsFactory.d.ts: -------------------------------------------------------------------------------- 1 | import { ExtractWeightsFunction, ParamMapping } from 'tfjs-image-recognition-base'; 2 | import { SeparableConvParams } from './types'; 3 | export declare function extractSeparableConvParamsFactory(extractWeights: ExtractWeightsFunction, paramMappings: ParamMapping[]): (channelsIn: number, channelsOut: number, mappedPrefix: string) => SeparableConvParams; 4 | export declare function loadSeparableConvParamsFactory(extractWeightEntry: (originalPath: string, paramRank: number) => T): (prefix: string) => SeparableConvParams; 5 | -------------------------------------------------------------------------------- /build/commonjs/common/extractSeparableConvParamsFactory.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tf = require("@tensorflow/tfjs-core"); 4 | var types_1 = require("./types"); 5 | function extractSeparableConvParamsFactory(extractWeights, paramMappings) { 6 | return function (channelsIn, channelsOut, mappedPrefix) { 7 | var depthwise_filter = tf.tensor4d(extractWeights(3 * 3 * channelsIn), [3, 3, channelsIn, 1]); 8 | var pointwise_filter = tf.tensor4d(extractWeights(channelsIn * channelsOut), [1, 1, channelsIn, channelsOut]); 9 | var bias = tf.tensor1d(extractWeights(channelsOut)); 10 | paramMappings.push({ paramPath: mappedPrefix + "/depthwise_filter" }, { paramPath: mappedPrefix + "/pointwise_filter" }, { paramPath: mappedPrefix + "/bias" }); 11 | return new types_1.SeparableConvParams(depthwise_filter, pointwise_filter, bias); 12 | }; 13 | } 14 | exports.extractSeparableConvParamsFactory = extractSeparableConvParamsFactory; 15 | function loadSeparableConvParamsFactory(extractWeightEntry) { 16 | return function (prefix) { 17 | var depthwise_filter = extractWeightEntry(prefix + "/depthwise_filter", 4); 18 | var pointwise_filter = extractWeightEntry(prefix + "/pointwise_filter", 4); 19 | var bias = extractWeightEntry(prefix + "/bias", 1); 20 | return new types_1.SeparableConvParams(depthwise_filter, pointwise_filter, bias); 21 | }; 22 | } 23 | exports.loadSeparableConvParamsFactory = loadSeparableConvParamsFactory; 24 | //# sourceMappingURL=extractSeparableConvParamsFactory.js.map -------------------------------------------------------------------------------- /build/commonjs/common/extractSeparableConvParamsFactory.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extractSeparableConvParamsFactory.js","sourceRoot":"","sources":["../../../src/common/extractSeparableConvParamsFactory.ts"],"names":[],"mappings":";;AAAA,0CAA4C;AAG5C,iCAA8C;AAE9C,2CACE,cAAsC,EACtC,aAA6B;IAG7B,OAAO,UAAS,UAAkB,EAAE,WAAmB,EAAE,YAAoB;QAC3E,IAAM,gBAAgB,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAA;QAC/F,IAAM,gBAAgB,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,UAAU,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAA;QAC/G,IAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,CAAA;QAErD,aAAa,CAAC,IAAI,CAChB,EAAE,SAAS,EAAK,YAAY,sBAAmB,EAAE,EACjD,EAAE,SAAS,EAAK,YAAY,sBAAmB,EAAE,EACjD,EAAE,SAAS,EAAK,YAAY,UAAO,EAAE,CACtC,CAAA;QAED,OAAO,IAAI,2BAAmB,CAC5B,gBAAgB,EAChB,gBAAgB,EAChB,IAAI,CACL,CAAA;IACH,CAAC,CAAA;AAEH,CAAC;AAvBD,8EAuBC;AAED,wCACE,kBAAqE;IAGrE,OAAO,UAAU,MAAc;QAC7B,IAAM,gBAAgB,GAAG,kBAAkB,CAAiB,MAAM,sBAAmB,EAAE,CAAC,CAAC,CAAA;QACzF,IAAM,gBAAgB,GAAG,kBAAkB,CAAiB,MAAM,sBAAmB,EAAE,CAAC,CAAC,CAAA;QACzF,IAAM,IAAI,GAAG,kBAAkB,CAAiB,MAAM,UAAO,EAAE,CAAC,CAAC,CAAA;QAEjE,OAAO,IAAI,2BAAmB,CAC5B,gBAAgB,EAChB,gBAAgB,EAChB,IAAI,CACL,CAAA;IACH,CAAC,CAAA;AAEH,CAAC;AAhBD,wEAgBC"} -------------------------------------------------------------------------------- /build/commonjs/common/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './convLayer'; 2 | export * from './extractConvParamsFactory'; 3 | export * from './extractFCParamsFactory'; 4 | export * from './extractSeparableConvParamsFactory'; 5 | export * from './types'; 6 | -------------------------------------------------------------------------------- /build/commonjs/common/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tslib_1 = require("tslib"); 4 | tslib_1.__exportStar(require("./convLayer"), exports); 5 | tslib_1.__exportStar(require("./extractConvParamsFactory"), exports); 6 | tslib_1.__exportStar(require("./extractFCParamsFactory"), exports); 7 | tslib_1.__exportStar(require("./extractSeparableConvParamsFactory"), exports); 8 | tslib_1.__exportStar(require("./types"), exports); 9 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /build/commonjs/common/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":";;;AAAA,sDAA4B;AAC5B,qEAA2C;AAC3C,mEAAyC;AACzC,8EAAoD;AACpD,kDAAwB"} -------------------------------------------------------------------------------- /build/commonjs/common/types.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | export declare type ConvParams = { 3 | filters: tf.Tensor4D; 4 | bias: tf.Tensor1D; 5 | }; 6 | export declare type FCParams = { 7 | weights: tf.Tensor2D; 8 | bias: tf.Tensor1D; 9 | }; 10 | export declare class SeparableConvParams { 11 | depthwise_filter: tf.Tensor4D; 12 | pointwise_filter: tf.Tensor4D; 13 | bias: tf.Tensor1D; 14 | constructor(depthwise_filter: tf.Tensor4D, pointwise_filter: tf.Tensor4D, bias: tf.Tensor1D); 15 | } 16 | -------------------------------------------------------------------------------- /build/commonjs/common/types.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var SeparableConvParams = /** @class */ (function () { 4 | function SeparableConvParams(depthwise_filter, pointwise_filter, bias) { 5 | this.depthwise_filter = depthwise_filter; 6 | this.pointwise_filter = pointwise_filter; 7 | this.bias = bias; 8 | } 9 | return SeparableConvParams; 10 | }()); 11 | exports.SeparableConvParams = SeparableConvParams; 12 | //# sourceMappingURL=types.js.map -------------------------------------------------------------------------------- /build/commonjs/common/types.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/common/types.ts"],"names":[],"mappings":";;AAYA;IACE,6BACS,gBAA6B,EAC7B,gBAA6B,EAC7B,IAAiB;QAFjB,qBAAgB,GAAhB,gBAAgB,CAAa;QAC7B,qBAAgB,GAAhB,gBAAgB,CAAa;QAC7B,SAAI,GAAJ,IAAI,CAAa;IACvB,CAAC;IACN,0BAAC;AAAD,CAAC,AAND,IAMC;AANY,kDAAmB"} -------------------------------------------------------------------------------- /build/commonjs/index.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | export * from 'tfjs-image-recognition-base'; 3 | export * from './common'; 4 | export * from './tinyYolov2'; 5 | export { tf }; 6 | -------------------------------------------------------------------------------- /build/commonjs/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tslib_1 = require("tslib"); 4 | var tf = require("@tensorflow/tfjs-core"); 5 | exports.tf = tf; 6 | tslib_1.__exportStar(require("tfjs-image-recognition-base"), exports); 7 | tslib_1.__exportStar(require("./common"), exports); 8 | tslib_1.__exportStar(require("./tinyYolov2"), exports); 9 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /build/commonjs/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,0CAA4C;AAMnC,gBAAE;AAJX,sEAA4C;AAC5C,mDAAyB;AACzB,uDAA6B"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/TinyYolov2.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { BoundingBox, Dimensions, NetInput, NeuralNetwork, ObjectDetection, TNetInput } from 'tfjs-image-recognition-base'; 3 | import { TinyYolov2Config } from './config'; 4 | import { ITinyYolov2Options } from './TinyYolov2Options'; 5 | import { DefaultTinyYolov2NetParams, MobilenetParams, TinyYolov2NetParams } from './types'; 6 | export declare class TinyYolov2 extends NeuralNetwork { 7 | private _config; 8 | constructor(config: TinyYolov2Config); 9 | readonly config: TinyYolov2Config; 10 | readonly withClassScores: boolean; 11 | readonly boxEncodingSize: number; 12 | runTinyYolov2(x: tf.Tensor4D, params: DefaultTinyYolov2NetParams): tf.Tensor4D; 13 | runMobilenet(x: tf.Tensor4D, params: MobilenetParams): tf.Tensor4D; 14 | forwardInput(input: NetInput, inputSize: number): tf.Tensor4D; 15 | forward(input: TNetInput, inputSize: number): Promise; 16 | detect(input: TNetInput, forwardParams?: ITinyYolov2Options): Promise; 17 | protected getDefaultModelName(): string; 18 | protected extractParamsFromWeigthMap(weightMap: tf.NamedTensorMap): { 19 | params: TinyYolov2NetParams; 20 | paramMappings: { 21 | originalPath?: string | undefined; 22 | paramPath: string; 23 | }[]; 24 | }; 25 | protected extractParams(weights: Float32Array): { 26 | params: TinyYolov2NetParams; 27 | paramMappings: { 28 | originalPath?: string | undefined; 29 | paramPath: string; 30 | }[]; 31 | }; 32 | protected extractBoxes(outputTensor: tf.Tensor4D, inputBlobDimensions: Dimensions, scoreThreshold?: number): { 33 | row: number; 34 | col: number; 35 | anchor: number; 36 | box: BoundingBox; 37 | score: number; 38 | classScore: number; 39 | label: number; 40 | }[]; 41 | private extractPredictedClass(classesTensor, pos); 42 | } 43 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/TinyYolov2LossFunction.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { Dimensions, IDimensions, Point } from 'tfjs-image-recognition-base'; 3 | import { TinyYolov2TrainableConfig } from './config'; 4 | import { GroundTruth, GroundTruthWithGridPosition } from './types'; 5 | export declare class TinyYolov2LossFunction { 6 | private _config; 7 | private _reshapedImgDims; 8 | private _outputTensor; 9 | private _groundTruth; 10 | private _predictedBoxes; 11 | noObjectLossMask: tf.Tensor4D; 12 | objectLossMask: tf.Tensor4D; 13 | coordBoxOffsetMask: tf.Tensor4D; 14 | coordBoxSizeMask: tf.Tensor4D; 15 | groundTruthClassScoresMask: tf.Tensor4D; 16 | constructor(outputTensor: tf.Tensor4D, groundTruth: GroundTruth[], predictedBoxes: GroundTruthWithGridPosition[], reshapedImgDims: IDimensions, config: TinyYolov2TrainableConfig); 17 | readonly config: TinyYolov2TrainableConfig; 18 | readonly reshapedImgDims: Dimensions; 19 | readonly outputTensor: tf.Tensor4D; 20 | readonly groundTruth: GroundTruthWithGridPosition[]; 21 | readonly predictedBoxes: GroundTruthWithGridPosition[]; 22 | readonly inputSize: number; 23 | readonly withClassScores: boolean; 24 | readonly boxEncodingSize: number; 25 | readonly anchors: Point[]; 26 | readonly numBoxes: number; 27 | readonly numCells: number; 28 | readonly gridCellEncodingSize: number; 29 | toOutputTensorShape(tensor: tf.Tensor): tf.Tensor; 30 | computeLoss(): { 31 | noObjectLoss: tf.Tensor; 32 | objectLoss: tf.Tensor; 33 | coordLoss: tf.Tensor; 34 | classLoss: tf.Tensor; 35 | totalLoss: tf.Tensor; 36 | }; 37 | computeNoObjectLoss(): tf.Tensor; 38 | computeObjectLoss(): tf.Tensor; 39 | computeClassLoss(): tf.Tensor; 40 | computeCoordLoss(): tf.Tensor; 41 | computeCoordBoxOffsetError(): tf.Tensor4D; 42 | computeCoordBoxSizeError(): tf.Tensor4D; 43 | private computeLossTerm(scale, mask, lossTensor); 44 | private squaredSumOverMask(mask, lossTensor); 45 | private validateGroundTruthBoxes(groundTruth); 46 | private assignGroundTruthToAnchors(groundTruth); 47 | private createGroundTruthMask(); 48 | private createCoordAndScoreMasks(); 49 | private createOneHotClassScoreMask(); 50 | private computeIous(); 51 | computeCoordBoxOffsets(): tf.Tensor; 52 | computeCoordBoxSizes(): tf.Tensor; 53 | } 54 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/TinyYolov2Options.d.ts: -------------------------------------------------------------------------------- 1 | export declare enum TinyYolov2SizeType { 2 | XS = 224, 3 | SM = 320, 4 | MD = 416, 5 | LG = 608, 6 | } 7 | export interface ITinyYolov2Options { 8 | inputSize?: number; 9 | scoreThreshold?: number; 10 | } 11 | export declare class TinyYolov2Options { 12 | protected _name: string; 13 | private _inputSize; 14 | private _scoreThreshold; 15 | constructor({inputSize, scoreThreshold}?: ITinyYolov2Options); 16 | readonly inputSize: number; 17 | readonly scoreThreshold: number; 18 | } 19 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/TinyYolov2Options.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var TinyYolov2SizeType; 4 | (function (TinyYolov2SizeType) { 5 | TinyYolov2SizeType[TinyYolov2SizeType["XS"] = 224] = "XS"; 6 | TinyYolov2SizeType[TinyYolov2SizeType["SM"] = 320] = "SM"; 7 | TinyYolov2SizeType[TinyYolov2SizeType["MD"] = 416] = "MD"; 8 | TinyYolov2SizeType[TinyYolov2SizeType["LG"] = 608] = "LG"; 9 | })(TinyYolov2SizeType = exports.TinyYolov2SizeType || (exports.TinyYolov2SizeType = {})); 10 | var TinyYolov2Options = /** @class */ (function () { 11 | function TinyYolov2Options(_a) { 12 | var _b = _a === void 0 ? {} : _a, inputSize = _b.inputSize, scoreThreshold = _b.scoreThreshold; 13 | this._name = 'TinyYolov2Options'; 14 | this._inputSize = inputSize || 416; 15 | this._scoreThreshold = scoreThreshold || 0.5; 16 | if (typeof this._inputSize !== 'number' || this._inputSize % 32 !== 0) { 17 | throw new Error(this._name + " - expected inputSize to be a number divisible by 32"); 18 | } 19 | if (typeof this._scoreThreshold !== 'number' || this._scoreThreshold <= 0 || this._scoreThreshold >= 1) { 20 | throw new Error(this._name + " - expected scoreThreshold to be a number between 0 and 1"); 21 | } 22 | } 23 | Object.defineProperty(TinyYolov2Options.prototype, "inputSize", { 24 | get: function () { return this._inputSize; }, 25 | enumerable: true, 26 | configurable: true 27 | }); 28 | Object.defineProperty(TinyYolov2Options.prototype, "scoreThreshold", { 29 | get: function () { return this._scoreThreshold; }, 30 | enumerable: true, 31 | configurable: true 32 | }); 33 | return TinyYolov2Options; 34 | }()); 35 | exports.TinyYolov2Options = TinyYolov2Options; 36 | //# sourceMappingURL=TinyYolov2Options.js.map -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/TinyYolov2Options.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"TinyYolov2Options.js","sourceRoot":"","sources":["../../../src/tinyYolov2/TinyYolov2Options.ts"],"names":[],"mappings":";;AAAA,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,yDAAQ,CAAA;IACR,yDAAQ,CAAA;IACR,yDAAQ,CAAA;IACR,yDAAQ,CAAA;AACV,CAAC,EALW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAK7B;AAOD;IAME,2BAAY,EAAsD;YAAtD,4BAAsD,EAApD,wBAAS,EAAE,kCAAc;QAL7B,UAAK,GAAW,mBAAmB,CAAA;QAM3C,IAAI,CAAC,UAAU,GAAG,SAAS,IAAI,GAAG,CAAA;QAClC,IAAI,CAAC,eAAe,GAAG,cAAc,IAAI,GAAG,CAAA;QAE5C,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,IAAI,IAAI,CAAC,UAAU,GAAG,EAAE,KAAK,CAAC,EAAE;YACrE,MAAM,IAAI,KAAK,CAAI,IAAI,CAAC,KAAK,yDAAsD,CAAC,CAAA;SACrF;QAED,IAAI,OAAO,IAAI,CAAC,eAAe,KAAK,QAAQ,IAAI,IAAI,CAAC,eAAe,IAAI,CAAC,IAAI,IAAI,CAAC,eAAe,IAAI,CAAC,EAAE;YACtG,MAAM,IAAI,KAAK,CAAI,IAAI,CAAC,KAAK,8DAA2D,CAAC,CAAA;SAC1F;IACH,CAAC;IAED,sBAAI,wCAAS;aAAb,cAA0B,OAAO,IAAI,CAAC,UAAU,CAAA,CAAC,CAAC;;;OAAA;IAClD,sBAAI,6CAAc;aAAlB,cAA+B,OAAO,IAAI,CAAC,eAAe,CAAA,CAAC,CAAC;;;OAAA;IAC9D,wBAAC;AAAD,CAAC,AArBD,IAqBC;AArBY,8CAAiB"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/TinyYolov2Trainable.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { Dimensions } from 'tfjs-image-recognition-base'; 3 | import { TinyYolov2TrainableConfig } from './config'; 4 | import { TinyYolov2 } from './TinyYolov2'; 5 | import { GroundTruth, TinyYolov2BackwardOptions } from './types'; 6 | export declare class TinyYolov2Trainable extends TinyYolov2 { 7 | private _trainableConfig; 8 | private _optimizer; 9 | constructor(trainableConfig: TinyYolov2TrainableConfig, optimizer: tf.Optimizer); 10 | readonly trainableConfig: TinyYolov2TrainableConfig; 11 | readonly optimizer: tf.Optimizer; 12 | backward(img: HTMLImageElement | HTMLCanvasElement, groundTruth: GroundTruth[], inputSize: number, options?: TinyYolov2BackwardOptions): Promise | null>; 13 | computeLoss(outputTensor: tf.Tensor4D, groundTruth: GroundTruth[], reshapedImgDims: Dimensions): { 14 | noObjectLoss: tf.Tensor; 15 | objectLoss: tf.Tensor; 16 | coordLoss: tf.Tensor; 17 | classLoss: tf.Tensor; 18 | totalLoss: tf.Tensor; 19 | }; 20 | filterGroundTruthBoxes(groundTruth: GroundTruth[], imgDims: Dimensions, minBoxSize: number): GroundTruth[]; 21 | load(weightsOrUrl: Float32Array | string | undefined): Promise; 22 | } 23 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/TinyYolov2Trainable.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"TinyYolov2Trainable.js","sourceRoot":"","sources":["../../../src/tinyYolov2/TinyYolov2Trainable.ts"],"names":[],"mappings":";;;AAAA,0CAA4C;AAC5C,2EAOqC;AAErC,mCAA0E;AAC1E,yEAAwE;AACxE,2CAA0C;AAC1C,mEAAkE;AAGlE;IAAyC,+CAAU;I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C,UAAC,EAAuB;gBAArB,QAAC,EAAE,QAAC,EAAE,gBAAK,EAAE,kBAAM;YAC9C,IAAM,GAAG,GAAG,CAAC,IAAI,kCAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;iBACxC,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;YAElD,IAAM,SAAS,GAAG,GAAG,CAAC,KAAK,GAAG,UAAU,IAAI,GAAG,CAAC,MAAM,GAAG,UAAU,CAAA;YACnE,OAAO,CAAC,SAAS,CAAA;QACnB,CAAC,CAAC,CAAA;IACJ,CAAC;IAEY,kCAAI,GAAjB,UAAkB,YAA+C;;;;4BAC/D,qBAAM,iBAAM,IAAI,YAAC,YAAY,CAAC,EAAA;;wBAA9B,SAA8B,CAAA;wBAC9B,IAAI,CAAC,QAAQ,EAAE,CAAA;;;;;KAChB;IACH,0BAAC;AAAD,CAAC,AA9GD,CAAyC,uBAAU,GA8GlD;AA9GY,kDAAmB"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/config.d.ts: -------------------------------------------------------------------------------- 1 | import { Point } from 'tfjs-image-recognition-base'; 2 | export declare type TinyYolov2Config = { 3 | withSeparableConvs: boolean; 4 | iouThreshold: number; 5 | anchors: Point[]; 6 | classes: string[]; 7 | meanRgb?: [number, number, number]; 8 | withClassScores?: boolean; 9 | filterSizes?: number[]; 10 | isFirstLayerConv2d?: boolean; 11 | }; 12 | export declare type TinyYolov2TrainableConfig = TinyYolov2Config & { 13 | noObjectScale: number; 14 | objectScale: number; 15 | coordScale: number; 16 | classScale: number; 17 | }; 18 | export declare function validateConfig(config: any): void; 19 | export declare function validateTrainConfig(config: any): TinyYolov2TrainableConfig; 20 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/config.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var isNumber = function (arg) { return typeof arg === 'number'; }; 4 | function validateConfig(config) { 5 | if (!config) { 6 | throw new Error("invalid config: " + config); 7 | } 8 | if (typeof config.withSeparableConvs !== 'boolean') { 9 | throw new Error("config.withSeparableConvs has to be a boolean, have: " + config.withSeparableConvs); 10 | } 11 | if (!isNumber(config.iouThreshold) || config.iouThreshold < 0 || config.iouThreshold > 1.0) { 12 | throw new Error("config.iouThreshold has to be a number between [0, 1], have: " + config.iouThreshold); 13 | } 14 | if (!Array.isArray(config.classes) 15 | || !config.classes.length 16 | || !config.classes.every(function (c) { return typeof c === 'string'; })) { 17 | throw new Error("config.classes has to be an array class names: string[], have: " + JSON.stringify(config.classes)); 18 | } 19 | if (!Array.isArray(config.anchors) 20 | || !config.anchors.length 21 | || !config.anchors.map(function (a) { return a || {}; }).every(function (a) { return isNumber(a.x) && isNumber(a.y); })) { 22 | throw new Error("config.anchors has to be an array of { x: number, y: number }, have: " + JSON.stringify(config.anchors)); 23 | } 24 | if (config.meanRgb && (!Array.isArray(config.meanRgb) 25 | || config.meanRgb.length !== 3 26 | || !config.meanRgb.every(isNumber))) { 27 | throw new Error("config.meanRgb has to be an array of shape [number, number, number], have: " + JSON.stringify(config.meanRgb)); 28 | } 29 | } 30 | exports.validateConfig = validateConfig; 31 | function validateTrainConfig(config) { 32 | if (![config.noObjectScale, config.objectScale, config.coordScale, config.classScale].every(isNumber)) { 33 | throw new Error("for training you have to specify noObjectScale, objectScale, coordScale, classScale parameters in your config.json file"); 34 | } 35 | return config; 36 | } 37 | exports.validateTrainConfig = validateTrainConfig; 38 | //# sourceMappingURL=config.js.map -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/config.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/tinyYolov2/config.ts"],"names":[],"mappings":";;AAqBA,IAAM,QAAQ,GAAG,UAAC,GAAQ,IAAK,OAAA,OAAO,GAAG,KAAK,QAAQ,EAAvB,CAAuB,CAAA;AAEtD,wBAA+B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AC,CAAA;KAC1H;IAED,IAAI,MAAM,CAAC,OAAO,IAAI,CACpB,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;WAC3B,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;WAC3B,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CACnC,EAAE;QAED,MAAM,IAAI,KAAK,CAAC,gFAA8E,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAG,CAAC,CAAA;KAChI;AACH,CAAC;AAvCD,wCAuCC;AAED,6BAAoC,MAAW;IAC7C,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;QACrG,MAAM,IAAI,KAAK,CAAC,yHAAyH,CAAC,CAAA;KAC3I;IAED,OAAO,MAAM,CAAA;AACf,CAAC;AAND,kDAMC"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/const.d.ts: -------------------------------------------------------------------------------- 1 | export declare const CELL_SIZE = 32; 2 | export declare const DEFAULT_FILTER_SIZES: number[]; 3 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/const.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | exports.CELL_SIZE = 32; 4 | exports.DEFAULT_FILTER_SIZES = [ 5 | 3, 16, 32, 64, 128, 256, 512, 1024, 1024 6 | ]; 7 | //# sourceMappingURL=const.js.map -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/const.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/tinyYolov2/const.ts"],"names":[],"mappings":";;AAAa,QAAA,SAAS,GAAG,EAAE,CAAA;AAEd,QAAA,oBAAoB,GAAG;IAClC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI;CACzC,CAAA"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/convWithBatchNorm.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { ConvWithBatchNorm } from './types'; 3 | export declare function convWithBatchNorm(x: tf.Tensor4D, params: ConvWithBatchNorm): tf.Tensor4D; 4 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/convWithBatchNorm.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tf = require("@tensorflow/tfjs-core"); 4 | var leaky_1 = require("./leaky"); 5 | function convWithBatchNorm(x, params) { 6 | return tf.tidy(function () { 7 | var out = tf.pad(x, [[0, 0], [1, 1], [1, 1], [0, 0]]); 8 | out = tf.conv2d(out, params.conv.filters, [1, 1], 'valid'); 9 | out = tf.sub(out, params.bn.sub); 10 | out = tf.mul(out, params.bn.truediv); 11 | out = tf.add(out, params.conv.bias); 12 | return leaky_1.leaky(out); 13 | }); 14 | } 15 | exports.convWithBatchNorm = convWithBatchNorm; 16 | //# sourceMappingURL=convWithBatchNorm.js.map -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/convWithBatchNorm.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"convWithBatchNorm.js","sourceRoot":"","sources":["../../../src/tinyYolov2/convWithBatchNorm.ts"],"names":[],"mappings":";;AAAA,0CAA4C;AAE5C,iCAAgC;AAGhC,2BAAkC,CAAc,EAAE,MAAyB;IACzE,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAI,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAgB,CAAA;QAEpE,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;QAC1D,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;QAChC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,CAAA;QACpC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEnC,OAAO,aAAK,CAAC,GAAG,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC;AAXD,8CAWC"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/depthwiseSeparableConv.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { SeparableConvParams } from '../common/types'; 3 | export declare function depthwiseSeparableConv(x: tf.Tensor4D, params: SeparableConvParams): tf.Tensor4D; 4 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/depthwiseSeparableConv.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tf = require("@tensorflow/tfjs-core"); 4 | var leaky_1 = require("./leaky"); 5 | function depthwiseSeparableConv(x, params) { 6 | return tf.tidy(function () { 7 | var out = tf.pad(x, [[0, 0], [1, 1], [1, 1], [0, 0]]); 8 | out = tf.separableConv2d(out, params.depthwise_filter, params.pointwise_filter, [1, 1], 'valid'); 9 | out = tf.add(out, params.bias); 10 | return leaky_1.leaky(out); 11 | }); 12 | } 13 | exports.depthwiseSeparableConv = depthwiseSeparableConv; 14 | //# sourceMappingURL=depthwiseSeparableConv.js.map -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/depthwiseSeparableConv.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"depthwiseSeparableConv.js","sourceRoot":"","sources":["../../../src/tinyYolov2/depthwiseSeparableConv.ts"],"names":[],"mappings":";;AAAA,0CAA4C;AAG5C,iCAAgC;AAEhC,gCAAuC,CAAc,EAAE,MAA2B;IAChF,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAI,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAgB,CAAA;QAEpE,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;QAChG,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAE9B,OAAO,aAAK,CAAC,GAAG,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC;AATD,wDASC"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/extractParams.d.ts: -------------------------------------------------------------------------------- 1 | import { ParamMapping } from 'tfjs-image-recognition-base'; 2 | import { TinyYolov2Config } from './config'; 3 | import { TinyYolov2NetParams } from './types'; 4 | export declare function extractParams(weights: Float32Array, config: TinyYolov2Config, boxEncodingSize: number, filterSizes: number[]): { 5 | params: TinyYolov2NetParams; 6 | paramMappings: ParamMapping[]; 7 | }; 8 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/extractParams.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tf = require("@tensorflow/tfjs-core"); 4 | var tfjs_image_recognition_base_1 = require("tfjs-image-recognition-base"); 5 | var common_1 = require("../common"); 6 | var extractSeparableConvParamsFactory_1 = require("../common/extractSeparableConvParamsFactory"); 7 | function extractorsFactory(extractWeights, paramMappings) { 8 | var extractConvParams = common_1.extractConvParamsFactory(extractWeights, paramMappings); 9 | function extractBatchNormParams(size, mappedPrefix) { 10 | var sub = tf.tensor1d(extractWeights(size)); 11 | var truediv = tf.tensor1d(extractWeights(size)); 12 | paramMappings.push({ paramPath: mappedPrefix + "/sub" }, { paramPath: mappedPrefix + "/truediv" }); 13 | return { sub: sub, truediv: truediv }; 14 | } 15 | function extractConvWithBatchNormParams(channelsIn, channelsOut, mappedPrefix) { 16 | var conv = extractConvParams(channelsIn, channelsOut, 3, mappedPrefix + "/conv"); 17 | var bn = extractBatchNormParams(channelsOut, mappedPrefix + "/bn"); 18 | return { conv: conv, bn: bn }; 19 | } 20 | var extractSeparableConvParams = extractSeparableConvParamsFactory_1.extractSeparableConvParamsFactory(extractWeights, paramMappings); 21 | return { 22 | extractConvParams: extractConvParams, 23 | extractConvWithBatchNormParams: extractConvWithBatchNormParams, 24 | extractSeparableConvParams: extractSeparableConvParams 25 | }; 26 | } 27 | function extractParams(weights, config, boxEncodingSize, filterSizes) { 28 | var _a = tfjs_image_recognition_base_1.extractWeightsFactory(weights), extractWeights = _a.extractWeights, getRemainingWeights = _a.getRemainingWeights; 29 | var paramMappings = []; 30 | var _b = extractorsFactory(extractWeights, paramMappings), extractConvParams = _b.extractConvParams, extractConvWithBatchNormParams = _b.extractConvWithBatchNormParams, extractSeparableConvParams = _b.extractSeparableConvParams; 31 | var params; 32 | if (config.withSeparableConvs) { 33 | var s0 = filterSizes[0], s1 = filterSizes[1], s2 = filterSizes[2], s3 = filterSizes[3], s4 = filterSizes[4], s5 = filterSizes[5], s6 = filterSizes[6], s7 = filterSizes[7], s8 = filterSizes[8]; 34 | var conv0 = config.isFirstLayerConv2d 35 | ? extractConvParams(s0, s1, 3, 'conv0') 36 | : extractSeparableConvParams(s0, s1, 'conv0'); 37 | var conv1 = extractSeparableConvParams(s1, s2, 'conv1'); 38 | var conv2 = extractSeparableConvParams(s2, s3, 'conv2'); 39 | var conv3 = extractSeparableConvParams(s3, s4, 'conv3'); 40 | var conv4 = extractSeparableConvParams(s4, s5, 'conv4'); 41 | var conv5 = extractSeparableConvParams(s5, s6, 'conv5'); 42 | var conv6 = s7 ? extractSeparableConvParams(s6, s7, 'conv6') : undefined; 43 | var conv7 = s8 ? extractSeparableConvParams(s7, s8, 'conv7') : undefined; 44 | var conv8 = extractConvParams(s8 || s7 || s6, 5 * boxEncodingSize, 1, 'conv8'); 45 | params = { conv0: conv0, conv1: conv1, conv2: conv2, conv3: conv3, conv4: conv4, conv5: conv5, conv6: conv6, conv7: conv7, conv8: conv8 }; 46 | } 47 | else { 48 | var s0 = filterSizes[0], s1 = filterSizes[1], s2 = filterSizes[2], s3 = filterSizes[3], s4 = filterSizes[4], s5 = filterSizes[5], s6 = filterSizes[6], s7 = filterSizes[7], s8 = filterSizes[8]; 49 | var conv0 = extractConvWithBatchNormParams(s0, s1, 'conv0'); 50 | var conv1 = extractConvWithBatchNormParams(s1, s2, 'conv1'); 51 | var conv2 = extractConvWithBatchNormParams(s2, s3, 'conv2'); 52 | var conv3 = extractConvWithBatchNormParams(s3, s4, 'conv3'); 53 | var conv4 = extractConvWithBatchNormParams(s4, s5, 'conv4'); 54 | var conv5 = extractConvWithBatchNormParams(s5, s6, 'conv5'); 55 | var conv6 = extractConvWithBatchNormParams(s6, s7, 'conv6'); 56 | var conv7 = extractConvWithBatchNormParams(s7, s8, 'conv7'); 57 | var conv8 = extractConvParams(s8, 5 * boxEncodingSize, 1, 'conv8'); 58 | params = { conv0: conv0, conv1: conv1, conv2: conv2, conv3: conv3, conv4: conv4, conv5: conv5, conv6: conv6, conv7: conv7, conv8: conv8 }; 59 | } 60 | if (getRemainingWeights().length !== 0) { 61 | throw new Error("weights remaing after extract: " + getRemainingWeights().length); 62 | } 63 | return { params: params, paramMappings: paramMappings }; 64 | } 65 | exports.extractParams = extractParams; 66 | //# sourceMappingURL=extractParams.js.map -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/extractParams.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extractParams.js","sourceRoot":"","sources":["../../../src/tinyYolov2/extractParams.ts"],"names":[],"mappings":";;AAAA,0CAA4C;AAC5C,2EAA0G;AAE1G,oCAAqD;AACrD,iGAAgG;AAIhG,2BAA2B,cAAsC,EAAE,aAA6B;IAE9F,IAAM,iBAAiB,GAAG,iCAAwB,CAAC,cAAc,EAAE,aAAa,CAAC,CAAA;IAEjF,gCAAgC,IAAY,EAAE,YAAoB;QAEhE,IAAM,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAA;QAC7C,IAAM,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAA;QAEjD,aAAa,CAAC,IAAI,CAChB,EAAE,SAAS,EAAK,YAAY,SAAM,EAAE,EACpC,EAAE,SAAS,EAAK,YAAY,aAAU,EAAE,CACzC,CAAA;QAED,OAAO,EAAE,GAAG,KAAA,EAAE,OAAO,SAAA,EAAE,CAAA;IACzB,CAAC;IAED,wCAAwC,UAAkB,EAAE,WAAmB,EAAE,YAAoB;QAEnG,IAAM,IAAI,GAAG,iBAAiB,CAAC,UAAU,EAAE,WAAW,EAAE,CAAC,EAAK,YAAY,UAAO,CAAC,CAAA;QAClF,IAAM,EAAE,GAAG,sBAAsB,CAAC,WAAW,EAAK,YAAY,QAAK,CAAC,CAAA;QAEpE,OAAO,EAAE,IAAI,MAAA,EAAE,EAAE,IAAA,EAAE,CAAA;IACrB,CAAC;IACD,IAAM,0BAA0B,GAAG,qEAAiC,CAAC,cAAc,EAAE,aAAa,CAAC,CAAA;IAEnG,OAAO;QACL,iBAAiB,mBAAA;QACjB,8B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7D,IAAM,KAAK,GAAG,iBAAiB,CAAC,EAAE,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,OAAO,CAAC,CAAA;QACpE,MAAM,GAAG,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,CAAA;KAC3E;IAED,IAAI,mBAAmB,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE;QACtC,MAAM,IAAI,KAAK,CAAC,oCAAkC,mBAAmB,EAAE,CAAC,MAAQ,CAAC,CAAA;KAClF;IAGD,OAAO,EAAE,MAAM,QAAA,EAAE,aAAa,eAAA,EAAE,CAAA;AAClC,CAAC;AAzDD,sCAyDC"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/extractParamsFromWeigthMap.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { ParamMapping } from 'tfjs-image-recognition-base'; 3 | import { TinyYolov2Config } from './config'; 4 | import { TinyYolov2NetParams } from './types'; 5 | export declare function extractParamsFromWeigthMap(weightMap: tf.NamedTensorMap, config: TinyYolov2Config): { 6 | params: TinyYolov2NetParams; 7 | paramMappings: ParamMapping[]; 8 | }; 9 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/extractParamsFromWeigthMap.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tfjs_image_recognition_base_1 = require("tfjs-image-recognition-base"); 4 | var extractSeparableConvParamsFactory_1 = require("../common/extractSeparableConvParamsFactory"); 5 | function extractorsFactory(weightMap, paramMappings) { 6 | var extractWeightEntry = tfjs_image_recognition_base_1.extractWeightEntryFactory(weightMap, paramMappings); 7 | function extractBatchNormParams(prefix) { 8 | var sub = extractWeightEntry(prefix + "/sub", 1); 9 | var truediv = extractWeightEntry(prefix + "/truediv", 1); 10 | return { sub: sub, truediv: truediv }; 11 | } 12 | function extractConvParams(prefix) { 13 | var filters = extractWeightEntry(prefix + "/filters", 4); 14 | var bias = extractWeightEntry(prefix + "/bias", 1); 15 | return { filters: filters, bias: bias }; 16 | } 17 | function extractConvWithBatchNormParams(prefix) { 18 | var conv = extractConvParams(prefix + "/conv"); 19 | var bn = extractBatchNormParams(prefix + "/bn"); 20 | return { conv: conv, bn: bn }; 21 | } 22 | var extractSeparableConvParams = extractSeparableConvParamsFactory_1.loadSeparableConvParamsFactory(extractWeightEntry); 23 | return { 24 | extractConvParams: extractConvParams, 25 | extractConvWithBatchNormParams: extractConvWithBatchNormParams, 26 | extractSeparableConvParams: extractSeparableConvParams 27 | }; 28 | } 29 | function extractParamsFromWeigthMap(weightMap, config) { 30 | var paramMappings = []; 31 | var _a = extractorsFactory(weightMap, paramMappings), extractConvParams = _a.extractConvParams, extractConvWithBatchNormParams = _a.extractConvWithBatchNormParams, extractSeparableConvParams = _a.extractSeparableConvParams; 32 | var params; 33 | if (config.withSeparableConvs) { 34 | var numFilters = (config.filterSizes && config.filterSizes.length || 9); 35 | params = { 36 | conv0: config.isFirstLayerConv2d ? extractConvParams('conv0') : extractSeparableConvParams('conv0'), 37 | conv1: extractSeparableConvParams('conv1'), 38 | conv2: extractSeparableConvParams('conv2'), 39 | conv3: extractSeparableConvParams('conv3'), 40 | conv4: extractSeparableConvParams('conv4'), 41 | conv5: extractSeparableConvParams('conv5'), 42 | conv6: numFilters > 7 ? extractSeparableConvParams('conv6') : undefined, 43 | conv7: numFilters > 8 ? extractSeparableConvParams('conv7') : undefined, 44 | conv8: extractConvParams('conv8') 45 | }; 46 | } 47 | else { 48 | params = { 49 | conv0: extractConvWithBatchNormParams('conv0'), 50 | conv1: extractConvWithBatchNormParams('conv1'), 51 | conv2: extractConvWithBatchNormParams('conv2'), 52 | conv3: extractConvWithBatchNormParams('conv3'), 53 | conv4: extractConvWithBatchNormParams('conv4'), 54 | conv5: extractConvWithBatchNormParams('conv5'), 55 | conv6: extractConvWithBatchNormParams('conv6'), 56 | conv7: extractConvWithBatchNormParams('conv7'), 57 | conv8: extractConvParams('conv8') 58 | }; 59 | } 60 | tfjs_image_recognition_base_1.disposeUnusedWeightTensors(weightMap, paramMappings); 61 | return { params: params, paramMappings: paramMappings }; 62 | } 63 | exports.extractParamsFromWeigthMap = extractParamsFromWeigthMap; 64 | //# sourceMappingURL=extractParamsFromWeigthMap.js.map -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/extractParamsFromWeigthMap.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extractParamsFromWeigthMap.js","sourceRoot":"","sources":["../../../src/tinyYolov2/extractParamsFromWeigthMap.ts"],"names":[],"mappings":";;AACA,2EAAkH;AAGlH,iGAA6F;AAI7F,2BAA2B,SAAc,EAAE,aAA6B;IAEtE,IAAM,kBAAkB,GAAG,uDAAyB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;IAE9E,gCAAgC,MAAc;QAC5C,IAAM,GAAG,GAAG,kBAAkB,CAAiB,MAAM,SAAM,EAAE,CAAC,CAAC,CAAA;QAC/D,IAAM,OAAO,GAAG,kBAAkB,CAAiB,MAAM,aAAU,EAAE,CAAC,CAAC,CAAA;QACvE,OAAO,EAAE,GAAG,KAAA,EAAE,OAAO,SAAA,EAAE,CAAA;IACzB,CAAC;IAED,2BAA2B,MAAc;QACvC,IAAM,OAAO,GAAG,kBAAkB,CAAiB,MAAM,aAAU,EAAE,CAAC,CAAC,CAAA;QACvE,IAAM,IAAI,GAAG,kBAAkB,CAAiB,MAAM,UAAO,EAAE,CAAC,CAAC,CAAA;QACjE,OAAO,EAAE,OAAO,SAAA,EAAE,IAAI,MAAA,EAAE,CAAA;IAC1B,CAAC;IAED,wCAAwC,MAAc;QACpD,IAAM,IAAI,GAAG,iBAAiB,CAAI,MAAM,UAAO,CAAC,CAAA;QAChD,IAAM,EAAE,GAAG,sBAAsB,CAAI,MAA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M,GAAG;YACP,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC;SAClC,CAAA;KACF;IAED,wDAA0B,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;IAEpD,OAAO,EAAE,MAAM,QAAA,EAAE,aAAa,eAAA,EAAE,CAAA;AAClC,CAAC;AA7CD,gEA6CC"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/getDefaultBackwardOptions.d.ts: -------------------------------------------------------------------------------- 1 | import { TinyYolov2BackwardOptions } from './types'; 2 | export declare function getDefaultBackwardOptions(options: TinyYolov2BackwardOptions): { 3 | minBoxSize: number; 4 | } & TinyYolov2BackwardOptions; 5 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/getDefaultBackwardOptions.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var const_1 = require("./const"); 4 | function getDefaultBackwardOptions(options) { 5 | return Object.assign({}, { 6 | minBoxSize: const_1.CELL_SIZE 7 | }, options); 8 | } 9 | exports.getDefaultBackwardOptions = getDefaultBackwardOptions; 10 | //# sourceMappingURL=getDefaultBackwardOptions.js.map -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/getDefaultBackwardOptions.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"getDefaultBackwardOptions.js","sourceRoot":"","sources":["../../../src/tinyYolov2/getDefaultBackwardOptions.ts"],"names":[],"mappings":";;AAAA,iCAAoC;AAGpC,mCAA0C,OAAkC;IAC1E,OAAO,MAAM,CAAC,MAAM,CAClB,EAAE,EACF;QACE,UAAU,EAAE,iBAAS;KACtB,EACD,OAAO,CACR,CAAA;AACH,CAAC;AARD,8DAQC"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './TinyYolov2'; 2 | export * from './TinyYolov2LossFunction'; 3 | export * from './TinyYolov2Trainable'; 4 | export * from './TinyYolov2Options'; 5 | export { TinyYolov2NetParams } from './types'; 6 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/index.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tslib_1 = require("tslib"); 4 | tslib_1.__exportStar(require("./TinyYolov2"), exports); 5 | tslib_1.__exportStar(require("./TinyYolov2LossFunction"), exports); 6 | tslib_1.__exportStar(require("./TinyYolov2Trainable"), exports); 7 | tslib_1.__exportStar(require("./TinyYolov2Options"), exports); 8 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tinyYolov2/index.ts"],"names":[],"mappings":";;;AAAA,uDAA6B;AAC7B,mEAAyC;AACzC,gEAAsC;AACtC,8DAAoC"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/leaky.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | export declare function leaky(x: tf.Tensor4D): tf.Tensor4D; 3 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/leaky.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | var tf = require("@tensorflow/tfjs-core"); 4 | function leaky(x) { 5 | return tf.tidy(function () { 6 | var min = tf.mul(x, tf.scalar(0.10000000149011612)); 7 | return tf.add(tf.relu(tf.sub(x, min)), min); 8 | //return tf.maximum(x, min) 9 | }); 10 | } 11 | exports.leaky = leaky; 12 | //# sourceMappingURL=leaky.js.map -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/leaky.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"leaky.js","sourceRoot":"","sources":["../../../src/tinyYolov2/leaky.ts"],"names":[],"mappings":";;AAAA,0CAA4C;AAE5C,eAAsB,CAAc;IAClC,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAM,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAA;QACrD,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;QAC3C,2BAA2B;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC;AAND,sBAMC"} -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/types.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { Box, IRect } from 'tfjs-image-recognition-base'; 3 | import { ConvParams } from '../common'; 4 | import { SeparableConvParams } from '../common/types'; 5 | export declare type BatchNorm = { 6 | sub: tf.Tensor1D; 7 | truediv: tf.Tensor1D; 8 | }; 9 | export declare type ConvWithBatchNorm = { 10 | conv: ConvParams; 11 | bn: BatchNorm; 12 | }; 13 | export declare type MobilenetParams = { 14 | conv0: SeparableConvParams | ConvParams; 15 | conv1: SeparableConvParams; 16 | conv2: SeparableConvParams; 17 | conv3: SeparableConvParams; 18 | conv4: SeparableConvParams; 19 | conv5: SeparableConvParams; 20 | conv6?: SeparableConvParams; 21 | conv7?: SeparableConvParams; 22 | conv8: ConvParams; 23 | }; 24 | export declare type DefaultTinyYolov2NetParams = { 25 | conv0: ConvWithBatchNorm; 26 | conv1: ConvWithBatchNorm; 27 | conv2: ConvWithBatchNorm; 28 | conv3: ConvWithBatchNorm; 29 | conv4: ConvWithBatchNorm; 30 | conv5: ConvWithBatchNorm; 31 | conv6: ConvWithBatchNorm; 32 | conv7: ConvWithBatchNorm; 33 | conv8: ConvParams; 34 | }; 35 | export declare type TinyYolov2NetParams = DefaultTinyYolov2NetParams | MobilenetParams; 36 | export declare type GridPosition = { 37 | row: number; 38 | col: number; 39 | anchor: number; 40 | }; 41 | export declare type GroundTruthWithGridPosition = GridPosition & { 42 | box: Box; 43 | label: number; 44 | }; 45 | export declare type GroundTruth = IRect & { 46 | label: number; 47 | }; 48 | export declare type YoloLoss = { 49 | totalLoss: number; 50 | noObjectLoss: number; 51 | objectLoss: number; 52 | coordLoss: number; 53 | classLoss: number; 54 | }; 55 | export declare type LossReport = { 56 | losses: YoloLoss; 57 | numBoxes: number; 58 | inputSize: number; 59 | }; 60 | export declare type TinyYolov2BackwardOptions = { 61 | minBoxSize?: number; 62 | reportLosses?: (report: LossReport) => void; 63 | }; 64 | -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/types.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | Object.defineProperty(exports, "__esModule", { value: true }); 3 | //# sourceMappingURL=types.js.map -------------------------------------------------------------------------------- /build/commonjs/tinyYolov2/types.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/tinyYolov2/types.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /build/es6/common/convLayer.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { ConvParams } from './types'; 3 | export declare function convLayer(x: tf.Tensor4D, params: ConvParams, padding?: 'valid' | 'same', withRelu?: boolean): tf.Tensor4D; 4 | -------------------------------------------------------------------------------- /build/es6/common/convLayer.js: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | export function convLayer(x, params, padding, withRelu) { 3 | if (padding === void 0) { padding = 'same'; } 4 | if (withRelu === void 0) { withRelu = false; } 5 | return tf.tidy(function () { 6 | var out = tf.add(tf.conv2d(x, params.filters, [1, 1], padding), params.bias); 7 | return withRelu ? tf.relu(out) : out; 8 | }); 9 | } 10 | //# sourceMappingURL=convLayer.js.map -------------------------------------------------------------------------------- /build/es6/common/convLayer.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"convLayer.js","sourceRoot":"","sources":["../../../src/common/convLayer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAI5C,MAAM,oBACJ,CAAc,EACd,MAAkB,EAClB,OAAkC,EAClC,QAAyB;IADzB,wBAAA,EAAA,gBAAkC;IAClC,yBAAA,EAAA,gBAAyB;IAEzB,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAM,GAAG,GAAG,EAAE,CAAC,GAAG,CAChB,EAAE,CAAC,MAAM,CAAC,CAAC,EAAE,MAAM,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,EAC7C,MAAM,CAAC,IAAI,CACG,CAAA;QAEhB,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAA;IACtC,CAAC,CAAC,CAAA;AACJ,CAAC"} -------------------------------------------------------------------------------- /build/es6/common/extractConvParamsFactory.d.ts: -------------------------------------------------------------------------------- 1 | import { ExtractWeightsFunction, ParamMapping } from 'tfjs-image-recognition-base'; 2 | import { ConvParams } from './types'; 3 | export declare function extractConvParamsFactory(extractWeights: ExtractWeightsFunction, paramMappings: ParamMapping[]): (channelsIn: number, channelsOut: number, filterSize: number, mappedPrefix: string) => ConvParams; 4 | -------------------------------------------------------------------------------- /build/es6/common/extractConvParamsFactory.js: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | export function extractConvParamsFactory(extractWeights, paramMappings) { 3 | return function (channelsIn, channelsOut, filterSize, mappedPrefix) { 4 | var filters = tf.tensor4d(extractWeights(channelsIn * channelsOut * filterSize * filterSize), [filterSize, filterSize, channelsIn, channelsOut]); 5 | var bias = tf.tensor1d(extractWeights(channelsOut)); 6 | paramMappings.push({ paramPath: mappedPrefix + "/filters" }, { paramPath: mappedPrefix + "/bias" }); 7 | return { filters: filters, bias: bias }; 8 | }; 9 | } 10 | //# sourceMappingURL=extractConvParamsFactory.js.map -------------------------------------------------------------------------------- /build/es6/common/extractConvParamsFactory.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extractConvParamsFactory.js","sourceRoot":"","sources":["../../../src/common/extractConvParamsFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAK5C,MAAM,mCACJ,cAAsC,EACtC,aAA6B;IAG7B,OAAO,UACL,UAAkB,EAClB,WAAmB,EACnB,UAAkB,EAClB,YAAoB;QAGpB,IAAM,OAAO,GAAG,EAAE,CAAC,QAAQ,CACzB,cAAc,CAAC,UAAU,GAAG,WAAW,GAAG,UAAU,GAAG,UAAU,CAAC,EAClE,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,WAAW,CAAC,CAClD,CAAA;QACD,IAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,CAAA;QAErD,aAAa,CAAC,IAAI,CAChB,EAAE,SAAS,EAAK,YAAY,aAAU,EAAE,EACxC,EAAE,SAAS,EAAK,YAAY,UAAO,EAAE,CACtC,CAAA;QAED,OAAO,EAAE,OAAO,SAAA,EAAE,IAAI,MAAA,EAAE,CAAA;IAC1B,CAAC,CAAA;AAEH,CAAC"} -------------------------------------------------------------------------------- /build/es6/common/extractFCParamsFactory.d.ts: -------------------------------------------------------------------------------- 1 | import { ExtractWeightsFunction, ParamMapping } from 'tfjs-image-recognition-base'; 2 | import { FCParams } from './types'; 3 | export declare function extractFCParamsFactory(extractWeights: ExtractWeightsFunction, paramMappings: ParamMapping[]): (channelsIn: number, channelsOut: number, mappedPrefix: string) => FCParams; 4 | -------------------------------------------------------------------------------- /build/es6/common/extractFCParamsFactory.js: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | export function extractFCParamsFactory(extractWeights, paramMappings) { 3 | return function (channelsIn, channelsOut, mappedPrefix) { 4 | var fc_weights = tf.tensor2d(extractWeights(channelsIn * channelsOut), [channelsIn, channelsOut]); 5 | var fc_bias = tf.tensor1d(extractWeights(channelsOut)); 6 | paramMappings.push({ paramPath: mappedPrefix + "/weights" }, { paramPath: mappedPrefix + "/bias" }); 7 | return { 8 | weights: fc_weights, 9 | bias: fc_bias 10 | }; 11 | }; 12 | } 13 | //# sourceMappingURL=extractFCParamsFactory.js.map -------------------------------------------------------------------------------- /build/es6/common/extractFCParamsFactory.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extractFCParamsFactory.js","sourceRoot":"","sources":["../../../src/common/extractFCParamsFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAM5C,MAAM,iCACJ,cAAsC,EACtC,aAA6B;IAG7B,OAAO,UACL,UAAkB,EAClB,WAAmB,EACnB,YAAoB;QAGpB,IAAM,UAAU,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,UAAU,GAAG,WAAW,CAAC,EAAE,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC,CAAA;QACnG,IAAM,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,CAAA;QAExD,aAAa,CAAC,IAAI,CAChB,EAAE,SAAS,EAAK,YAAY,aAAU,EAAE,EACxC,EAAE,SAAS,EAAK,YAAY,UAAO,EAAE,CACtC,CAAA;QAED,OAAO;YACL,OAAO,EAAE,UAAU;YACnB,IAAI,EAAE,OAAO;SACd,CAAA;IACH,CAAC,CAAA;AAEH,CAAC"} -------------------------------------------------------------------------------- /build/es6/common/extractSeparableConvParamsFactory.d.ts: -------------------------------------------------------------------------------- 1 | import { ExtractWeightsFunction, ParamMapping } from 'tfjs-image-recognition-base'; 2 | import { SeparableConvParams } from './types'; 3 | export declare function extractSeparableConvParamsFactory(extractWeights: ExtractWeightsFunction, paramMappings: ParamMapping[]): (channelsIn: number, channelsOut: number, mappedPrefix: string) => SeparableConvParams; 4 | export declare function loadSeparableConvParamsFactory(extractWeightEntry: (originalPath: string, paramRank: number) => T): (prefix: string) => SeparableConvParams; 5 | -------------------------------------------------------------------------------- /build/es6/common/extractSeparableConvParamsFactory.js: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { SeparableConvParams } from './types'; 3 | export function extractSeparableConvParamsFactory(extractWeights, paramMappings) { 4 | return function (channelsIn, channelsOut, mappedPrefix) { 5 | var depthwise_filter = tf.tensor4d(extractWeights(3 * 3 * channelsIn), [3, 3, channelsIn, 1]); 6 | var pointwise_filter = tf.tensor4d(extractWeights(channelsIn * channelsOut), [1, 1, channelsIn, channelsOut]); 7 | var bias = tf.tensor1d(extractWeights(channelsOut)); 8 | paramMappings.push({ paramPath: mappedPrefix + "/depthwise_filter" }, { paramPath: mappedPrefix + "/pointwise_filter" }, { paramPath: mappedPrefix + "/bias" }); 9 | return new SeparableConvParams(depthwise_filter, pointwise_filter, bias); 10 | }; 11 | } 12 | export function loadSeparableConvParamsFactory(extractWeightEntry) { 13 | return function (prefix) { 14 | var depthwise_filter = extractWeightEntry(prefix + "/depthwise_filter", 4); 15 | var pointwise_filter = extractWeightEntry(prefix + "/pointwise_filter", 4); 16 | var bias = extractWeightEntry(prefix + "/bias", 1); 17 | return new SeparableConvParams(depthwise_filter, pointwise_filter, bias); 18 | }; 19 | } 20 | //# sourceMappingURL=extractSeparableConvParamsFactory.js.map -------------------------------------------------------------------------------- /build/es6/common/extractSeparableConvParamsFactory.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extractSeparableConvParamsFactory.js","sourceRoot":"","sources":["../../../src/common/extractSeparableConvParamsFactory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAG5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAE9C,MAAM,4CACJ,cAAsC,EACtC,aAA6B;IAG7B,OAAO,UAAS,UAAkB,EAAE,WAAmB,EAAE,YAAoB;QAC3E,IAAM,gBAAgB,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAA;QAC/F,IAAM,gBAAgB,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,UAAU,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC,CAAA;QAC/G,IAAM,IAAI,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,WAAW,CAAC,CAAC,CAAA;QAErD,aAAa,CAAC,IAAI,CAChB,EAAE,SAAS,EAAK,YAAY,sBAAmB,EAAE,EACjD,EAAE,SAAS,EAAK,YAAY,sBAAmB,EAAE,EACjD,EAAE,SAAS,EAAK,YAAY,UAAO,EAAE,CACtC,CAAA;QAED,OAAO,IAAI,mBAAmB,CAC5B,gBAAgB,EAChB,gBAAgB,EAChB,IAAI,CACL,CAAA;IACH,CAAC,CAAA;AAEH,CAAC;AAED,MAAM,yCACJ,kBAAqE;IAGrE,OAAO,UAAU,MAAc;QAC7B,IAAM,gBAAgB,GAAG,kBAAkB,CAAiB,MAAM,sBAAmB,EAAE,CAAC,CAAC,CAAA;QACzF,IAAM,gBAAgB,GAAG,kBAAkB,CAAiB,MAAM,sBAAmB,EAAE,CAAC,CAAC,CAAA;QACzF,IAAM,IAAI,GAAG,kBAAkB,CAAiB,MAAM,UAAO,EAAE,CAAC,CAAC,CAAA;QAEjE,OAAO,IAAI,mBAAmB,CAC5B,gBAAgB,EAChB,gBAAgB,EAChB,IAAI,CACL,CAAA;IACH,CAAC,CAAA;AAEH,CAAC"} -------------------------------------------------------------------------------- /build/es6/common/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './convLayer'; 2 | export * from './extractConvParamsFactory'; 3 | export * from './extractFCParamsFactory'; 4 | export * from './extractSeparableConvParamsFactory'; 5 | export * from './types'; 6 | -------------------------------------------------------------------------------- /build/es6/common/index.js: -------------------------------------------------------------------------------- 1 | export * from './convLayer'; 2 | export * from './extractConvParamsFactory'; 3 | export * from './extractFCParamsFactory'; 4 | export * from './extractSeparableConvParamsFactory'; 5 | export * from './types'; 6 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /build/es6/common/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/common/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,4BAA4B,CAAC;AAC3C,cAAc,0BAA0B,CAAC;AACzC,cAAc,qCAAqC,CAAC;AACpD,cAAc,SAAS,CAAC"} -------------------------------------------------------------------------------- /build/es6/common/types.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | export declare type ConvParams = { 3 | filters: tf.Tensor4D; 4 | bias: tf.Tensor1D; 5 | }; 6 | export declare type FCParams = { 7 | weights: tf.Tensor2D; 8 | bias: tf.Tensor1D; 9 | }; 10 | export declare class SeparableConvParams { 11 | depthwise_filter: tf.Tensor4D; 12 | pointwise_filter: tf.Tensor4D; 13 | bias: tf.Tensor1D; 14 | constructor(depthwise_filter: tf.Tensor4D, pointwise_filter: tf.Tensor4D, bias: tf.Tensor1D); 15 | } 16 | -------------------------------------------------------------------------------- /build/es6/common/types.js: -------------------------------------------------------------------------------- 1 | var SeparableConvParams = /** @class */ (function () { 2 | function SeparableConvParams(depthwise_filter, pointwise_filter, bias) { 3 | this.depthwise_filter = depthwise_filter; 4 | this.pointwise_filter = pointwise_filter; 5 | this.bias = bias; 6 | } 7 | return SeparableConvParams; 8 | }()); 9 | export { SeparableConvParams }; 10 | //# sourceMappingURL=types.js.map -------------------------------------------------------------------------------- /build/es6/common/types.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/common/types.ts"],"names":[],"mappings":"AAYA;IACE,6BACS,gBAA6B,EAC7B,gBAA6B,EAC7B,IAAiB;QAFjB,qBAAgB,GAAhB,gBAAgB,CAAa;QAC7B,qBAAgB,GAAhB,gBAAgB,CAAa;QAC7B,SAAI,GAAJ,IAAI,CAAa;IACvB,CAAC;IACN,0BAAC;AAAD,CAAC,AAND,IAMC"} -------------------------------------------------------------------------------- /build/es6/index.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | export * from 'tfjs-image-recognition-base'; 3 | export * from './common'; 4 | export * from './tinyYolov2'; 5 | export { tf }; 6 | -------------------------------------------------------------------------------- /build/es6/index.js: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | export * from 'tfjs-image-recognition-base'; 3 | export * from './common'; 4 | export * from './tinyYolov2'; 5 | export { tf }; 6 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /build/es6/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE5C,cAAc,6BAA6B,CAAC;AAC5C,cAAc,UAAU,CAAC;AACzB,cAAc,cAAc,CAAC;AAE7B,OAAO,EAAE,EAAE,EAAE,CAAA"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/TinyYolov2.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { BoundingBox, Dimensions, NetInput, NeuralNetwork, ObjectDetection, TNetInput } from 'tfjs-image-recognition-base'; 3 | import { TinyYolov2Config } from './config'; 4 | import { ITinyYolov2Options } from './TinyYolov2Options'; 5 | import { DefaultTinyYolov2NetParams, MobilenetParams, TinyYolov2NetParams } from './types'; 6 | export declare class TinyYolov2 extends NeuralNetwork { 7 | private _config; 8 | constructor(config: TinyYolov2Config); 9 | readonly config: TinyYolov2Config; 10 | readonly withClassScores: boolean; 11 | readonly boxEncodingSize: number; 12 | runTinyYolov2(x: tf.Tensor4D, params: DefaultTinyYolov2NetParams): tf.Tensor4D; 13 | runMobilenet(x: tf.Tensor4D, params: MobilenetParams): tf.Tensor4D; 14 | forwardInput(input: NetInput, inputSize: number): tf.Tensor4D; 15 | forward(input: TNetInput, inputSize: number): Promise; 16 | detect(input: TNetInput, forwardParams?: ITinyYolov2Options): Promise; 17 | protected getDefaultModelName(): string; 18 | protected extractParamsFromWeigthMap(weightMap: tf.NamedTensorMap): { 19 | params: TinyYolov2NetParams; 20 | paramMappings: { 21 | originalPath?: string | undefined; 22 | paramPath: string; 23 | }[]; 24 | }; 25 | protected extractParams(weights: Float32Array): { 26 | params: TinyYolov2NetParams; 27 | paramMappings: { 28 | originalPath?: string | undefined; 29 | paramPath: string; 30 | }[]; 31 | }; 32 | protected extractBoxes(outputTensor: tf.Tensor4D, inputBlobDimensions: Dimensions, scoreThreshold?: number): { 33 | row: number; 34 | col: number; 35 | anchor: number; 36 | box: BoundingBox; 37 | score: number; 38 | classScore: number; 39 | label: number; 40 | }[]; 41 | private extractPredictedClass(classesTensor, pos); 42 | } 43 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/TinyYolov2LossFunction.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { Dimensions, IDimensions, Point } from 'tfjs-image-recognition-base'; 3 | import { TinyYolov2TrainableConfig } from './config'; 4 | import { GroundTruth, GroundTruthWithGridPosition } from './types'; 5 | export declare class TinyYolov2LossFunction { 6 | private _config; 7 | private _reshapedImgDims; 8 | private _outputTensor; 9 | private _groundTruth; 10 | private _predictedBoxes; 11 | noObjectLossMask: tf.Tensor4D; 12 | objectLossMask: tf.Tensor4D; 13 | coordBoxOffsetMask: tf.Tensor4D; 14 | coordBoxSizeMask: tf.Tensor4D; 15 | groundTruthClassScoresMask: tf.Tensor4D; 16 | constructor(outputTensor: tf.Tensor4D, groundTruth: GroundTruth[], predictedBoxes: GroundTruthWithGridPosition[], reshapedImgDims: IDimensions, config: TinyYolov2TrainableConfig); 17 | readonly config: TinyYolov2TrainableConfig; 18 | readonly reshapedImgDims: Dimensions; 19 | readonly outputTensor: tf.Tensor4D; 20 | readonly groundTruth: GroundTruthWithGridPosition[]; 21 | readonly predictedBoxes: GroundTruthWithGridPosition[]; 22 | readonly inputSize: number; 23 | readonly withClassScores: boolean; 24 | readonly boxEncodingSize: number; 25 | readonly anchors: Point[]; 26 | readonly numBoxes: number; 27 | readonly numCells: number; 28 | readonly gridCellEncodingSize: number; 29 | toOutputTensorShape(tensor: tf.Tensor): tf.Tensor; 30 | computeLoss(): { 31 | noObjectLoss: tf.Tensor; 32 | objectLoss: tf.Tensor; 33 | coordLoss: tf.Tensor; 34 | classLoss: tf.Tensor; 35 | totalLoss: tf.Tensor; 36 | }; 37 | computeNoObjectLoss(): tf.Tensor; 38 | computeObjectLoss(): tf.Tensor; 39 | computeClassLoss(): tf.Tensor; 40 | computeCoordLoss(): tf.Tensor; 41 | computeCoordBoxOffsetError(): tf.Tensor4D; 42 | computeCoordBoxSizeError(): tf.Tensor4D; 43 | private computeLossTerm(scale, mask, lossTensor); 44 | private squaredSumOverMask(mask, lossTensor); 45 | private validateGroundTruthBoxes(groundTruth); 46 | private assignGroundTruthToAnchors(groundTruth); 47 | private createGroundTruthMask(); 48 | private createCoordAndScoreMasks(); 49 | private createOneHotClassScoreMask(); 50 | private computeIous(); 51 | computeCoordBoxOffsets(): tf.Tensor; 52 | computeCoordBoxSizes(): tf.Tensor; 53 | } 54 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/TinyYolov2Options.d.ts: -------------------------------------------------------------------------------- 1 | export declare enum TinyYolov2SizeType { 2 | XS = 224, 3 | SM = 320, 4 | MD = 416, 5 | LG = 608, 6 | } 7 | export interface ITinyYolov2Options { 8 | inputSize?: number; 9 | scoreThreshold?: number; 10 | } 11 | export declare class TinyYolov2Options { 12 | protected _name: string; 13 | private _inputSize; 14 | private _scoreThreshold; 15 | constructor({inputSize, scoreThreshold}?: ITinyYolov2Options); 16 | readonly inputSize: number; 17 | readonly scoreThreshold: number; 18 | } 19 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/TinyYolov2Options.js: -------------------------------------------------------------------------------- 1 | export var TinyYolov2SizeType; 2 | (function (TinyYolov2SizeType) { 3 | TinyYolov2SizeType[TinyYolov2SizeType["XS"] = 224] = "XS"; 4 | TinyYolov2SizeType[TinyYolov2SizeType["SM"] = 320] = "SM"; 5 | TinyYolov2SizeType[TinyYolov2SizeType["MD"] = 416] = "MD"; 6 | TinyYolov2SizeType[TinyYolov2SizeType["LG"] = 608] = "LG"; 7 | })(TinyYolov2SizeType || (TinyYolov2SizeType = {})); 8 | var TinyYolov2Options = /** @class */ (function () { 9 | function TinyYolov2Options(_a) { 10 | var _b = _a === void 0 ? {} : _a, inputSize = _b.inputSize, scoreThreshold = _b.scoreThreshold; 11 | this._name = 'TinyYolov2Options'; 12 | this._inputSize = inputSize || 416; 13 | this._scoreThreshold = scoreThreshold || 0.5; 14 | if (typeof this._inputSize !== 'number' || this._inputSize % 32 !== 0) { 15 | throw new Error(this._name + " - expected inputSize to be a number divisible by 32"); 16 | } 17 | if (typeof this._scoreThreshold !== 'number' || this._scoreThreshold <= 0 || this._scoreThreshold >= 1) { 18 | throw new Error(this._name + " - expected scoreThreshold to be a number between 0 and 1"); 19 | } 20 | } 21 | Object.defineProperty(TinyYolov2Options.prototype, "inputSize", { 22 | get: function () { return this._inputSize; }, 23 | enumerable: true, 24 | configurable: true 25 | }); 26 | Object.defineProperty(TinyYolov2Options.prototype, "scoreThreshold", { 27 | get: function () { return this._scoreThreshold; }, 28 | enumerable: true, 29 | configurable: true 30 | }); 31 | return TinyYolov2Options; 32 | }()); 33 | export { TinyYolov2Options }; 34 | //# sourceMappingURL=TinyYolov2Options.js.map -------------------------------------------------------------------------------- /build/es6/tinyYolov2/TinyYolov2Options.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"TinyYolov2Options.js","sourceRoot":"","sources":["../../../src/tinyYolov2/TinyYolov2Options.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,kBAKX;AALD,WAAY,kBAAkB;IAC5B,yDAAQ,CAAA;IACR,yDAAQ,CAAA;IACR,yDAAQ,CAAA;IACR,yDAAQ,CAAA;AACV,CAAC,EALW,kBAAkB,KAAlB,kBAAkB,QAK7B;AAOD;IAME,2BAAY,EAAsD;YAAtD,4BAAsD,EAApD,wBAAS,EAAE,kCAAc;QAL7B,UAAK,GAAW,mBAAmB,CAAA;QAM3C,IAAI,CAAC,UAAU,GAAG,SAAS,IAAI,GAAG,CAAA;QAClC,IAAI,CAAC,eAAe,GAAG,cAAc,IAAI,GAAG,CAAA;QAE5C,IAAI,OAAO,IAAI,CAAC,UAAU,KAAK,QAAQ,IAAI,IAAI,CAAC,UAAU,GAAG,EAAE,KAAK,CAAC,EAAE;YACrE,MAAM,IAAI,KAAK,CAAI,IAAI,CAAC,KAAK,yDAAsD,CAAC,CAAA;SACrF;QAED,IAAI,OAAO,IAAI,CAAC,eAAe,KAAK,QAAQ,IAAI,IAAI,CAAC,eAAe,IAAI,CAAC,IAAI,IAAI,CAAC,eAAe,IAAI,CAAC,EAAE;YACtG,MAAM,IAAI,KAAK,CAAI,IAAI,CAAC,KAAK,8DAA2D,CAAC,CAAA;SAC1F;IACH,CAAC;IAED,sBAAI,wCAAS;aAAb,cAA0B,OAAO,IAAI,CAAC,UAAU,CAAA,CAAC,CAAC;;;OAAA;IAClD,sBAAI,6CAAc;aAAlB,cAA+B,OAAO,IAAI,CAAC,eAAe,CAAA,CAAC,CAAC;;;OAAA;IAC9D,wBAAC;AAAD,CAAC,AArBD,IAqBC"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/TinyYolov2Trainable.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { Dimensions } from 'tfjs-image-recognition-base'; 3 | import { TinyYolov2TrainableConfig } from './config'; 4 | import { TinyYolov2 } from './TinyYolov2'; 5 | import { GroundTruth, TinyYolov2BackwardOptions } from './types'; 6 | export declare class TinyYolov2Trainable extends TinyYolov2 { 7 | private _trainableConfig; 8 | private _optimizer; 9 | constructor(trainableConfig: TinyYolov2TrainableConfig, optimizer: tf.Optimizer); 10 | readonly trainableConfig: TinyYolov2TrainableConfig; 11 | readonly optimizer: tf.Optimizer; 12 | backward(img: HTMLImageElement | HTMLCanvasElement, groundTruth: GroundTruth[], inputSize: number, options?: TinyYolov2BackwardOptions): Promise | null>; 13 | computeLoss(outputTensor: tf.Tensor4D, groundTruth: GroundTruth[], reshapedImgDims: Dimensions): { 14 | noObjectLoss: tf.Tensor; 15 | objectLoss: tf.Tensor; 16 | coordLoss: tf.Tensor; 17 | classLoss: tf.Tensor; 18 | totalLoss: tf.Tensor; 19 | }; 20 | filterGroundTruthBoxes(groundTruth: GroundTruth[], imgDims: Dimensions, minBoxSize: number): GroundTruth[]; 21 | load(weightsOrUrl: Float32Array | string | undefined): Promise; 22 | } 23 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/TinyYolov2Trainable.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"TinyYolov2Trainable.js","sourceRoot":"","sources":["../../../src/tinyYolov2/TinyYolov2Trainable.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EACL,yBAAyB,EAEzB,kBAAkB,EAClB,aAAa,EACb,IAAI,EACJ,UAAU,GACX,MAAM,6B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EAAE,MAAM,CAAC,CAAA;YACnH,OAAO,YAAY,CAAC,WAAW,EAAE,CAAA;QACnC,CAAC,CAAC,CAAA;IACJ,CAAC;IAEM,oDAAsB,GAA7B,UAA8B,WAA0B,EAAE,OAAmB,EAAE,UAAkB;QAEvF,IAAA,0BAAiB,EAAE,wBAAe,CAAY;QAEtD,OAAO,WAAW,CAAC,MAAM,CAAC,UAAC,EAAuB;gBAArB,QAAC,EAAE,QAAC,EAAE,gBAAK,EAAE,kBAAM;YAC9C,IAAM,GAAG,GAAG,CAAC,IAAI,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;iBACxC,OAAO,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,CAAC,CAAA;YAElD,IAAM,SAAS,GAAG,GAAG,CAAC,KAAK,GAAG,UAAU,IAAI,GAAG,CAAC,MAAM,GAAG,UAAU,CAAA;YACnE,OAAO,CAAC,SAAS,CAAA;QACnB,CAAC,CAAC,CAAA;IACJ,CAAC;IAEY,kCAAI,GAAjB,UAAkB,YAA+C;;;;4BAC/D,qBAAM,iBAAM,IAAI,YAAC,YAAY,CAAC,EAAA;;wBAA9B,SAA8B,CAAA;wBAC9B,IAAI,CAAC,QAAQ,EAAE,CAAA;;;;;KAChB;IACH,0BAAC;AAAD,CAAC,AA9GD,CAAyC,UAAU,GA8GlD"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/config.d.ts: -------------------------------------------------------------------------------- 1 | import { Point } from 'tfjs-image-recognition-base'; 2 | export declare type TinyYolov2Config = { 3 | withSeparableConvs: boolean; 4 | iouThreshold: number; 5 | anchors: Point[]; 6 | classes: string[]; 7 | meanRgb?: [number, number, number]; 8 | withClassScores?: boolean; 9 | filterSizes?: number[]; 10 | isFirstLayerConv2d?: boolean; 11 | }; 12 | export declare type TinyYolov2TrainableConfig = TinyYolov2Config & { 13 | noObjectScale: number; 14 | objectScale: number; 15 | coordScale: number; 16 | classScale: number; 17 | }; 18 | export declare function validateConfig(config: any): void; 19 | export declare function validateTrainConfig(config: any): TinyYolov2TrainableConfig; 20 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/config.js: -------------------------------------------------------------------------------- 1 | var isNumber = function (arg) { return typeof arg === 'number'; }; 2 | export function validateConfig(config) { 3 | if (!config) { 4 | throw new Error("invalid config: " + config); 5 | } 6 | if (typeof config.withSeparableConvs !== 'boolean') { 7 | throw new Error("config.withSeparableConvs has to be a boolean, have: " + config.withSeparableConvs); 8 | } 9 | if (!isNumber(config.iouThreshold) || config.iouThreshold < 0 || config.iouThreshold > 1.0) { 10 | throw new Error("config.iouThreshold has to be a number between [0, 1], have: " + config.iouThreshold); 11 | } 12 | if (!Array.isArray(config.classes) 13 | || !config.classes.length 14 | || !config.classes.every(function (c) { return typeof c === 'string'; })) { 15 | throw new Error("config.classes has to be an array class names: string[], have: " + JSON.stringify(config.classes)); 16 | } 17 | if (!Array.isArray(config.anchors) 18 | || !config.anchors.length 19 | || !config.anchors.map(function (a) { return a || {}; }).every(function (a) { return isNumber(a.x) && isNumber(a.y); })) { 20 | throw new Error("config.anchors has to be an array of { x: number, y: number }, have: " + JSON.stringify(config.anchors)); 21 | } 22 | if (config.meanRgb && (!Array.isArray(config.meanRgb) 23 | || config.meanRgb.length !== 3 24 | || !config.meanRgb.every(isNumber))) { 25 | throw new Error("config.meanRgb has to be an array of shape [number, number, number], have: " + JSON.stringify(config.meanRgb)); 26 | } 27 | } 28 | export function validateTrainConfig(config) { 29 | if (![config.noObjectScale, config.objectScale, config.coordScale, config.classScale].every(isNumber)) { 30 | throw new Error("for training you have to specify noObjectScale, objectScale, coordScale, classScale parameters in your config.json file"); 31 | } 32 | return config; 33 | } 34 | //# sourceMappingURL=config.js.map -------------------------------------------------------------------------------- /build/es6/tinyYolov2/config.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/tinyYolov2/config.ts"],"names":[],"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,CAAC,EAA9B,CAA8B,CAAC,EAC7F;QAEA,MAAM,IAAI,KAAK,CAAC,0EAAwE,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAG,CAAC,CAAA;KAC1H;IAED,IAAI,MAAM,CAAC,OAAO,IAAI,CACpB,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,OAAO,CAAC;WAC3B,MAAM,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC;WAC3B,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,QAAQ,CAAC,CACnC,EAAE;QAED,MAAM,IAAI,KAAK,CAAC,gFAA8E,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,OAAO,CAAG,CAAC,CAAA;KAChI;AACH,CAAC;AAED,MAAM,8BAA8B,MAAW;IAC7C,IAAI,CAAC,CAAC,MAAM,CAAC,aAAa,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE;QACrG,MAAM,IAAI,KAAK,CAAC,yHAAyH,CAAC,CAAA;KAC3I;IAED,OAAO,MAAM,CAAA;AACf,CAAC"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/const.d.ts: -------------------------------------------------------------------------------- 1 | export declare const CELL_SIZE = 32; 2 | export declare const DEFAULT_FILTER_SIZES: number[]; 3 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/const.js: -------------------------------------------------------------------------------- 1 | export var CELL_SIZE = 32; 2 | export var DEFAULT_FILTER_SIZES = [ 3 | 3, 16, 32, 64, 128, 256, 512, 1024, 1024 4 | ]; 5 | //# sourceMappingURL=const.js.map -------------------------------------------------------------------------------- /build/es6/tinyYolov2/const.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/tinyYolov2/const.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,IAAM,SAAS,GAAG,EAAE,CAAA;AAE3B,MAAM,CAAC,IAAM,oBAAoB,GAAG;IAClC,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI;CACzC,CAAA"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/convWithBatchNorm.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { ConvWithBatchNorm } from './types'; 3 | export declare function convWithBatchNorm(x: tf.Tensor4D, params: ConvWithBatchNorm): tf.Tensor4D; 4 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/convWithBatchNorm.js: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { leaky } from './leaky'; 3 | export function convWithBatchNorm(x, params) { 4 | return tf.tidy(function () { 5 | var out = tf.pad(x, [[0, 0], [1, 1], [1, 1], [0, 0]]); 6 | out = tf.conv2d(out, params.conv.filters, [1, 1], 'valid'); 7 | out = tf.sub(out, params.bn.sub); 8 | out = tf.mul(out, params.bn.truediv); 9 | out = tf.add(out, params.conv.bias); 10 | return leaky(out); 11 | }); 12 | } 13 | //# sourceMappingURL=convWithBatchNorm.js.map -------------------------------------------------------------------------------- /build/es6/tinyYolov2/convWithBatchNorm.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"convWithBatchNorm.js","sourceRoot":"","sources":["../../../src/tinyYolov2/convWithBatchNorm.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAGhC,MAAM,4BAA4B,CAAc,EAAE,MAAyB;IACzE,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAI,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAgB,CAAA;QAEpE,GAAG,GAAG,EAAE,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;QAC1D,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;QAChC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,OAAO,CAAC,CAAA;QACpC,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEnC,OAAO,KAAK,CAAC,GAAG,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/depthwiseSeparableConv.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { SeparableConvParams } from '../common/types'; 3 | export declare function depthwiseSeparableConv(x: tf.Tensor4D, params: SeparableConvParams): tf.Tensor4D; 4 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/depthwiseSeparableConv.js: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { leaky } from './leaky'; 3 | export function depthwiseSeparableConv(x, params) { 4 | return tf.tidy(function () { 5 | var out = tf.pad(x, [[0, 0], [1, 1], [1, 1], [0, 0]]); 6 | out = tf.separableConv2d(out, params.depthwise_filter, params.pointwise_filter, [1, 1], 'valid'); 7 | out = tf.add(out, params.bias); 8 | return leaky(out); 9 | }); 10 | } 11 | //# sourceMappingURL=depthwiseSeparableConv.js.map -------------------------------------------------------------------------------- /build/es6/tinyYolov2/depthwiseSeparableConv.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"depthwiseSeparableConv.js","sourceRoot":"","sources":["../../../src/tinyYolov2/depthwiseSeparableConv.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAG5C,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAEhC,MAAM,iCAAiC,CAAc,EAAE,MAA2B;IAChF,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAI,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAgB,CAAA;QAEpE,GAAG,GAAG,EAAE,CAAC,eAAe,CAAC,GAAG,EAAE,MAAM,CAAC,gBAAgB,EAAE,MAAM,CAAC,gBAAgB,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,CAAA;QAChG,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;QAE9B,OAAO,KAAK,CAAC,GAAG,CAAC,CAAA;IACnB,CAAC,CAAC,CAAA;AACJ,CAAC"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/extractParams.d.ts: -------------------------------------------------------------------------------- 1 | import { ParamMapping } from 'tfjs-image-recognition-base'; 2 | import { TinyYolov2Config } from './config'; 3 | import { TinyYolov2NetParams } from './types'; 4 | export declare function extractParams(weights: Float32Array, config: TinyYolov2Config, boxEncodingSize: number, filterSizes: number[]): { 5 | params: TinyYolov2NetParams; 6 | paramMappings: ParamMapping[]; 7 | }; 8 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/extractParams.js: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { extractWeightsFactory } from 'tfjs-image-recognition-base'; 3 | import { extractConvParamsFactory } from '../common'; 4 | import { extractSeparableConvParamsFactory } from '../common/extractSeparableConvParamsFactory'; 5 | function extractorsFactory(extractWeights, paramMappings) { 6 | var extractConvParams = extractConvParamsFactory(extractWeights, paramMappings); 7 | function extractBatchNormParams(size, mappedPrefix) { 8 | var sub = tf.tensor1d(extractWeights(size)); 9 | var truediv = tf.tensor1d(extractWeights(size)); 10 | paramMappings.push({ paramPath: mappedPrefix + "/sub" }, { paramPath: mappedPrefix + "/truediv" }); 11 | return { sub: sub, truediv: truediv }; 12 | } 13 | function extractConvWithBatchNormParams(channelsIn, channelsOut, mappedPrefix) { 14 | var conv = extractConvParams(channelsIn, channelsOut, 3, mappedPrefix + "/conv"); 15 | var bn = extractBatchNormParams(channelsOut, mappedPrefix + "/bn"); 16 | return { conv: conv, bn: bn }; 17 | } 18 | var extractSeparableConvParams = extractSeparableConvParamsFactory(extractWeights, paramMappings); 19 | return { 20 | extractConvParams: extractConvParams, 21 | extractConvWithBatchNormParams: extractConvWithBatchNormParams, 22 | extractSeparableConvParams: extractSeparableConvParams 23 | }; 24 | } 25 | export function extractParams(weights, config, boxEncodingSize, filterSizes) { 26 | var _a = extractWeightsFactory(weights), extractWeights = _a.extractWeights, getRemainingWeights = _a.getRemainingWeights; 27 | var paramMappings = []; 28 | var _b = extractorsFactory(extractWeights, paramMappings), extractConvParams = _b.extractConvParams, extractConvWithBatchNormParams = _b.extractConvWithBatchNormParams, extractSeparableConvParams = _b.extractSeparableConvParams; 29 | var params; 30 | if (config.withSeparableConvs) { 31 | var s0 = filterSizes[0], s1 = filterSizes[1], s2 = filterSizes[2], s3 = filterSizes[3], s4 = filterSizes[4], s5 = filterSizes[5], s6 = filterSizes[6], s7 = filterSizes[7], s8 = filterSizes[8]; 32 | var conv0 = config.isFirstLayerConv2d 33 | ? extractConvParams(s0, s1, 3, 'conv0') 34 | : extractSeparableConvParams(s0, s1, 'conv0'); 35 | var conv1 = extractSeparableConvParams(s1, s2, 'conv1'); 36 | var conv2 = extractSeparableConvParams(s2, s3, 'conv2'); 37 | var conv3 = extractSeparableConvParams(s3, s4, 'conv3'); 38 | var conv4 = extractSeparableConvParams(s4, s5, 'conv4'); 39 | var conv5 = extractSeparableConvParams(s5, s6, 'conv5'); 40 | var conv6 = s7 ? extractSeparableConvParams(s6, s7, 'conv6') : undefined; 41 | var conv7 = s8 ? extractSeparableConvParams(s7, s8, 'conv7') : undefined; 42 | var conv8 = extractConvParams(s8 || s7 || s6, 5 * boxEncodingSize, 1, 'conv8'); 43 | params = { conv0: conv0, conv1: conv1, conv2: conv2, conv3: conv3, conv4: conv4, conv5: conv5, conv6: conv6, conv7: conv7, conv8: conv8 }; 44 | } 45 | else { 46 | var s0 = filterSizes[0], s1 = filterSizes[1], s2 = filterSizes[2], s3 = filterSizes[3], s4 = filterSizes[4], s5 = filterSizes[5], s6 = filterSizes[6], s7 = filterSizes[7], s8 = filterSizes[8]; 47 | var conv0 = extractConvWithBatchNormParams(s0, s1, 'conv0'); 48 | var conv1 = extractConvWithBatchNormParams(s1, s2, 'conv1'); 49 | var conv2 = extractConvWithBatchNormParams(s2, s3, 'conv2'); 50 | var conv3 = extractConvWithBatchNormParams(s3, s4, 'conv3'); 51 | var conv4 = extractConvWithBatchNormParams(s4, s5, 'conv4'); 52 | var conv5 = extractConvWithBatchNormParams(s5, s6, 'conv5'); 53 | var conv6 = extractConvWithBatchNormParams(s6, s7, 'conv6'); 54 | var conv7 = extractConvWithBatchNormParams(s7, s8, 'conv7'); 55 | var conv8 = extractConvParams(s8, 5 * boxEncodingSize, 1, 'conv8'); 56 | params = { conv0: conv0, conv1: conv1, conv2: conv2, conv3: conv3, conv4: conv4, conv5: conv5, conv6: conv6, conv7: conv7, conv8: conv8 }; 57 | } 58 | if (getRemainingWeights().length !== 0) { 59 | throw new Error("weights remaing after extract: " + getRemainingWeights().length); 60 | } 61 | return { params: params, paramMappings: paramMappings }; 62 | } 63 | //# sourceMappingURL=extractParams.js.map -------------------------------------------------------------------------------- /build/es6/tinyYolov2/extractParams.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extractParams.js","sourceRoot":"","sources":["../../../src/tinyYolov2/extractParams.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAwC,MAAM,6BAA6B,CAAC;AAE1G,OAAO,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AACrD,OAAO,EAAE,iCAAiC,EAAE,MAAM,6CAA6C,CAAC;AAIhG,2BAA2B,cAAsC,EAAE,aAA6B;IAE9F,IAAM,iBAAiB,GAAG,wBAAwB,CAAC,cAAc,EAAE,aAAa,CAAC,CAAA;IAEjF,gCAAgC,IAAY,EAAE,YAAoB;QAEhE,IAAM,GAAG,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAA;QAC7C,IAAM,OAAO,GAAG,EAAE,CAAC,QAAQ,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAA;QAEjD,aAAa,CAAC,IAAI,CAChB,EAAE,SAAS,EAAK,YAAY,SAAM,EAAE,EACpC,EAAE,SAAS,EAAK,YAAY,aAAU,EAAE,CACzC,CAAA;QAED,OAAO,EAAE,GAAG,KAAA,EAAE,OAAO,SAAA,EAAE,CAAA;IACzB,CAAC;IAED,wCAAwC,UAAkB,EAAE,WAAmB,EAAE,YAAoB;QAEnG,IAAM,IAAI,GAAG,iBAAiB,CAAC,UAAU,EAAE,WAAW,EAAE,CAAC,EAAK,YAAY,UAAO,CAAC,CAAA;QAClF,IAAM,EAAE,GAAG,sBAAsB,CAAC,WAAW,EAAK,YAAY,QAAK,CAAC,CAAA;QAEpE,OAAO,EAAE,IAAI,MAAA,EAAE,EAAE,IAAA,EAAE,CAAA;IACrB,CAAC;IACD,IAAM,0BAA0B,GAAG,iCAAiC,CAAC,cAAc,EAAE,aAAa,CAAC,CAAA;IAEnG,OAAO;QACL,iB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,EAAE,OAAO,CAAC,CAAA;QAC7D,IAAM,KAAK,GAAG,iBAAiB,CAAC,EAAE,EAAE,CAAC,GAAG,eAAe,EAAE,CAAC,EAAE,OAAO,CAAC,CAAA;QACpE,MAAM,GAAG,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,KAAK,OAAA,EAAE,CAAA;KAC3E;IAED,IAAI,mBAAmB,EAAE,CAAC,MAAM,KAAK,CAAC,EAAE;QACtC,MAAM,IAAI,KAAK,CAAC,oCAAkC,mBAAmB,EAAE,CAAC,MAAQ,CAAC,CAAA;KAClF;IAGD,OAAO,EAAE,MAAM,QAAA,EAAE,aAAa,eAAA,EAAE,CAAA;AAClC,CAAC"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/extractParamsFromWeigthMap.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { ParamMapping } from 'tfjs-image-recognition-base'; 3 | import { TinyYolov2Config } from './config'; 4 | import { TinyYolov2NetParams } from './types'; 5 | export declare function extractParamsFromWeigthMap(weightMap: tf.NamedTensorMap, config: TinyYolov2Config): { 6 | params: TinyYolov2NetParams; 7 | paramMappings: ParamMapping[]; 8 | }; 9 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/extractParamsFromWeigthMap.js: -------------------------------------------------------------------------------- 1 | import { disposeUnusedWeightTensors, extractWeightEntryFactory } from 'tfjs-image-recognition-base'; 2 | import { loadSeparableConvParamsFactory } from '../common/extractSeparableConvParamsFactory'; 3 | function extractorsFactory(weightMap, paramMappings) { 4 | var extractWeightEntry = extractWeightEntryFactory(weightMap, paramMappings); 5 | function extractBatchNormParams(prefix) { 6 | var sub = extractWeightEntry(prefix + "/sub", 1); 7 | var truediv = extractWeightEntry(prefix + "/truediv", 1); 8 | return { sub: sub, truediv: truediv }; 9 | } 10 | function extractConvParams(prefix) { 11 | var filters = extractWeightEntry(prefix + "/filters", 4); 12 | var bias = extractWeightEntry(prefix + "/bias", 1); 13 | return { filters: filters, bias: bias }; 14 | } 15 | function extractConvWithBatchNormParams(prefix) { 16 | var conv = extractConvParams(prefix + "/conv"); 17 | var bn = extractBatchNormParams(prefix + "/bn"); 18 | return { conv: conv, bn: bn }; 19 | } 20 | var extractSeparableConvParams = loadSeparableConvParamsFactory(extractWeightEntry); 21 | return { 22 | extractConvParams: extractConvParams, 23 | extractConvWithBatchNormParams: extractConvWithBatchNormParams, 24 | extractSeparableConvParams: extractSeparableConvParams 25 | }; 26 | } 27 | export function extractParamsFromWeigthMap(weightMap, config) { 28 | var paramMappings = []; 29 | var _a = extractorsFactory(weightMap, paramMappings), extractConvParams = _a.extractConvParams, extractConvWithBatchNormParams = _a.extractConvWithBatchNormParams, extractSeparableConvParams = _a.extractSeparableConvParams; 30 | var params; 31 | if (config.withSeparableConvs) { 32 | var numFilters = (config.filterSizes && config.filterSizes.length || 9); 33 | params = { 34 | conv0: config.isFirstLayerConv2d ? extractConvParams('conv0') : extractSeparableConvParams('conv0'), 35 | conv1: extractSeparableConvParams('conv1'), 36 | conv2: extractSeparableConvParams('conv2'), 37 | conv3: extractSeparableConvParams('conv3'), 38 | conv4: extractSeparableConvParams('conv4'), 39 | conv5: extractSeparableConvParams('conv5'), 40 | conv6: numFilters > 7 ? extractSeparableConvParams('conv6') : undefined, 41 | conv7: numFilters > 8 ? extractSeparableConvParams('conv7') : undefined, 42 | conv8: extractConvParams('conv8') 43 | }; 44 | } 45 | else { 46 | params = { 47 | conv0: extractConvWithBatchNormParams('conv0'), 48 | conv1: extractConvWithBatchNormParams('conv1'), 49 | conv2: extractConvWithBatchNormParams('conv2'), 50 | conv3: extractConvWithBatchNormParams('conv3'), 51 | conv4: extractConvWithBatchNormParams('conv4'), 52 | conv5: extractConvWithBatchNormParams('conv5'), 53 | conv6: extractConvWithBatchNormParams('conv6'), 54 | conv7: extractConvWithBatchNormParams('conv7'), 55 | conv8: extractConvParams('conv8') 56 | }; 57 | } 58 | disposeUnusedWeightTensors(weightMap, paramMappings); 59 | return { params: params, paramMappings: paramMappings }; 60 | } 61 | //# sourceMappingURL=extractParamsFromWeigthMap.js.map -------------------------------------------------------------------------------- /build/es6/tinyYolov2/extractParamsFromWeigthMap.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"extractParamsFromWeigthMap.js","sourceRoot":"","sources":["../../../src/tinyYolov2/extractParamsFromWeigthMap.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,yBAAyB,EAAgB,MAAM,6BAA6B,CAAC;AAGlH,OAAO,EAAE,8BAA8B,EAAE,MAAM,6CAA6C,CAAC;AAI7F,2BAA2B,SAAc,EAAE,aAA6B;IAEtE,IAAM,kBAAkB,GAAG,yBAAyB,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;IAE9E,gCAAgC,MAAc;QAC5C,IAAM,GAAG,GAAG,kBAAkB,CAAiB,MAAM,SAAM,EAAE,CAAC,CAAC,CAAA;QAC/D,IAAM,OAAO,GAAG,kBAAkB,CAAiB,MAAM,aAAU,EAAE,CAAC,CAAC,CAAA;QACvE,OAAO,EAAE,GAAG,KAAA,EAAE,OAAO,SAAA,EAAE,CAAA;IACzB,CAAC;IAED,2BAA2B,MAAc;QACvC,IAAM,OAAO,GAAG,kBAAkB,CAAiB,MAAM,aAAU,EAAE,CAAC,CAAC,CAAA;QACvE,IAAM,IAAI,GAAG,kBAAkB,CAAiB,MAAM,UAAO,EAAE,CAAC,CAAC,CAAA;QACjE,OAAO,EAAE,OAAO,SAAA,EAAE,IAAI,MAAA,EAAE,CAAA;IAC1B,CAAC;IAED,wCAAwC,MAAc;QACpD,IAAM,IAAI,GAAG,iBAAiB,CAAI,MAAM,UAAO,CAAC,CAAA;QAChD,IAAM,EAAE,GAAG,sBAAsB,CAAI,MAAM,QAAK,CAAC,CAAA;QACjD,OAAO,E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BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,8BAA8B,CAAC,OAAO,CAAC;YAC9C,KAAK,EAAE,iBAAiB,CAAC,OAAO,CAAC;SAClC,CAAA;KACF;IAED,0BAA0B,CAAC,SAAS,EAAE,aAAa,CAAC,CAAA;IAEpD,OAAO,EAAE,MAAM,QAAA,EAAE,aAAa,eAAA,EAAE,CAAA;AAClC,CAAC"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/getDefaultBackwardOptions.d.ts: -------------------------------------------------------------------------------- 1 | import { TinyYolov2BackwardOptions } from './types'; 2 | export declare function getDefaultBackwardOptions(options: TinyYolov2BackwardOptions): { 3 | minBoxSize: number; 4 | } & TinyYolov2BackwardOptions; 5 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/getDefaultBackwardOptions.js: -------------------------------------------------------------------------------- 1 | import { CELL_SIZE } from './const'; 2 | export function getDefaultBackwardOptions(options) { 3 | return Object.assign({}, { 4 | minBoxSize: CELL_SIZE 5 | }, options); 6 | } 7 | //# sourceMappingURL=getDefaultBackwardOptions.js.map -------------------------------------------------------------------------------- /build/es6/tinyYolov2/getDefaultBackwardOptions.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"getDefaultBackwardOptions.js","sourceRoot":"","sources":["../../../src/tinyYolov2/getDefaultBackwardOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,MAAM,oCAAoC,OAAkC;IAC1E,OAAO,MAAM,CAAC,MAAM,CAClB,EAAE,EACF;QACE,UAAU,EAAE,SAAS;KACtB,EACD,OAAO,CACR,CAAA;AACH,CAAC"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/index.d.ts: -------------------------------------------------------------------------------- 1 | export * from './TinyYolov2'; 2 | export * from './TinyYolov2LossFunction'; 3 | export * from './TinyYolov2Trainable'; 4 | export * from './TinyYolov2Options'; 5 | export { TinyYolov2NetParams } from './types'; 6 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/index.js: -------------------------------------------------------------------------------- 1 | export * from './TinyYolov2'; 2 | export * from './TinyYolov2LossFunction'; 3 | export * from './TinyYolov2Trainable'; 4 | export * from './TinyYolov2Options'; 5 | //# sourceMappingURL=index.js.map -------------------------------------------------------------------------------- /build/es6/tinyYolov2/index.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tinyYolov2/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/leaky.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | export declare function leaky(x: tf.Tensor4D): tf.Tensor4D; 3 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/leaky.js: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | export function leaky(x) { 3 | return tf.tidy(function () { 4 | var min = tf.mul(x, tf.scalar(0.10000000149011612)); 5 | return tf.add(tf.relu(tf.sub(x, min)), min); 6 | //return tf.maximum(x, min) 7 | }); 8 | } 9 | //# sourceMappingURL=leaky.js.map -------------------------------------------------------------------------------- /build/es6/tinyYolov2/leaky.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"leaky.js","sourceRoot":"","sources":["../../../src/tinyYolov2/leaky.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,uBAAuB,CAAC;AAE5C,MAAM,gBAAgB,CAAc;IAClC,OAAO,EAAE,CAAC,IAAI,CAAC;QACb,IAAM,GAAG,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC,CAAA;QACrD,OAAO,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,GAAG,CAAC,CAAA;QAC3C,2BAA2B;IAC7B,CAAC,CAAC,CAAA;AACJ,CAAC"} -------------------------------------------------------------------------------- /build/es6/tinyYolov2/types.d.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { Box, IRect } from 'tfjs-image-recognition-base'; 3 | import { ConvParams } from '../common'; 4 | import { SeparableConvParams } from '../common/types'; 5 | export declare type BatchNorm = { 6 | sub: tf.Tensor1D; 7 | truediv: tf.Tensor1D; 8 | }; 9 | export declare type ConvWithBatchNorm = { 10 | conv: ConvParams; 11 | bn: BatchNorm; 12 | }; 13 | export declare type MobilenetParams = { 14 | conv0: SeparableConvParams | ConvParams; 15 | conv1: SeparableConvParams; 16 | conv2: SeparableConvParams; 17 | conv3: SeparableConvParams; 18 | conv4: SeparableConvParams; 19 | conv5: SeparableConvParams; 20 | conv6?: SeparableConvParams; 21 | conv7?: SeparableConvParams; 22 | conv8: ConvParams; 23 | }; 24 | export declare type DefaultTinyYolov2NetParams = { 25 | conv0: ConvWithBatchNorm; 26 | conv1: ConvWithBatchNorm; 27 | conv2: ConvWithBatchNorm; 28 | conv3: ConvWithBatchNorm; 29 | conv4: ConvWithBatchNorm; 30 | conv5: ConvWithBatchNorm; 31 | conv6: ConvWithBatchNorm; 32 | conv7: ConvWithBatchNorm; 33 | conv8: ConvParams; 34 | }; 35 | export declare type TinyYolov2NetParams = DefaultTinyYolov2NetParams | MobilenetParams; 36 | export declare type GridPosition = { 37 | row: number; 38 | col: number; 39 | anchor: number; 40 | }; 41 | export declare type GroundTruthWithGridPosition = GridPosition & { 42 | box: Box; 43 | label: number; 44 | }; 45 | export declare type GroundTruth = IRect & { 46 | label: number; 47 | }; 48 | export declare type YoloLoss = { 49 | totalLoss: number; 50 | noObjectLoss: number; 51 | objectLoss: number; 52 | coordLoss: number; 53 | classLoss: number; 54 | }; 55 | export declare type LossReport = { 56 | losses: YoloLoss; 57 | numBoxes: number; 58 | inputSize: number; 59 | }; 60 | export declare type TinyYolov2BackwardOptions = { 61 | minBoxSize?: number; 62 | reportLosses?: (report: LossReport) => void; 63 | }; 64 | -------------------------------------------------------------------------------- /build/es6/tinyYolov2/types.js: -------------------------------------------------------------------------------- 1 | //# sourceMappingURL=types.js.map -------------------------------------------------------------------------------- /build/es6/tinyYolov2/types.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/tinyYolov2/types.ts"],"names":[],"mappings":""} -------------------------------------------------------------------------------- /examples/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "start": "node server.js" 4 | }, 5 | "author": "justadudewhohacks", 6 | "license": "MIT", 7 | "dependencies": { 8 | "express": "^4.16.3", 9 | "request": "^2.87.0" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /examples/public/commons.js: -------------------------------------------------------------------------------- 1 | function getImageUri(imageName) { 2 | return `images/${imageName}` 3 | } 4 | 5 | async function fetchImage(uri) { 6 | return (await fetch(uri)).blob() 7 | } 8 | 9 | async function fetchJson(uri) { 10 | return (await fetch(uri)).json() 11 | } 12 | 13 | async function loadNetWeights(uri) { 14 | return new Float32Array(await (await fetch(uri)).arrayBuffer()) 15 | } 16 | 17 | async function requestExternalImage(imageUrl) { 18 | const res = await fetch('fetch_external_image', { 19 | method: 'post', 20 | headers: { 21 | 'content-type': 'application/json' 22 | }, 23 | body: JSON.stringify({ imageUrl }) 24 | }) 25 | if (!(res.status < 400)) { 26 | console.error(res.status + ' : ' + await res.text()) 27 | throw new Error('failed to fetch image from url: ' + imageUrl) 28 | } 29 | 30 | let blob 31 | try { 32 | blob = await res.blob() 33 | return await yolo.bufferToImage(blob) 34 | } catch (e) { 35 | console.error('received blob:', blob) 36 | console.error('error:', e) 37 | throw new Error('failed to load image from url: ' + imageUrl) 38 | } 39 | } 40 | 41 | function renderSelectList(selectListId, onChange, initialValue, renderChildren) { 42 | const select = document.createElement('select') 43 | $(selectListId).get(0).appendChild(select) 44 | renderChildren(select) 45 | $(select).val(initialValue) 46 | $(select).on('change', (e) => onChange(e.target.value)) 47 | $(select).material_select() 48 | } 49 | 50 | function renderOption(parent, text, value) { 51 | const option = document.createElement('option') 52 | option.innerHTML = text 53 | option.value = value 54 | parent.appendChild(option) 55 | } 56 | 57 | function renderImageSelectList(selectListId, onChange, values, initialValue) { 58 | function renderChildren(select) { 59 | values.forEach(imageUri => { 60 | let imageName = imageUri.split('/') 61 | imageName = imageName[imageName.length - 1] 62 | renderOption( 63 | select, 64 | imageName, 65 | imageUri 66 | ) 67 | }) 68 | } 69 | 70 | renderSelectList( 71 | selectListId, 72 | onChange, 73 | initialValue, 74 | renderChildren 75 | ) 76 | } 77 | 78 | function renderNavBar(navbarId, exampleUri) { 79 | const examples = [ 80 | { 81 | uri: 'voc_object_detection', 82 | name: 'VOC Object Detection' 83 | }, 84 | { 85 | uri: 'coco_object_detection', 86 | name: 'COCO Object Detection' 87 | }, 88 | { 89 | uri: 'face_detection', 90 | name: 'Face Detection' 91 | } 92 | ] 93 | 94 | const navbar = $(navbarId).get(0) 95 | const pageContainer = $('.page-container').get(0) 96 | 97 | const header = document.createElement('h3') 98 | header.innerHTML = examples.find(ex => ex.uri === exampleUri).name 99 | pageContainer.insertBefore(header, pageContainer.children[0]) 100 | 101 | const menuContent = document.createElement('ul') 102 | menuContent.id = 'slide-out' 103 | menuContent.classList.add('side-nav', 'fixed') 104 | navbar.appendChild(menuContent) 105 | 106 | const menuButton = document.createElement('a') 107 | menuButton.href='#' 108 | menuButton.classList.add('button-collapse', 'show-on-large') 109 | menuButton.setAttribute('data-activates', 'slide-out') 110 | const menuButtonIcon = document.createElement('img') 111 | menuButtonIcon.src = 'menu_icon.png' 112 | menuButton.appendChild(menuButtonIcon) 113 | navbar.appendChild(menuButton) 114 | 115 | const li = document.createElement('li') 116 | const githubLink = document.createElement('a') 117 | githubLink.classList.add('waves-effect', 'waves-light', 'side-by-side') 118 | githubLink.id = 'github-link' 119 | githubLink.href = 'https://github.com/justadudewhohacks/tfjs-tiny-yolo-v2' 120 | const h5 = document.createElement('h5') 121 | h5.innerHTML = 'tfjs-tiny-yolo-v2' 122 | h5.style.whiteSpace = 'nowrap' 123 | githubLink.appendChild(h5) 124 | const githubLinkIcon = document.createElement('img') 125 | githubLinkIcon.src = 'github_link_icon.png' 126 | githubLink.appendChild(githubLinkIcon) 127 | li.appendChild(githubLink) 128 | menuContent.appendChild(li) 129 | 130 | examples 131 | .forEach(ex => { 132 | const li = document.createElement('li') 133 | if (ex.uri === exampleUri) { 134 | li.style.background='#b0b0b0' 135 | } 136 | const a = document.createElement('a') 137 | a.classList.add('waves-effect', 'waves-light') 138 | a.href = ex.uri 139 | const span = document.createElement('span') 140 | span.innerHTML = ex.name 141 | span.style.whiteSpace = 'nowrap' 142 | a.appendChild(span) 143 | li.appendChild(a) 144 | menuContent.appendChild(li) 145 | }) 146 | 147 | $('.button-collapse').sideNav({ 148 | menuWidth: 280 149 | }) 150 | } -------------------------------------------------------------------------------- /examples/public/github_link_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/github_link_icon.png -------------------------------------------------------------------------------- /examples/public/images/face_detection/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/images/face_detection/1.jpg -------------------------------------------------------------------------------- /examples/public/images/face_detection/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/images/face_detection/2.jpg -------------------------------------------------------------------------------- /examples/public/images/face_detection/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/images/face_detection/3.jpg -------------------------------------------------------------------------------- /examples/public/images/face_detection/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/images/face_detection/4.jpg -------------------------------------------------------------------------------- /examples/public/images/face_detection/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/images/face_detection/5.jpg -------------------------------------------------------------------------------- /examples/public/images/object_detection/1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/images/object_detection/1.jpg -------------------------------------------------------------------------------- /examples/public/images/object_detection/2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/images/object_detection/2.jpg -------------------------------------------------------------------------------- /examples/public/images/object_detection/3.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/images/object_detection/3.jpg -------------------------------------------------------------------------------- /examples/public/images/object_detection/4.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/images/object_detection/4.jpg -------------------------------------------------------------------------------- /examples/public/images/object_detection/5.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/images/object_detection/5.jpg -------------------------------------------------------------------------------- /examples/public/images/object_detection/6.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/images/object_detection/6.jpg -------------------------------------------------------------------------------- /examples/public/menu_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/examples/public/menu_icon.png -------------------------------------------------------------------------------- /examples/public/styles.css: -------------------------------------------------------------------------------- 1 | .page-container { 2 | left: 0; 3 | right: 0; 4 | margin: auto; 5 | margin-top: 20px; 6 | padding-left: 300px; 7 | display: inline-flex !important; 8 | } 9 | 10 | @media only screen and (max-width : 992px) { 11 | .page-container { 12 | padding-left: 0; 13 | display: flex !important; 14 | } 15 | } 16 | 17 | #navbar { 18 | position: absolute; 19 | top: 20px; 20 | left: 20px; 21 | } 22 | 23 | .center-content { 24 | display: flex; 25 | flex-direction: column; 26 | justify-content: center; 27 | align-items: center; 28 | flex-wrap: wrap; 29 | } 30 | 31 | .side-by-side { 32 | display: flex; 33 | justify-content: center; 34 | align-items: center; 35 | } 36 | .side-by-side >* { 37 | margin: 0 5px; 38 | } 39 | 40 | .bold { 41 | font-weight: bold; 42 | } 43 | 44 | .margin-sm { 45 | margin: 5px; 46 | } 47 | 48 | .margin { 49 | margin: 20px; 50 | } 51 | 52 | .button-sm { 53 | padding: 0 10px !important; 54 | } 55 | 56 | #github-link { 57 | display: flex !important; 58 | justify-content: center; 59 | align-items: center; 60 | border-bottom: 1px solid; 61 | margin-bottom: 10px; 62 | } 63 | 64 | #overlay { 65 | position: absolute; 66 | top: 0; 67 | left: 0; 68 | } 69 | 70 | #facesContainer canvas { 71 | margin: 10px; 72 | } -------------------------------------------------------------------------------- /examples/server.js: -------------------------------------------------------------------------------- 1 | const express = require('express') 2 | const path = require('path') 3 | const { get } = require('request') 4 | 5 | const app = express() 6 | 7 | app.use(express.json()) 8 | app.use(express.urlencoded({ extended: true })) 9 | 10 | const viewsDir = path.join(__dirname, 'views') 11 | app.use(express.static(viewsDir)) 12 | app.use(express.static(path.join(__dirname, './public'))) 13 | app.use(express.static(path.join(__dirname, '../models'))) 14 | app.use(express.static(path.join(__dirname, '../dist'))) 15 | 16 | app.get('/', (req, res) => res.redirect('/voc_object_detection')) 17 | app.get('/voc_object_detection', (req, res) => res.sendFile(path.join(viewsDir, 'vocObjectDetection.html'))) 18 | app.get('/coco_object_detection', (req, res) => res.sendFile(path.join(viewsDir, 'cocoObjectDetection.html'))) 19 | app.get('/face_detection', (req, res) => res.sendFile(path.join(viewsDir, 'faceDetection.html'))) 20 | 21 | app.post('/fetch_external_image', async (req, res) => { 22 | const { imageUrl } = req.body 23 | if (!imageUrl) { 24 | return res.status(400).send('imageUrl param required') 25 | } 26 | try { 27 | const externalResponse = await request(imageUrl) 28 | res.set('content-type', externalResponse.headers['content-type']) 29 | return res.status(202).send(Buffer.from(externalResponse.body)) 30 | } catch (err) { 31 | return res.status(404).send(err.toString()) 32 | } 33 | }) 34 | 35 | app.listen(3000, () => console.log('Listening on port 3000!')) 36 | 37 | function request(url, returnBuffer = true, timeout = 10000) { 38 | return new Promise(function(resolve, reject) { 39 | const options = Object.assign( 40 | {}, 41 | { 42 | url, 43 | isBuffer: true, 44 | timeout, 45 | headers: { 46 | 'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36' 47 | } 48 | }, 49 | returnBuffer ? { encoding: null } : {} 50 | ) 51 | 52 | get(options, function(err, res) { 53 | if (err) return reject(err) 54 | return resolve(res) 55 | }) 56 | }) 57 | } -------------------------------------------------------------------------------- /examples/views/cocoObjectDetection.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 |
18 | 19 | 20 |
21 |
22 |
23 |
24 | 25 | 26 |
27 | 33 |
34 |
35 |
36 | 43 | 44 |
45 |
46 | 47 | 48 |
49 | 55 | 61 |
62 |
63 | 64 | 144 | 145 | -------------------------------------------------------------------------------- /examples/views/faceDetection.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 |
18 | 19 | 20 |
21 |
22 |
23 |
24 | 25 | 26 |
27 | 33 |
34 |
35 |
36 | 43 | 44 |
45 |
46 | 47 | 48 |
49 | 55 | 61 |
62 |
63 | 64 | 144 | 145 | -------------------------------------------------------------------------------- /examples/views/vocObjectDetection.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 |
18 | 19 | 20 |
21 |
22 |
23 |
24 | 25 | 26 |
27 | 33 |
34 |
35 |
36 | 43 | 44 |
45 |
46 | 47 | 48 |
49 | 55 | 61 |
62 |
63 | 64 | 144 | 145 | -------------------------------------------------------------------------------- /karma.conf.js: -------------------------------------------------------------------------------- 1 | const dataFiles = [ 2 | ].map(pattern => ({ 3 | pattern, 4 | watched: false, 5 | included: false, 6 | served: true, 7 | nocache: false 8 | })) 9 | 10 | module.exports = function(config) { 11 | config.set({ 12 | frameworks: ['jasmine', 'karma-typescript'], 13 | files: [ 14 | 'src/**/*.ts', 15 | 'test/**/*.ts' 16 | ].concat(dataFiles), 17 | preprocessors: { 18 | '**/*.ts': ['karma-typescript'] 19 | }, 20 | karmaTypescriptConfig: { 21 | tsconfig: 'tsconfig.test.json' 22 | }, 23 | browsers: process.env.KARMA_BROWSERS 24 | ? process.env.KARMA_BROWSERS.split(',') 25 | : ['Chrome'], 26 | browserNoActivityTimeout: 120000, 27 | captureTimeout: 60000, 28 | client: { 29 | jasmine: { 30 | timeoutInterval: 60000 31 | } 32 | }, 33 | customLaunchers: { 34 | ChromeNoSandbox: { 35 | base: 'Chrome', 36 | flags: ['--no-sandbox'] 37 | } 38 | } 39 | }) 40 | } 41 | -------------------------------------------------------------------------------- /models/coco_model-shard1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/models/coco_model-shard1 -------------------------------------------------------------------------------- /models/coco_model-shard2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/models/coco_model-shard2 -------------------------------------------------------------------------------- /models/coco_model-shard3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/models/coco_model-shard3 -------------------------------------------------------------------------------- /models/coco_model-weights_manifest.json: -------------------------------------------------------------------------------- 1 | [{"weights":[{"name":"conv0/conv/filters","shape":[3,3,3,16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.011227687199910482,"min":-1.4034608999888103}},{"name":"conv0/conv/bias","shape":[16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.04075822456210267,"min":-8.110886687858432}},{"name":"conv0/bn/sub","shape":[16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.003961804567598829,"min":-0.6933157993297951}},{"name":"conv0/bn/truediv","shape":[16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.08890059695524329,"min":3.744166135787964}},{"name":"conv1/conv/filters","shape":[3,3,16,32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.008739762212715897,"min":-1.2934848074819527}},{"name":"conv1/conv/bias","shape":[32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.013421327927533318,"min":-2.107148484622731}},{"name":"conv1/bn/sub","shape":[32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0802123368955126,"min":-12.673549229490991}},{"name":"conv1/bn/truediv","shape":[32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0020733264147066604,"min":0.17438730597496033}},{"name":"conv2/conv/filters","shape":[3,3,32,64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.009141019512625302,"min":-0.8592558341867784}},{"name":"conv2/conv/bias","shape":[64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.02747218842599906,"min":-4.642799843993841}},{"name":"conv2/bn/sub","shape":[64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.07064345303703756,"min":-11.444239392000085}},{"name":"conv2/bn/truediv","shape":[64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.00466110811514013,"min":0.29356715083122253}},{"name":"conv3/conv/filters","shape":[3,3,64,128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.006632709503173828,"min":-0.6632709503173828}},{"name":"conv3/conv/bias","shape":[128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.025126705683913887,"min":-5.678635484564539}},{"name":"conv3/bn/sub","shape":[128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.06612326491112802,"min":-10.976461975247252}},{"name":"conv3/bn/truediv","shape":[128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.003775325008467132,"min":0.4091604948043823}},{"name":"conv4/conv/filters","shape":[3,3,128,256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.005578470463846244,"min":-0.43512069618000704}},{"name":"conv4/conv/bias","shape":[256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.02095775510750565,"min":-5.00890347069385}},{"name":"conv4/bn/sub","shape":[256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.04735012241438323,"min":-5.682014689725988}},{"name":"conv4/bn/truediv","shape":[256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.003602779495949839,"min":0.4792077839374542}},{"name":"conv5/conv/filters","shape":[3,3,256,512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.005162689148211012,"min":-0.449153955894358}},{"name":"conv5/conv/bias","shape":[512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.023350540095684574,"min":-5.534078002677244}},{"name":"conv5/bn/sub","shape":[512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.02642957275989009,"min":-2.9865417218675803}},{"name":"conv5/bn/truediv","shape":[512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0055937476017895865,"min":0.36458805203437805}},{"name":"conv6/conv/filters","shape":[3,3,512,1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0022607706341088987,"min":-0.30746480623881023}},{"name":"conv6/conv/bias","shape":[1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.016120481491088866,"min":-5.771284103393555}},{"name":"conv6/bn/sub","shape":[1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.010448805023642148,"min":-1.1702661626479205}},{"name":"conv6/bn/truediv","shape":[1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.023905235178330365,"min":2.220590353012085}},{"name":"conv7/conv/filters","shape":[3,3,1024,512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0021607393727583043,"min":-0.3392360815230538}},{"name":"conv7/conv/bias","shape":[512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0050693973606708,"min":-0.3244414310829312}},{"name":"conv7/bn/sub","shape":[512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.027484004637774298,"min":-2.775884468415204}},{"name":"conv7/bn/truediv","shape":[512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0018514200460677053,"min":0.0702701285481453}},{"name":"conv8/filters","shape":[1,1,512,425],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0053151773471458285,"min":-0.807906956766166}},{"name":"conv8/bias","shape":[425],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.015736654225517722,"min":-2.218868245797999}}],"paths":["coco_model-shard1","coco_model-shard2","coco_model-shard3"]}] -------------------------------------------------------------------------------- /models/coco_model_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "withSeparableConvs": false, 3 | "iouThreshold": 0.4, 4 | "anchors": [ 5 | { "x": 0.57, "y": 0.68 }, 6 | { "x": 1.87, "y": 2.06 }, 7 | { "x": 3.34, "y": 5.47 }, 8 | { "x": 7.88, "y": 3.53 }, 9 | { "x": 9.77, "y": 9.17 } 10 | ], 11 | "classes": [ 12 | "person", "bicycle", "car", "motorbike", "aeroplane", 13 | "bus", "train", "truck", "boat", "traffic light", 14 | "fire hydrant", "stop sign", "parking meter", "bench", "bird", 15 | "cat", "dog", "horse", "sheep", "cow", 16 | "elephant", "bear", "zebra", "giraffe", "backpack", 17 | "umbrella" ,"handbag", "tie", "suitcase", "frisbee", 18 | "skis", "snowboard", "sports ball", "kite", "baseball bat", 19 | "baseball glove", "skateboard", "surfboard", "tennis racket", "bottle", 20 | "wine glass", "cup", "fork", "knife", "spoon", 21 | "bowl", "banana", "apple", "sandwich", "orange", 22 | "broccoli", "carrot", "hot dog", "pizza", "donut", 23 | "cake", "chair", "sofa", "pottedplant", "bed", 24 | "diningtable", "toilet", "tvmonitor", "laptop", "mouse", 25 | "remote", "keyboard", "cell phone", "microwave", "oven", 26 | "toaster", "sink", "refrigerator", "book", "clock", 27 | "vase", "scissors", "teddy bear", "hair drier", "toothbrush" 28 | ] 29 | } -------------------------------------------------------------------------------- /models/face_detection_model-shard1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/models/face_detection_model-shard1 -------------------------------------------------------------------------------- /models/face_detection_model-weights_manifest.json: -------------------------------------------------------------------------------- 1 | [{"weights":[{"name":"conv0/depthwise_filter","shape":[3,3,3,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.004699238725737029,"min":-0.7471789573921876}},{"name":"conv0/pointwise_filter","shape":[1,1,3,16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.008118405529097015,"min":-1.071629529840806}},{"name":"conv0/bias","shape":[16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0024678509609372006,"min":-0.28873856242965246}},{"name":"conv1/depthwise_filter","shape":[3,3,16,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.004553892331964829,"min":-0.5737904338275684}},{"name":"conv1/pointwise_filter","shape":[1,1,16,32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.00980057996862075,"min":-1.3230782957638012}},{"name":"conv1/bias","shape":[32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0011220066278588537,"min":-0.20644921952602907}},{"name":"conv2/depthwise_filter","shape":[3,3,32,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0032098570290733787,"min":-0.38839270051787883}},{"name":"conv2/pointwise_filter","shape":[1,1,32,64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.008682825051101984,"min":-1.154815731796564}},{"name":"conv2/bias","shape":[64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0015120926440930834,"min":-0.21471715546121783}},{"name":"conv3/depthwise_filter","shape":[3,3,64,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.003597520496331009,"min":-0.4317024595597211}},{"name":"conv3/pointwise_filter","shape":[1,1,64,128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.010341314240997913,"min":-1.3650534798117246}},{"name":"conv3/bias","shape":[128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.002109630785736383,"min":-0.4113780032185947}},{"name":"conv4/depthwise_filter","shape":[3,3,128,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.004783747476689955,"min":-0.6171034244930043}},{"name":"conv4/pointwise_filter","shape":[1,1,128,256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.009566552498761345,"min":-1.2627849298364977}},{"name":"conv4/bias","shape":[256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0020002245903015135,"min":-0.3860433459281921}},{"name":"conv5/depthwise_filter","shape":[3,3,256,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.004355777244941861,"min":-0.4791354969436047}},{"name":"conv5/pointwise_filter","shape":[1,1,256,512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.010036561068366555,"min":-1.2545701335458193}},{"name":"conv5/bias","shape":[512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0023248311935686597,"min":-0.42776893961663337}},{"name":"conv6/depthwise_filter","shape":[3,3,512,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.004659063442080629,"min":-0.5963601205863205}},{"name":"conv6/pointwise_filter","shape":[1,1,512,1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.010061494509379069,"min":-1.2576868136723836}},{"name":"conv6/bias","shape":[1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0029680932269376867,"min":-0.3947563991827123}},{"name":"conv7/depthwise_filter","shape":[3,3,1024,1],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.003887363508635876,"min":-0.48980780208812036}},{"name":"conv7/pointwise_filter","shape":[1,1,1024,1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.009973861189449535,"min":-1.2766542322495404}},{"name":"conv7/bias","shape":[1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.004667898486642276,"min":-0.6955168745096991}},{"name":"conv8/filters","shape":[1,1,1024,25],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.01573958116419175,"min":-2.5340725674348716}},{"name":"conv8/bias","shape":[25],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.009396760662396749,"min":-2.2552225589752197}}],"paths":["face_detection_model-shard1"]}] -------------------------------------------------------------------------------- /models/face_detection_model_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "withSeparableConvs": true, 3 | "iouThreshold": 0.4, 4 | "anchors": [ 5 | { "x": 1.603231, "y": 2.094468 }, 6 | { "x": 6.041143, "y": 7.080126 }, 7 | { "x": 2.882459, "y": 3.518061 }, 8 | { "x": 4.266906, "y": 5.178857 }, 9 | { "x": 9.041765, "y": 10.66308 } 10 | ], 11 | "classes": ["face"], 12 | "meanRgb": [117.001, 114.697, 97.404] 13 | } -------------------------------------------------------------------------------- /models/voc_model-shard1: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/models/voc_model-shard1 -------------------------------------------------------------------------------- /models/voc_model-shard2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/models/voc_model-shard2 -------------------------------------------------------------------------------- /models/voc_model-shard3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/models/voc_model-shard3 -------------------------------------------------------------------------------- /models/voc_model-shard4: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/justadudewhohacks/tfjs-tiny-yolov2/0ddad18731379ea214e0cfa0238b83b29dfbdb16/models/voc_model-shard4 -------------------------------------------------------------------------------- /models/voc_model-weights_manifest.json: -------------------------------------------------------------------------------- 1 | [{"weights":[{"name":"conv0/conv/filters","shape":[3,3,3,16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.007426351659438189,"min":-0.9877047707052792}},{"name":"conv0/conv/bias","shape":[16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.035724733390060125,"min":-6.680525143941243}},{"name":"conv0/bn/sub","shape":[16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0038174834905886183,"min":-0.290128745284735}},{"name":"conv0/bn/truediv","shape":[16],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.16335838355270085,"min":4.554934978485107}},{"name":"conv1/conv/filters","shape":[3,3,16,32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.005392294771531049,"min":-0.9220824059318093}},{"name":"conv1/conv/bias","shape":[32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.015471505651287003,"min":-2.3826118702981987}},{"name":"conv1/bn/sub","shape":[32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.060432755713369334,"min":-8.823182334151923}},{"name":"conv1/bn/truediv","shape":[32],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0034136923504810707,"min":0.24765677750110626}},{"name":"conv2/conv/filters","shape":[3,3,32,64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.004636397899365893,"min":-0.4682761878359552}},{"name":"conv2/conv/bias","shape":[64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.023580264577678606,"min":-4.197287094826792}},{"name":"conv2/bn/sub","shape":[64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.033199439329259534,"min":-5.0131153387181895}},{"name":"conv2/bn/truediv","shape":[64],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.010565236269258985,"min":0.5823931097984314}},{"name":"conv3/conv/filters","shape":[3,3,64,128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.003869555627598482,"min":-0.3908251183874467}},{"name":"conv3/conv/bias","shape":[128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.023621471138561473,"min":-5.598288659839069}},{"name":"conv3/bn/sub","shape":[128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.038176966648475794,"min":-5.153890497544232}},{"name":"conv3/bn/truediv","shape":[128],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.005379354252534754,"min":0.6950623989105225}},{"name":"conv4/conv/filters","shape":[3,3,128,256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.003175805363000608,"min":-0.2826466773070541}},{"name":"conv4/conv/bias","shape":[256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.019259587485416264,"min":-4.969756603240967}},{"name":"conv4/bn/sub","shape":[256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.022720872654634364,"min":-2.930992572447833}},{"name":"conv4/bn/truediv","shape":[256],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0064447440353094364,"min":0.7607946395874023}},{"name":"conv5/conv/filters","shape":[3,3,256,512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0024417561643263874,"min":-0.26370966574724986}},{"name":"conv5/conv/bias","shape":[512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.021392013570841622,"min":-5.4121794334229305}},{"name":"conv5/bn/sub","shape":[512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.011062789898292692,"min":-1.7036696443370745}},{"name":"conv5/bn/truediv","shape":[512],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.010622238177879184,"min":0.43005430698394775}},{"name":"conv6/conv/filters","shape":[3,3,512,1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.000941162950852338,"min":-0.11670420590568992}},{"name":"conv6/conv/bias","shape":[1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.01599158913481469,"min":-5.752869129180908}},{"name":"conv6/bn/sub","shape":[1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0033525523017434514,"min":-0.5162930544684915}},{"name":"conv6/bn/truediv","shape":[1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.03785188525330787,"min":3.051419734954834}},{"name":"conv7/conv/filters","shape":[3,3,1024,1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0003866200645764669,"min":-0.047167647878328965}},{"name":"conv7/conv/bias","shape":[1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.00030979972113581267,"min":-0.022615379642914324}},{"name":"conv7/bn/sub","shape":[1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.01670971290737975,"min":-1.8213587069043926}},{"name":"conv7/bn/truediv","shape":[1024],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.001588598185894536,"min":0.25779926776885986}},{"name":"conv8/filters","shape":[1,1,1024,125],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0016826132348939484,"min":-0.23556585288515278}},{"name":"conv8/bias","shape":[125],"dtype":"float32","quantization":{"dtype":"uint8","scale":0.0015116248937214122,"min":-0.2841854800196255}}],"paths":["voc_model-shard1","voc_model-shard2","voc_model-shard3","voc_model-shard4"]}] -------------------------------------------------------------------------------- /models/voc_model_config.json: -------------------------------------------------------------------------------- 1 | { 2 | "withSeparableConvs": false, 3 | "iouThreshold": 0.4, 4 | "anchors": [ 5 | { "x": 1.08, "y": 1.19 }, 6 | { "x": 3.42, "y": 4.41 }, 7 | { "x": 6.63, "y": 11.38 }, 8 | { "x": 9.42, "y": 5.11 }, 9 | { "x": 16.62, "y": 10.52 } 10 | ], 11 | "classes": [ 12 | "aeroplane", "bicycle", "bird", "boat", "bottle", 13 | "bus", "car", "cat", "chair", "cow", 14 | "diningtable", "dog", "horse", "motorbike", "person", 15 | "pottedplant", "sheep", "sofa", "train", "tvmonitor" 16 | ] 17 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "tfjs-tiny-yolov2", 3 | "version": "0.4.0", 4 | "description": "Tiny YOLO v2 object detection with tensorflow.js.", 5 | "module": "./build/es6/index.js", 6 | "main": "./build/commonjs/index.js", 7 | "typings": "./build/commonjs/index.d.ts", 8 | "scripts": { 9 | "rollup-min": "rollup -c rollup.config.js --environment minify:true", 10 | "rollup": "rollup -c rollup.config.js", 11 | "tsc": "tsc", 12 | "tsc-es6": "tsc --p tsconfig.es6.json", 13 | "build": "rm -rf ./build && rm -rf ./dist && npm run rollup && npm run rollup-min && npm run tsc && npm run tsc-es6", 14 | "test": "karma start", 15 | "test-travis": "set KARMA_BROWSERS=ChromeHeadlessNoSandbox&& karma start --single-run" 16 | }, 17 | "keywords": [ 18 | "tiny", 19 | "yolo", 20 | "tensorflow", 21 | "tf" 22 | ], 23 | "author": "justadudewhohacks", 24 | "license": "MIT", 25 | "dependencies": { 26 | "@tensorflow/tfjs-core": "0.14.2", 27 | "tfjs-image-recognition-base": "^0.3.0", 28 | "tslib": "^1.9.3" 29 | }, 30 | "devDependencies": { 31 | "@types/jasmine": "^2.8.8", 32 | "@types/node": "^10.12.12", 33 | "jasmine-core": "^3.2.1", 34 | "karma": "^3.0.0", 35 | "karma-chrome-launcher": "^2.2.0", 36 | "karma-jasmine": "^1.1.2", 37 | "karma-typescript": "^3.0.12", 38 | "rollup": "^0.65.0", 39 | "rollup-plugin-commonjs": "^9.1.6", 40 | "rollup-plugin-node-resolve": "^3.3.0", 41 | "rollup-plugin-typescript2": "^0.16.1", 42 | "rollup-plugin-uglify": "^4.0.0", 43 | "typescript": "2.8.4" 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /rollup.config.js: -------------------------------------------------------------------------------- 1 | import commonjs from 'rollup-plugin-commonjs'; 2 | import node from 'rollup-plugin-node-resolve'; 3 | import typescript from 'rollup-plugin-typescript2'; 4 | import { uglify } from 'rollup-plugin-uglify'; 5 | import path from 'path'; 6 | 7 | const { minify } = process.env 8 | 9 | export default { 10 | input: 'src/index.ts', 11 | plugins: [ 12 | typescript({ 13 | tsconfigOverride: { 14 | compilerOptions: { 15 | module: 'ES2015', 16 | declaration: false 17 | } 18 | } 19 | }), 20 | node(), 21 | commonjs({ 22 | include: 'node_modules/**' 23 | }) 24 | ].concat(minify ? uglify() : []), 25 | output: { 26 | extend: true, 27 | file: `dist/tiny-yolov2${minify ? '.min' : ''}.js`, 28 | format: 'umd', 29 | name: 'yolo', 30 | globals: { 31 | 'crypto': 'crypto' 32 | }, 33 | sourcemap: minify ? false : true 34 | }, 35 | external: ['crypto'], 36 | onwarn: (warning) => { 37 | const ignoreWarnings = ['CIRCULAR_DEPENDENCY', 'CIRCULAR', 'THIS_IS_UNDEFINED'] 38 | if (ignoreWarnings.some(w => w === warning.code)) 39 | return 40 | 41 | if (warning.missing === 'alea') 42 | return 43 | 44 | console.warn(warning.message) 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/common/convLayer.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | 3 | import { ConvParams } from './types'; 4 | 5 | export function convLayer( 6 | x: tf.Tensor4D, 7 | params: ConvParams, 8 | padding: 'valid' | 'same' = 'same', 9 | withRelu: boolean = false 10 | ): tf.Tensor4D { 11 | return tf.tidy(() => { 12 | const out = tf.add( 13 | tf.conv2d(x, params.filters, [1, 1], padding), 14 | params.bias 15 | ) as tf.Tensor4D 16 | 17 | return withRelu ? tf.relu(out) : out 18 | }) 19 | } -------------------------------------------------------------------------------- /src/common/extractConvParamsFactory.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { ExtractWeightsFunction, ParamMapping } from 'tfjs-image-recognition-base'; 3 | 4 | import { ConvParams } from './types'; 5 | 6 | export function extractConvParamsFactory( 7 | extractWeights: ExtractWeightsFunction, 8 | paramMappings: ParamMapping[] 9 | ) { 10 | 11 | return function( 12 | channelsIn: number, 13 | channelsOut: number, 14 | filterSize: number, 15 | mappedPrefix: string 16 | ): ConvParams { 17 | 18 | const filters = tf.tensor4d( 19 | extractWeights(channelsIn * channelsOut * filterSize * filterSize), 20 | [filterSize, filterSize, channelsIn, channelsOut] 21 | ) 22 | const bias = tf.tensor1d(extractWeights(channelsOut)) 23 | 24 | paramMappings.push( 25 | { paramPath: `${mappedPrefix}/filters` }, 26 | { paramPath: `${mappedPrefix}/bias` } 27 | ) 28 | 29 | return { filters, bias } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/common/extractFCParamsFactory.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { ExtractWeightsFunction, ParamMapping } from 'tfjs-image-recognition-base'; 3 | 4 | import { FCParams } from './types'; 5 | 6 | 7 | export function extractFCParamsFactory( 8 | extractWeights: ExtractWeightsFunction, 9 | paramMappings: ParamMapping[] 10 | ) { 11 | 12 | return function( 13 | channelsIn: number, 14 | channelsOut: number, 15 | mappedPrefix: string 16 | ): FCParams { 17 | 18 | const fc_weights = tf.tensor2d(extractWeights(channelsIn * channelsOut), [channelsIn, channelsOut]) 19 | const fc_bias = tf.tensor1d(extractWeights(channelsOut)) 20 | 21 | paramMappings.push( 22 | { paramPath: `${mappedPrefix}/weights` }, 23 | { paramPath: `${mappedPrefix}/bias` } 24 | ) 25 | 26 | return { 27 | weights: fc_weights, 28 | bias: fc_bias 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/common/extractSeparableConvParamsFactory.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { ExtractWeightsFunction, ParamMapping } from 'tfjs-image-recognition-base'; 3 | 4 | import { SeparableConvParams } from './types'; 5 | 6 | export function extractSeparableConvParamsFactory( 7 | extractWeights: ExtractWeightsFunction, 8 | paramMappings: ParamMapping[] 9 | ) { 10 | 11 | return function(channelsIn: number, channelsOut: number, mappedPrefix: string): SeparableConvParams { 12 | const depthwise_filter = tf.tensor4d(extractWeights(3 * 3 * channelsIn), [3, 3, channelsIn, 1]) 13 | const pointwise_filter = tf.tensor4d(extractWeights(channelsIn * channelsOut), [1, 1, channelsIn, channelsOut]) 14 | const bias = tf.tensor1d(extractWeights(channelsOut)) 15 | 16 | paramMappings.push( 17 | { paramPath: `${mappedPrefix}/depthwise_filter` }, 18 | { paramPath: `${mappedPrefix}/pointwise_filter` }, 19 | { paramPath: `${mappedPrefix}/bias` } 20 | ) 21 | 22 | return new SeparableConvParams( 23 | depthwise_filter, 24 | pointwise_filter, 25 | bias 26 | ) 27 | } 28 | 29 | } 30 | 31 | export function loadSeparableConvParamsFactory( 32 | extractWeightEntry: (originalPath: string, paramRank: number) => T 33 | ) { 34 | 35 | return function (prefix: string): SeparableConvParams { 36 | const depthwise_filter = extractWeightEntry(`${prefix}/depthwise_filter`, 4) 37 | const pointwise_filter = extractWeightEntry(`${prefix}/pointwise_filter`, 4) 38 | const bias = extractWeightEntry(`${prefix}/bias`, 1) 39 | 40 | return new SeparableConvParams( 41 | depthwise_filter, 42 | pointwise_filter, 43 | bias 44 | ) 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/common/index.ts: -------------------------------------------------------------------------------- 1 | export * from './convLayer'; 2 | export * from './extractConvParamsFactory'; 3 | export * from './extractFCParamsFactory'; 4 | export * from './extractSeparableConvParamsFactory'; 5 | export * from './types'; 6 | -------------------------------------------------------------------------------- /src/common/types.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | 3 | export type ConvParams = { 4 | filters: tf.Tensor4D 5 | bias: tf.Tensor1D 6 | } 7 | 8 | export type FCParams = { 9 | weights: tf.Tensor2D 10 | bias: tf.Tensor1D 11 | } 12 | 13 | export class SeparableConvParams { 14 | constructor( 15 | public depthwise_filter: tf.Tensor4D, 16 | public pointwise_filter: tf.Tensor4D, 17 | public bias: tf.Tensor1D 18 | ) {} 19 | } -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | 3 | export * from 'tfjs-image-recognition-base'; 4 | export * from './common'; 5 | export * from './tinyYolov2'; 6 | 7 | export { tf } -------------------------------------------------------------------------------- /src/tinyYolov2/TinyYolov2Options.ts: -------------------------------------------------------------------------------- 1 | export enum TinyYolov2SizeType { 2 | XS = 224, 3 | SM = 320, 4 | MD = 416, 5 | LG = 608 6 | } 7 | 8 | export interface ITinyYolov2Options { 9 | inputSize?: number 10 | scoreThreshold?: number 11 | } 12 | 13 | export class TinyYolov2Options { 14 | protected _name: string = 'TinyYolov2Options' 15 | 16 | private _inputSize: number 17 | private _scoreThreshold: number 18 | 19 | constructor({ inputSize, scoreThreshold }: ITinyYolov2Options = {}) { 20 | this._inputSize = inputSize || 416 21 | this._scoreThreshold = scoreThreshold || 0.5 22 | 23 | if (typeof this._inputSize !== 'number' || this._inputSize % 32 !== 0) { 24 | throw new Error(`${this._name} - expected inputSize to be a number divisible by 32`) 25 | } 26 | 27 | if (typeof this._scoreThreshold !== 'number' || this._scoreThreshold <= 0 || this._scoreThreshold >= 1) { 28 | throw new Error(`${this._name} - expected scoreThreshold to be a number between 0 and 1`) 29 | } 30 | } 31 | 32 | get inputSize(): number { return this._inputSize } 33 | get scoreThreshold(): number { return this._scoreThreshold } 34 | } -------------------------------------------------------------------------------- /src/tinyYolov2/TinyYolov2Trainable.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { 3 | computeReshapedDimensions, 4 | Dimensions, 5 | getMediaDimensions, 6 | imageToSquare, 7 | Rect, 8 | toNetInput, 9 | } from 'tfjs-image-recognition-base'; 10 | 11 | import { TinyYolov2TrainableConfig, validateTrainConfig } from './config'; 12 | import { getDefaultBackwardOptions } from './getDefaultBackwardOptions'; 13 | import { TinyYolov2 } from './TinyYolov2'; 14 | import { TinyYolov2LossFunction } from './TinyYolov2LossFunction'; 15 | import { GroundTruth, TinyYolov2BackwardOptions } from './types'; 16 | 17 | export class TinyYolov2Trainable extends TinyYolov2 { 18 | 19 | private _trainableConfig: TinyYolov2TrainableConfig 20 | private _optimizer: tf.Optimizer 21 | 22 | constructor(trainableConfig: TinyYolov2TrainableConfig, optimizer: tf.Optimizer) { 23 | super(trainableConfig) 24 | this._trainableConfig = validateTrainConfig(trainableConfig) 25 | this._optimizer = optimizer 26 | } 27 | 28 | public get trainableConfig(): TinyYolov2TrainableConfig { 29 | return this._trainableConfig 30 | } 31 | 32 | public get optimizer(): tf.Optimizer { 33 | return this._optimizer 34 | } 35 | 36 | public async backward( 37 | img: HTMLImageElement | HTMLCanvasElement, 38 | groundTruth: GroundTruth[], 39 | inputSize: number, 40 | options: TinyYolov2BackwardOptions = {} 41 | ): Promise | null> { 42 | 43 | const { minBoxSize, reportLosses } = getDefaultBackwardOptions(options) 44 | const reshapedImgDims = computeReshapedDimensions(getMediaDimensions(img), inputSize) 45 | const filteredGroundTruthBoxes = this.filterGroundTruthBoxes(groundTruth, reshapedImgDims, minBoxSize) 46 | 47 | if (!filteredGroundTruthBoxes.length) { 48 | return null 49 | } 50 | 51 | // square input images before creating tensor to prevent gpu memory overflow bug 52 | const netInput = await toNetInput(imageToSquare(img, inputSize)) 53 | 54 | const loss = this.optimizer.minimize(() => { 55 | 56 | const { 57 | noObjectLoss, 58 | objectLoss, 59 | coordLoss, 60 | classLoss, 61 | totalLoss 62 | } = this.computeLoss( 63 | this.forwardInput(netInput, inputSize), 64 | filteredGroundTruthBoxes, 65 | reshapedImgDims 66 | ) 67 | 68 | if (reportLosses) { 69 | const losses = { 70 | totalLoss: totalLoss.dataSync()[0], 71 | noObjectLoss: noObjectLoss.dataSync()[0], 72 | objectLoss: objectLoss.dataSync()[0], 73 | coordLoss: coordLoss.dataSync()[0], 74 | classLoss: classLoss.dataSync()[0] 75 | } 76 | 77 | const report = { 78 | losses, 79 | numBoxes: filteredGroundTruthBoxes.length, 80 | inputSize 81 | } 82 | 83 | reportLosses(report) 84 | } 85 | 86 | return totalLoss 87 | }, true) 88 | 89 | return loss 90 | } 91 | 92 | public computeLoss(outputTensor: tf.Tensor4D, groundTruth: GroundTruth[], reshapedImgDims: Dimensions) { 93 | 94 | const config = validateTrainConfig(this.config) 95 | 96 | const inputSize = Math.max(reshapedImgDims.width, reshapedImgDims.height) 97 | 98 | if (!inputSize) { 99 | throw new Error(`computeLoss - invalid inputSize: ${inputSize}`) 100 | } 101 | 102 | const predictedBoxes = this.extractBoxes(outputTensor, reshapedImgDims) 103 | 104 | return tf.tidy(() => { 105 | const lossFunction = new TinyYolov2LossFunction(outputTensor, groundTruth, predictedBoxes, reshapedImgDims, config) 106 | return lossFunction.computeLoss() 107 | }) 108 | } 109 | 110 | public filterGroundTruthBoxes(groundTruth: GroundTruth[], imgDims: Dimensions, minBoxSize: number) { 111 | 112 | const { height: imgHeight, width: imgWidth } = imgDims 113 | 114 | return groundTruth.filter(({ x, y, width, height }) => { 115 | const box = (new Rect(x, y, width, height)) 116 | .rescale({ height: imgHeight, width: imgWidth }) 117 | 118 | const isTooTiny = box.width < minBoxSize || box.height < minBoxSize 119 | return !isTooTiny 120 | }) 121 | } 122 | 123 | public async load(weightsOrUrl: Float32Array | string | undefined): Promise { 124 | await super.load(weightsOrUrl) 125 | this.variable() 126 | } 127 | } -------------------------------------------------------------------------------- /src/tinyYolov2/config.ts: -------------------------------------------------------------------------------- 1 | import { Point } from 'tfjs-image-recognition-base'; 2 | 3 | export type TinyYolov2Config = { 4 | withSeparableConvs: boolean 5 | iouThreshold: number 6 | anchors: Point[] 7 | classes: string[] 8 | meanRgb?: [number, number, number] 9 | withClassScores?: boolean, 10 | filterSizes?: number[] 11 | isFirstLayerConv2d?: boolean 12 | } 13 | 14 | export type TinyYolov2TrainableConfig = TinyYolov2Config & { 15 | // hyper params for training 16 | noObjectScale: number 17 | objectScale: number 18 | coordScale: number 19 | classScale: number 20 | } 21 | 22 | const isNumber = (arg: any) => typeof arg === 'number' 23 | 24 | export function validateConfig(config: any) { 25 | if (!config) { 26 | throw new Error(`invalid config: ${config}`) 27 | } 28 | 29 | if (typeof config.withSeparableConvs !== 'boolean') { 30 | throw new Error(`config.withSeparableConvs has to be a boolean, have: ${config.withSeparableConvs}`) 31 | } 32 | 33 | if (!isNumber(config.iouThreshold) || config.iouThreshold < 0 || config.iouThreshold > 1.0) { 34 | throw new Error(`config.iouThreshold has to be a number between [0, 1], have: ${config.iouThreshold}`) 35 | } 36 | 37 | if ( 38 | !Array.isArray(config.classes) 39 | || !config.classes.length 40 | || !config.classes.every((c: any) => typeof c === 'string') 41 | ) { 42 | 43 | throw new Error(`config.classes has to be an array class names: string[], have: ${JSON.stringify(config.classes)}`) 44 | } 45 | 46 | if ( 47 | !Array.isArray(config.anchors) 48 | || !config.anchors.length 49 | || !config.anchors.map((a: any) => a || {}).every((a: any) => isNumber(a.x) && isNumber(a.y)) 50 | ) { 51 | 52 | throw new Error(`config.anchors has to be an array of { x: number, y: number }, have: ${JSON.stringify(config.anchors)}`) 53 | } 54 | 55 | if (config.meanRgb && ( 56 | !Array.isArray(config.meanRgb) 57 | || config.meanRgb.length !== 3 58 | || !config.meanRgb.every(isNumber) 59 | )) { 60 | 61 | throw new Error(`config.meanRgb has to be an array of shape [number, number, number], have: ${JSON.stringify(config.meanRgb)}`) 62 | } 63 | } 64 | 65 | export function validateTrainConfig(config: any): TinyYolov2TrainableConfig { 66 | if (![config.noObjectScale, config.objectScale, config.coordScale, config.classScale].every(isNumber)) { 67 | throw new Error(`for training you have to specify noObjectScale, objectScale, coordScale, classScale parameters in your config.json file`) 68 | } 69 | 70 | return config 71 | } -------------------------------------------------------------------------------- /src/tinyYolov2/const.ts: -------------------------------------------------------------------------------- 1 | export const CELL_SIZE = 32 2 | 3 | export const DEFAULT_FILTER_SIZES = [ 4 | 3, 16, 32, 64, 128, 256, 512, 1024, 1024 5 | ] -------------------------------------------------------------------------------- /src/tinyYolov2/convWithBatchNorm.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | 3 | import { leaky } from './leaky'; 4 | import { ConvWithBatchNorm } from './types'; 5 | 6 | export function convWithBatchNorm(x: tf.Tensor4D, params: ConvWithBatchNorm): tf.Tensor4D { 7 | return tf.tidy(() => { 8 | let out = tf.pad(x, [[0, 0], [1, 1], [1, 1], [0, 0]]) as tf.Tensor4D 9 | 10 | out = tf.conv2d(out, params.conv.filters, [1, 1], 'valid') 11 | out = tf.sub(out, params.bn.sub) 12 | out = tf.mul(out, params.bn.truediv) 13 | out = tf.add(out, params.conv.bias) 14 | 15 | return leaky(out) 16 | }) 17 | } -------------------------------------------------------------------------------- /src/tinyYolov2/depthwiseSeparableConv.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | 3 | import { SeparableConvParams } from '../common/types'; 4 | import { leaky } from './leaky'; 5 | 6 | export function depthwiseSeparableConv(x: tf.Tensor4D, params: SeparableConvParams): tf.Tensor4D { 7 | return tf.tidy(() => { 8 | let out = tf.pad(x, [[0, 0], [1, 1], [1, 1], [0, 0]]) as tf.Tensor4D 9 | 10 | out = tf.separableConv2d(out, params.depthwise_filter, params.pointwise_filter, [1, 1], 'valid') 11 | out = tf.add(out, params.bias) 12 | 13 | return leaky(out) 14 | }) 15 | } -------------------------------------------------------------------------------- /src/tinyYolov2/extractParams.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { extractWeightsFactory, ExtractWeightsFunction, ParamMapping } from 'tfjs-image-recognition-base'; 3 | 4 | import { extractConvParamsFactory } from '../common'; 5 | import { extractSeparableConvParamsFactory } from '../common/extractSeparableConvParamsFactory'; 6 | import { TinyYolov2Config } from './config'; 7 | import { BatchNorm, ConvWithBatchNorm, TinyYolov2NetParams } from './types'; 8 | 9 | function extractorsFactory(extractWeights: ExtractWeightsFunction, paramMappings: ParamMapping[]) { 10 | 11 | const extractConvParams = extractConvParamsFactory(extractWeights, paramMappings) 12 | 13 | function extractBatchNormParams(size: number, mappedPrefix: string): BatchNorm { 14 | 15 | const sub = tf.tensor1d(extractWeights(size)) 16 | const truediv = tf.tensor1d(extractWeights(size)) 17 | 18 | paramMappings.push( 19 | { paramPath: `${mappedPrefix}/sub` }, 20 | { paramPath: `${mappedPrefix}/truediv` } 21 | ) 22 | 23 | return { sub, truediv } 24 | } 25 | 26 | function extractConvWithBatchNormParams(channelsIn: number, channelsOut: number, mappedPrefix: string): ConvWithBatchNorm { 27 | 28 | const conv = extractConvParams(channelsIn, channelsOut, 3, `${mappedPrefix}/conv`) 29 | const bn = extractBatchNormParams(channelsOut, `${mappedPrefix}/bn`) 30 | 31 | return { conv, bn } 32 | } 33 | const extractSeparableConvParams = extractSeparableConvParamsFactory(extractWeights, paramMappings) 34 | 35 | return { 36 | extractConvParams, 37 | extractConvWithBatchNormParams, 38 | extractSeparableConvParams 39 | } 40 | 41 | } 42 | 43 | export function extractParams( 44 | weights: Float32Array, 45 | config: TinyYolov2Config, 46 | boxEncodingSize: number, 47 | filterSizes: number[] 48 | ): { params: TinyYolov2NetParams, paramMappings: ParamMapping[] } { 49 | 50 | const { 51 | extractWeights, 52 | getRemainingWeights 53 | } = extractWeightsFactory(weights) 54 | 55 | const paramMappings: ParamMapping[] = [] 56 | 57 | const { 58 | extractConvParams, 59 | extractConvWithBatchNormParams, 60 | extractSeparableConvParams 61 | } = extractorsFactory(extractWeights, paramMappings) 62 | 63 | let params: TinyYolov2NetParams 64 | 65 | if (config.withSeparableConvs) { 66 | const [s0, s1, s2, s3, s4, s5, s6, s7, s8] = filterSizes 67 | 68 | const conv0 = config.isFirstLayerConv2d 69 | ? extractConvParams(s0, s1, 3, 'conv0') 70 | : extractSeparableConvParams(s0, s1, 'conv0') 71 | const conv1 = extractSeparableConvParams(s1, s2, 'conv1') 72 | const conv2 = extractSeparableConvParams(s2, s3, 'conv2') 73 | const conv3 = extractSeparableConvParams(s3, s4, 'conv3') 74 | const conv4 = extractSeparableConvParams(s4, s5, 'conv4') 75 | const conv5 = extractSeparableConvParams(s5, s6, 'conv5') 76 | const conv6 = s7 ? extractSeparableConvParams(s6, s7, 'conv6') : undefined 77 | const conv7 = s8 ? extractSeparableConvParams(s7, s8, 'conv7') : undefined 78 | const conv8 = extractConvParams(s8 || s7 || s6, 5 * boxEncodingSize, 1, 'conv8') 79 | params = { conv0, conv1, conv2, conv3, conv4, conv5, conv6, conv7, conv8 } 80 | } else { 81 | const [s0, s1, s2, s3, s4, s5, s6, s7, s8] = filterSizes 82 | const conv0 = extractConvWithBatchNormParams(s0, s1, 'conv0',) 83 | const conv1 = extractConvWithBatchNormParams(s1, s2, 'conv1') 84 | const conv2 = extractConvWithBatchNormParams(s2, s3, 'conv2') 85 | const conv3 = extractConvWithBatchNormParams(s3, s4, 'conv3') 86 | const conv4 = extractConvWithBatchNormParams(s4, s5, 'conv4') 87 | const conv5 = extractConvWithBatchNormParams(s5, s6, 'conv5') 88 | const conv6 = extractConvWithBatchNormParams(s6, s7, 'conv6') 89 | const conv7 = extractConvWithBatchNormParams(s7, s8, 'conv7') 90 | const conv8 = extractConvParams(s8, 5 * boxEncodingSize, 1, 'conv8') 91 | params = { conv0, conv1, conv2, conv3, conv4, conv5, conv6, conv7, conv8 } 92 | } 93 | 94 | if (getRemainingWeights().length !== 0) { 95 | throw new Error(`weights remaing after extract: ${getRemainingWeights().length}`) 96 | } 97 | 98 | 99 | return { params, paramMappings } 100 | } -------------------------------------------------------------------------------- /src/tinyYolov2/extractParamsFromWeigthMap.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { disposeUnusedWeightTensors, extractWeightEntryFactory, ParamMapping } from 'tfjs-image-recognition-base'; 3 | 4 | import { ConvParams } from '../common'; 5 | import { loadSeparableConvParamsFactory } from '../common/extractSeparableConvParamsFactory'; 6 | import { TinyYolov2Config } from './config'; 7 | import { BatchNorm, ConvWithBatchNorm, TinyYolov2NetParams } from './types'; 8 | 9 | function extractorsFactory(weightMap: any, paramMappings: ParamMapping[]) { 10 | 11 | const extractWeightEntry = extractWeightEntryFactory(weightMap, paramMappings) 12 | 13 | function extractBatchNormParams(prefix: string): BatchNorm { 14 | const sub = extractWeightEntry(`${prefix}/sub`, 1) 15 | const truediv = extractWeightEntry(`${prefix}/truediv`, 1) 16 | return { sub, truediv } 17 | } 18 | 19 | function extractConvParams(prefix: string): ConvParams { 20 | const filters = extractWeightEntry(`${prefix}/filters`, 4) 21 | const bias = extractWeightEntry(`${prefix}/bias`, 1) 22 | return { filters, bias } 23 | } 24 | 25 | function extractConvWithBatchNormParams(prefix: string): ConvWithBatchNorm { 26 | const conv = extractConvParams(`${prefix}/conv`) 27 | const bn = extractBatchNormParams(`${prefix}/bn`) 28 | return { conv, bn } 29 | } 30 | 31 | const extractSeparableConvParams = loadSeparableConvParamsFactory(extractWeightEntry) 32 | 33 | return { 34 | extractConvParams, 35 | extractConvWithBatchNormParams, 36 | extractSeparableConvParams 37 | } 38 | 39 | } 40 | 41 | export function extractParamsFromWeigthMap( 42 | weightMap: tf.NamedTensorMap, 43 | config: TinyYolov2Config 44 | ): { params: TinyYolov2NetParams, paramMappings: ParamMapping[] } { 45 | 46 | const paramMappings: ParamMapping[] = [] 47 | 48 | const { 49 | extractConvParams, 50 | extractConvWithBatchNormParams, 51 | extractSeparableConvParams 52 | } = extractorsFactory(weightMap, paramMappings) 53 | 54 | let params: TinyYolov2NetParams 55 | 56 | if (config.withSeparableConvs) { 57 | const numFilters = (config.filterSizes && config.filterSizes.length || 9) 58 | params = { 59 | conv0: config.isFirstLayerConv2d ? extractConvParams('conv0') : extractSeparableConvParams('conv0'), 60 | conv1: extractSeparableConvParams('conv1'), 61 | conv2: extractSeparableConvParams('conv2'), 62 | conv3: extractSeparableConvParams('conv3'), 63 | conv4: extractSeparableConvParams('conv4'), 64 | conv5: extractSeparableConvParams('conv5'), 65 | conv6: numFilters > 7 ? extractSeparableConvParams('conv6') : undefined, 66 | conv7: numFilters > 8 ? extractSeparableConvParams('conv7') : undefined, 67 | conv8: extractConvParams('conv8') 68 | } 69 | } else { 70 | params = { 71 | conv0: extractConvWithBatchNormParams('conv0'), 72 | conv1: extractConvWithBatchNormParams('conv1'), 73 | conv2: extractConvWithBatchNormParams('conv2'), 74 | conv3: extractConvWithBatchNormParams('conv3'), 75 | conv4: extractConvWithBatchNormParams('conv4'), 76 | conv5: extractConvWithBatchNormParams('conv5'), 77 | conv6: extractConvWithBatchNormParams('conv6'), 78 | conv7: extractConvWithBatchNormParams('conv7'), 79 | conv8: extractConvParams('conv8') 80 | } 81 | } 82 | 83 | disposeUnusedWeightTensors(weightMap, paramMappings) 84 | 85 | return { params, paramMappings } 86 | } -------------------------------------------------------------------------------- /src/tinyYolov2/getDefaultBackwardOptions.ts: -------------------------------------------------------------------------------- 1 | import { CELL_SIZE } from './const'; 2 | import { TinyYolov2BackwardOptions } from './types'; 3 | 4 | export function getDefaultBackwardOptions(options: TinyYolov2BackwardOptions) { 5 | return Object.assign( 6 | {}, 7 | { 8 | minBoxSize: CELL_SIZE 9 | }, 10 | options 11 | ) 12 | } -------------------------------------------------------------------------------- /src/tinyYolov2/index.ts: -------------------------------------------------------------------------------- 1 | export * from './TinyYolov2'; 2 | export * from './TinyYolov2LossFunction'; 3 | export * from './TinyYolov2Trainable'; 4 | export * from './TinyYolov2Options'; 5 | 6 | export { TinyYolov2NetParams } from './types' -------------------------------------------------------------------------------- /src/tinyYolov2/leaky.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | 3 | export function leaky(x: tf.Tensor4D): tf.Tensor4D { 4 | return tf.tidy(() => { 5 | const min = tf.mul(x, tf.scalar(0.10000000149011612)) 6 | return tf.add(tf.relu(tf.sub(x, min)), min) 7 | //return tf.maximum(x, min) 8 | }) 9 | } -------------------------------------------------------------------------------- /src/tinyYolov2/types.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | import { Box, IRect } from 'tfjs-image-recognition-base'; 3 | 4 | import { ConvParams } from '../common'; 5 | import { SeparableConvParams } from '../common/types'; 6 | 7 | export type BatchNorm = { 8 | sub: tf.Tensor1D 9 | truediv: tf.Tensor1D 10 | } 11 | 12 | export type ConvWithBatchNorm = { 13 | conv: ConvParams 14 | bn: BatchNorm 15 | } 16 | 17 | export type MobilenetParams = { 18 | conv0: SeparableConvParams | ConvParams 19 | conv1: SeparableConvParams 20 | conv2: SeparableConvParams 21 | conv3: SeparableConvParams 22 | conv4: SeparableConvParams 23 | conv5: SeparableConvParams 24 | conv6?: SeparableConvParams 25 | conv7?: SeparableConvParams 26 | conv8: ConvParams 27 | } 28 | 29 | export type DefaultTinyYolov2NetParams = { 30 | conv0: ConvWithBatchNorm 31 | conv1: ConvWithBatchNorm 32 | conv2: ConvWithBatchNorm 33 | conv3: ConvWithBatchNorm 34 | conv4: ConvWithBatchNorm 35 | conv5: ConvWithBatchNorm 36 | conv6: ConvWithBatchNorm 37 | conv7: ConvWithBatchNorm 38 | conv8: ConvParams 39 | } 40 | 41 | export type TinyYolov2NetParams = DefaultTinyYolov2NetParams | MobilenetParams 42 | 43 | export type GridPosition = { 44 | row: number 45 | col: number 46 | anchor: number 47 | } 48 | 49 | export type GroundTruthWithGridPosition = GridPosition & { 50 | box: Box 51 | label: number 52 | } 53 | 54 | export type GroundTruth = IRect & { 55 | label: number 56 | } 57 | 58 | export type YoloLoss = { 59 | totalLoss: number 60 | noObjectLoss: number 61 | objectLoss: number 62 | coordLoss: number 63 | classLoss: number 64 | } 65 | 66 | export type LossReport = { 67 | losses: YoloLoss 68 | numBoxes: number 69 | inputSize: number 70 | } 71 | 72 | export type TinyYolov2BackwardOptions = { 73 | minBoxSize?: number 74 | reportLosses?: (report: LossReport) => void 75 | } -------------------------------------------------------------------------------- /test/utils.ts: -------------------------------------------------------------------------------- 1 | import * as tf from '@tensorflow/tfjs-core'; 2 | 3 | import { TinyYolov2LossFunction } from '../src/tinyYolov2/TinyYolov2LossFunction'; 4 | import { GroundTruth, GroundTruthWithGridPosition } from '../src/tinyYolov2/types'; 5 | 6 | export function expectTensorToBeZeros(tensor: tf.Tensor) { 7 | return expect(Array.from(tensor.dataSync()).reduce((sum, val) => sum + val, 0)).toEqual(0) 8 | } 9 | 10 | export function createFakeConfig(config: any = {}) { 11 | return { 12 | withSeparableConvs: true, 13 | iouThreshold: 0.4, 14 | anchors: [ 15 | { x: 1, y: 1 } 16 | ], 17 | classes: ['foo', 'bar'], 18 | objectScale: 5, 19 | noObjectScale: 1, 20 | coordScale: 1, 21 | classScale: 0, 22 | ...config 23 | } 24 | } 25 | 26 | export function createFakeLossFunction(numCells: number, groundTruth: GroundTruth[], predictedBoxes: GroundTruthWithGridPosition[], config: any = {}) { 27 | const fakeConfig = createFakeConfig(config) 28 | const numBoxes = fakeConfig.anchors.length 29 | const numClasses = fakeConfig.classes.length 30 | 31 | const outputTensor = tf.ones([1, numCells, numCells, numBoxes * (5 + numClasses)]) as tf.Tensor4D 32 | 33 | return new TinyYolov2LossFunction( 34 | outputTensor, 35 | groundTruth, 36 | predictedBoxes, 37 | { width: numCells * 32, height: numCells * 32 }, 38 | fakeConfig 39 | ) 40 | } 41 | 42 | export function createFakeLossFunctionMd(groundTruth: GroundTruth[], predictedBoxes: GroundTruthWithGridPosition[], config: any = {}) { 43 | return createFakeLossFunction(13, groundTruth, predictedBoxes, config) 44 | } -------------------------------------------------------------------------------- /train/face/initWeights.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 16 | 17 |
18 | 24 | 30 |
31 | 32 | 107 | 108 | -------------------------------------------------------------------------------- /train/face/test.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 49 | 50 | -------------------------------------------------------------------------------- /train/face/train.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 140 | 141 | -------------------------------------------------------------------------------- /train/js/createLossReporter.js: -------------------------------------------------------------------------------- 1 | function createLossReporter(trainSizes) { 2 | 3 | const totalLosses = {} 4 | const noObjectLosses = {} 5 | const objectLosses = {} 6 | const classLosses = {} 7 | const coordLosses = {} 8 | const counters = {} 9 | 10 | function resetLosses() { 11 | trainSizes.forEach(size => { 12 | totalLosses[size] = 0 13 | noObjectLosses[size] = 0 14 | objectLosses[size] = 0 15 | classLosses[size] = 0 16 | coordLosses[size] = 0 17 | counters[size] = 0 18 | }) 19 | } 20 | 21 | function reportLosses({ losses, inputSize }) { 22 | totalLosses[inputSize] += losses.totalLoss 23 | noObjectLosses[inputSize] += losses.noObjectLoss 24 | objectLosses[inputSize] += losses.objectLoss 25 | classLosses[inputSize] += losses.classLoss 26 | coordLosses[inputSize] += losses.coordLoss 27 | counters[inputSize] += 1 28 | } 29 | 30 | function summary(reportTotalLossOnly = false) { 31 | const avgLosses = {} 32 | 33 | trainSizes.forEach(size => { 34 | avgLosses[size] = Object.assign( 35 | {}, 36 | { 37 | count: counters[size], 38 | totalLoss: totalLosses[size] / counters[size] 39 | }, 40 | reportTotalLossOnly ? {} : { 41 | noObjectLoss: noObjectLosses[size] / counters[size], 42 | objectLoss: objectLosses[size] / counters[size], 43 | classLoss: classLosses[size] / counters[size], 44 | coordLoss: coordLosses[size] / counters[size] 45 | } 46 | ) 47 | }) 48 | 49 | return avgLosses 50 | } 51 | 52 | resetLosses() 53 | 54 | return { 55 | resetLosses, 56 | reportLosses, 57 | summary 58 | } 59 | } -------------------------------------------------------------------------------- /train/js/randomCrop.js: -------------------------------------------------------------------------------- 1 | function randomCrop(img, rects) { 2 | 3 | if (!rects.length) { 4 | throw new Error('randomCrop - rects empty') 5 | } 6 | 7 | let minX = img.width 8 | let minY = img.height 9 | let maxX = 0 10 | let maxY = 0 11 | 12 | const rescaledRects = rects.map(({ x, y, width, height }) => 13 | new yolo.Rect(x * img.width, y * img.height, width * img.width, height * img.height) 14 | ) 15 | 16 | rescaledRects.forEach(({ x, y, width, height }) => { 17 | minX = Math.min(minX, x) 18 | minY = Math.min(minY, y) 19 | maxX = Math.max(maxX, x + width) 20 | maxY = Math.max(maxY, y + height) 21 | }) 22 | 23 | console.log(rects) 24 | console.log(minX, minY, maxX, maxY) 25 | 26 | const x0 = Math.random() * minX 27 | const y0 = Math.random() * minY 28 | 29 | const x1 = (Math.random() * Math.abs(img.width - maxX)) + maxX 30 | const y1 = (Math.random() * Math.abs(img.height - maxY)) + maxY 31 | 32 | console.log(x0, y0, x1, y1) 33 | 34 | const targetCanvas = yolo.createCanvas({ width: x1 - x0, height: y1 - y0 }) 35 | const inputCanvas = img instanceof HTMLCanvasElement ? img : yolo.createCanvasFromMedia(img) 36 | const region = yolo.getContext2dOrThrow(inputCanvas) 37 | .getImageData(x0, y0, targetCanvas.width, targetCanvas.height) 38 | yolo.getContext2dOrThrow(targetCanvas).putImageData(region, 0, 0) 39 | 40 | return { 41 | croppedImage: targetCanvas, 42 | shiftedRects: rescaledRects.map(rect => 43 | new yolo.Rect(rect.x - x0, rect.y - y0, rect.width, rect.height) 44 | .rescale({ width: 1 / targetCanvas.width, height: 1 / targetCanvas.height }) 45 | ) 46 | } 47 | } -------------------------------------------------------------------------------- /train/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "scripts": { 3 | "start": "node server.js" 4 | }, 5 | "author": "justadudewhohacks", 6 | "license": "MIT", 7 | "dependencies": { 8 | "express": "^4.16.3", 9 | "file-saver": "^1.3.8", 10 | "request": "^2.87.0" 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /train/serveFaceDetection.js: -------------------------------------------------------------------------------- 1 | require('./face/.env') 2 | 3 | const express = require('express') 4 | const path = require('path') 5 | const fs = require('fs') 6 | 7 | const app = express() 8 | 9 | app.use(express.json()) 10 | app.use(express.urlencoded({ extended: true })) 11 | 12 | const public = path.join(__dirname, 'face') 13 | app.use(express.static(public)) 14 | app.use(express.static(path.join(__dirname, './js'))) 15 | app.use(express.static(path.join(__dirname, '../examples/public'))) 16 | app.use(express.static(path.join(__dirname, '../models'))) 17 | app.use(express.static(path.join(__dirname, '../dist'))) 18 | app.use(express.static(path.join(__dirname, './node_modules/file-saver'))) 19 | 20 | app.get('/', (req, res) => res.redirect('/train')) 21 | app.get('/train', (req, res) => res.sendFile(path.join(public, 'train.html'))) 22 | app.get('/verify', (req, res) => res.sendFile(path.join(public, 'verify.html'))) 23 | app.get('/test', (req, res) => res.sendFile(path.join(public, 'test.html'))) 24 | 25 | const trainDataPath = path.resolve(process.env.TRAIN_DATA_PATH) 26 | const testDataPath = path.resolve(process.env.TEST_DATA_PATH) 27 | const imagesPath = path.join(trainDataPath, 'jpgs') 28 | const groundTruthPath = path.join(trainDataPath, 'ground_truth') 29 | app.use(express.static(imagesPath)) 30 | app.use(express.static(groundTruthPath)) 31 | app.use(express.static(testDataPath)) 32 | 33 | const trainIds = fs.readdirSync(groundTruthPath).map(gt => gt.replace('.json', '')) 34 | const testIds = JSON.parse(fs.readFileSync(path.join(testDataPath, 'test_ground_truth.json')).toString()) 35 | .map(gt => gt.imgFile.replace('.jpg', '')) 36 | 37 | app.get('/train_ids', (req, res) => res.status(202).send(trainIds)) 38 | app.get('/test_ids', (req, res) => res.status(202).send(testIds)) 39 | 40 | app.listen(8000, () => console.log('Listening on port 8000!')) -------------------------------------------------------------------------------- /train/serveVoc.js: -------------------------------------------------------------------------------- 1 | require('./voc/.env') 2 | 3 | const express = require('express') 4 | const path = require('path') 5 | const fs = require('fs') 6 | 7 | const app = express() 8 | 9 | app.use(express.json()) 10 | app.use(express.urlencoded({ extended: true })) 11 | 12 | const public = path.join(__dirname, './voc') 13 | app.use(express.static(public)) 14 | app.use(express.static(path.join(__dirname, './js'))) 15 | app.use(express.static(path.join(__dirname, '../examples/public'))) 16 | app.use(express.static(path.join(__dirname, '../models'))) 17 | app.use(express.static(path.join(__dirname, '../dist'))) 18 | app.use(express.static(path.join(__dirname, './node_modules/file-saver'))) 19 | 20 | app.get('/', (req, res) => res.redirect('/train')) 21 | app.get('/train', (req, res) => res.sendFile(path.join(public, 'trainVoc.html'))) 22 | app.get('/verify', (req, res) => res.sendFile(path.join(public, 'verifyVoc.html'))) 23 | 24 | const trainDataPath = path.resolve(process.env.TRAIN_DATA_PATH) 25 | const imagesPath = path.join(trainDataPath, 'images') 26 | const groundTruthPath = path.join(trainDataPath, 'ground_truth') 27 | app.use(express.static(imagesPath)) 28 | app.use(express.static(groundTruthPath)) 29 | 30 | const groundTruthFilenames = fs.readdirSync(groundTruthPath) 31 | 32 | app.get('/voc_train_filenames', (req, res) => res.status(202).send(groundTruthFilenames)) 33 | 34 | app.listen(8000, () => console.log('Listening on port 8000!')) -------------------------------------------------------------------------------- /train/voc/initWeights.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 | 16 | 17 |
18 | 24 |
25 | 26 | 88 | 89 | -------------------------------------------------------------------------------- /train/voc/trainVoc.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 133 | 134 | -------------------------------------------------------------------------------- /tsconfig.es6.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "build/es6", 5 | "module": "es6", 6 | "target": "es5" 7 | }, 8 | "include": [ 9 | "src" 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | 4 | "removeComments": false, 5 | "preserveConstEnums": true, 6 | "emitDecoratorMetadata": true, 7 | "experimentalDecorators": true, 8 | "sourceMap": true, 9 | "declaration": true, 10 | "noImplicitAny": true, 11 | "noImplicitReturns": true, 12 | "noImplicitThis": true, 13 | "noFallthroughCasesInSwitch": true, 14 | "suppressImplicitAnyIndexErrors": true, 15 | "strictNullChecks": true, 16 | "importHelpers": true, 17 | "outDir": "build/commonjs", 18 | "module": "commonjs", 19 | "target": "es5", 20 | "moduleResolution": "node", 21 | "lib": ["es2015", "dom"], 22 | "typeRoots": [ 23 | "typings", 24 | "node_modules/@types" 25 | ], 26 | "baseUrl": "." 27 | }, 28 | "formatCodeOptions": { 29 | "indentSize": 2, 30 | "tabSize": 2 31 | }, 32 | "include": [ 33 | "src" 34 | ] 35 | } -------------------------------------------------------------------------------- /tsconfig.test.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./tsconfig.json", 3 | "include": [ 4 | "src", 5 | "test" 6 | ] 7 | } 8 | --------------------------------------------------------------------------------