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: Allow partial execution of network #51

Merged
merged 18 commits into from
Feb 2, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
update mnist example
  • Loading branch information
retraigo committed Jan 28, 2024
commit cd3112c9e6befdbcbb0892e02fff529ec1008f4b
20 changes: 15 additions & 5 deletions examples/mnist/predict.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { CPU, Rank, Sequential, setupBackend, Tensor } from "../../mod.ts";
import {
CPU,
Rank,
Sequential,
setupBackend,
Shape,
Tensor,
tensor,
} from "../../mod.ts";
import { loadDataset } from "./common.ts";

await setupBackend(CPU);
Expand All @@ -22,14 +30,16 @@ function argmax(mat: Tensor<Rank>) {

let correct = 0;
for (const test of testSet) {
const prediction = argmax(await network.predict(test.inputs as Tensor<Rank>));
const prediction = argmax(
await network.predict(
tensor(test.inputs.data, [1, ...test.inputs.shape] as Shape[keyof Shape])
)
);
const expected = argmax(test.outputs as Tensor<Rank>);
if (expected === prediction) {
correct += 1;
}
}

console.log(`${correct} / ${testSet.length} correct`);
console.log(
`accuracy: ${((correct / testSet.length) * 100).toFixed(2)}%`,
);
console.log(`accuracy: ${((correct / testSet.length) * 100).toFixed(2)}%`);
Loading