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

feat(KNNClassifier): This adds typescript support for KNNClassifier #276

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ experiments/node_modules
node_modules
**/npm-debug.log
.vscode
.idea
*.DS_STORE
experiments
training/lstm/data/t
Expand Down
6 changes: 3 additions & 3 deletions dist/ml5.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/ml5.min.js.map

Large diffs are not rendered by default.

15 changes: 10 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
"scripts": {
"commit": "git-cz",
"prebuild": "rimraf dist",
"start": "webpack-dev-server --open --config webpack.dev.babel.js",
"build": "webpack --config webpack.prod.babel.js",
"start": "tsc && webpack-dev-server --open --config webpack.dev.babel.js",
"build": "tsc && webpack --config webpack.prod.babel.js",
"test": "./node_modules/karma/bin/karma start karma.conf.js",
"test:single": "./node_modules/karma/bin/karma start karma.conf.js --single-run",
"test-travis": "./scripts/test-travis.sh"
Expand Down Expand Up @@ -63,7 +63,8 @@
"webpack": "4.1.1",
"webpack-cli": "2.0.10",
"webpack-dev-server": "3.1.0",
"webpack-merge": "^4.1.2"
"webpack-merge": "^4.1.2",
"typescript": "^3.3.1"
},
"config": {
"commitizen": {
Expand All @@ -87,9 +88,9 @@
},
"dependencies": {
"@magenta/sketch": "^0.1.2",
"@tensorflow-models/knn-classifier": "0.2.2",
"@tensorflow-models/mobilenet": "0.2.2",
"@tensorflow-models/posenet": "0.2.2",
"@tensorflow-models/knn-classifier": "0.2.2",
"@tensorflow/tfjs": "0.13.0",
"events": "^3.0.0"
}
Expand Down
33 changes: 33 additions & 0 deletions src/KNNClassifier/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import * as tf from '@tensorflow/tfjs';
import * as knnClassifier from '@tensorflow-models/knn-classifier';
declare class KNN {
knnClassifier: knnClassifier.KNNClassifier;
mapStringToIndex: Array<any>;
constructor();
addExample(input: any, classIndexOrLabel: any): void;
classify(input: any, kOrCallback: any, cb: any): Promise<any>;
classifyInternal(input: any, k: any): Promise<{
classIndex: number;
confidences: {
[classId: number]: number;
};
}>;
clearLabel(labelIndex: any): void;
clearAllLabels(): void;
getCountByLabel(): {
[classId: number]: number;
};
getCount(): {
[classId: number]: number;
};
getClassifierDataset(): {
[classId: number]: tf.Tensor<tf.Rank.R2>;
};
setClassifierDataset(dataset: any): void;
getNumLabels(): number;
dispose(): void;
save(name: any): void;
load(path: any, callback: any): void;
}
declare const KNNClassifier: () => KNN;
export default KNNClassifier;
Loading