Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update the model summary tool to check sub functions #3481

Merged
merged 2 commits into from Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);