Skip to content

Commit

Permalink
update the model summary tool to check both sub functions (#3481)
Browse files Browse the repository at this point in the history
INTERNAL
  • Loading branch information
pyu10055 committed Jun 20, 2020
1 parent 3ca8d5c commit 9fc2314
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
1 change: 1 addition & 0 deletions tfjs-converter/package.json
Expand Up @@ -76,6 +76,7 @@
"make-version": "sh -c ./scripts/make-version",
"gen-doc": "ts-node -s ./scripts/gen_doc.ts",
"gen-json": "ts-node -s ./scripts/gen_json.ts",
"model-summary": "ts-node -s ./tools/model_summary.ts",
"pb2json": "ts-node -s ./tools/pb2json_converter.ts",
"build-pip-package": "yarn gen-json --test && cd python && ./build-pip-package.sh --test /tmp/tfjs-pips",
"run-python-tests": "yarn gen-json --test && cd python && ./run-python-tests.sh"
Expand Down
28 changes: 20 additions & 8 deletions tfjs-converter/tools/model_summary.ts
Expand Up @@ -18,27 +18,39 @@ import * as fs from 'fs';

function summarize(argv: string[]) {
if (argv.length < 3) {
console.log('Usage: ts-node pb2json.ts model_file');
console.log('Usage: yarn model-summary model_file');
return;
}

const sourcePath = process.argv[2];
console.log('reading pb model file: ' + sourcePath);
const rawdata = fs.readFileSync(sourcePath);
const nodes: Array<any> = JSON.parse(rawdata.toString())['modelTopology']['node'];
const model = JSON.parse(rawdata.toString());
if (model.format !== 'graph-model') {
console.log('This tool only supports TFJS Graph models.');
return;
}
// tslint:disable-next-line: no-any
const nodes: any[] = model['modelTopology']['node'];
const library = model['modelTopology']['library'];
if (library != null) {
const functions = library['function'];
// tslint:disable-next-line: no-any
functions.forEach((func: any) => nodes.concat(func['nodeDef']));
}

const opCount: {[key: string]: number} = {};
for (const opNode of nodes) {
nodes.forEach(opNode => {
let count = 0;
const op = opNode['op'];
if (opCount[op]) {
count = opCount[op];
}
opCount[op] = count + 1;
}
count = opCount[op];
}
opCount[op] = count + 1;
});

console.log(opCount);
console.log('Total ops = ' + nodes.length);
console.log(`Total ops = ${nodes.length}`);
}

summarize(process.argv);

0 comments on commit 9fc2314

Please sign in to comment.