Skip to content

Commit

Permalink
put knn back in
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryXII committed May 28, 2024
1 parent 3182a62 commit 23fbd96
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 20 deletions.
2 changes: 1 addition & 1 deletion public/build/bundle.css

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

47 changes: 32 additions & 15 deletions public/build/bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -25281,15 +25281,15 @@ var app = (function () {
attr_dev(canvas0, "width", "400");
attr_dev(canvas0, "height", "400");
attr_dev(canvas0, "class", "svelte-1fh5jg7");
add_location(canvas0, file$2, 91, 6, 3031);
add_location(canvas0, file$2, 95, 6, 3036);
attr_dev(canvas1, "id", "resized-canvas");
attr_dev(canvas1, "width", "28");
attr_dev(canvas1, "height", "28");
attr_dev(canvas1, "class", "svelte-1fh5jg7");
add_location(canvas1, file$2, 93, 6, 3149);
add_location(button0, file$2, 94, 6, 3216);
add_location(button1, file$2, 95, 6, 3268);
add_location(div, file$2, 90, 4, 3019);
add_location(canvas1, file$2, 97, 6, 3154);
add_location(button0, file$2, 98, 6, 3221);
add_location(button1, file$2, 99, 6, 3273);
add_location(div, file$2, 94, 4, 3024);
},
l: function claim(nodes) {
throw new Error("options.hydrate only works if the component was compiled with the `hydratable: true` option");
Expand Down Expand Up @@ -25349,6 +25349,7 @@ var app = (function () {
let lastY = 0;
let knnClassifier;
let mnistData;
let trained = false;

async function trainClassifier() {
mnistData = new MnistData();
Expand All @@ -25368,7 +25369,6 @@ var app = (function () {
onMount(() => {
knnClassifier = ml5_min.KNNClassifier();
knnClassifier.k = 3;
trainClassifier();
canvas = document.getElementById('canvas');
ctx = canvas.getContext('2d');
ctx.lineWidth = 10;
Expand Down Expand Up @@ -25409,9 +25409,13 @@ var app = (function () {
}

async function classifyDrawing() {
if (trained === false) {
trainClassifier();
trained = true;
}

const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
const alphaData = imageData.data.filter((_, i) => i % 4 === 3);
const tensorImg = Pn(alphaData, [canvas.height, canvas.width, 1]);
const tensorImg = Vd.fromPixels(imageData, 1);
console.log(tensorImg.arraySync());
const resizedImg = nf.resizeBilinear(tensorImg, [28, 28]);
const normalizedImg = resizedImg.div(255.0);
Expand Down Expand Up @@ -25444,6 +25448,7 @@ var app = (function () {
lastY,
knnClassifier,
mnistData,
trained,
trainClassifier,
startDrawing,
draw,
Expand All @@ -25462,6 +25467,7 @@ var app = (function () {
if ('lastY' in $$props) lastY = $$props.lastY;
if ('knnClassifier' in $$props) knnClassifier = $$props.knnClassifier;
if ('mnistData' in $$props) mnistData = $$props.mnistData;
if ('trained' in $$props) trained = $$props.trained;
};

if ($$props && "$$inject" in $$props) {
Expand Down Expand Up @@ -59933,18 +59939,21 @@ var app = (function () {
let t2;
let intro;
let t3;
let drawing;
let knnchart;
let t4;
let conclusion;
let t5;
let drawing;
let t6;
let resources;
let current;
load = new Load({ $$inline: true });
meta = new Meta({ $$inline: true });
title = new Title({ $$inline: true });
intro = new Intro({ $$inline: true });
drawing = new Drawing({ $$inline: true });
knnchart = new KnnChart({ $$inline: true });
conclusion = new Conclusion({ $$inline: true });
drawing = new Drawing({ $$inline: true });
resources = new Resources({ $$inline: true });

const block = {
Expand All @@ -59957,10 +59966,12 @@ var app = (function () {
t2 = space();
create_component(intro.$$.fragment);
t3 = space();
create_component(drawing.$$.fragment);
create_component(knnchart.$$.fragment);
t4 = space();
create_component(conclusion.$$.fragment);
t5 = space();
create_component(drawing.$$.fragment);
t6 = space();
create_component(resources.$$.fragment);
},
l: function claim(nodes) {
Expand All @@ -59975,10 +59986,12 @@ var app = (function () {
insert_dev(target, t2, anchor);
mount_component(intro, target, anchor);
insert_dev(target, t3, anchor);
mount_component(drawing, target, anchor);
mount_component(knnchart, target, anchor);
insert_dev(target, t4, anchor);
mount_component(conclusion, target, anchor);
insert_dev(target, t5, anchor);
mount_component(drawing, target, anchor);
insert_dev(target, t6, anchor);
mount_component(resources, target, anchor);
current = true;
},
Expand All @@ -59989,8 +60002,9 @@ var app = (function () {
transition_in(meta.$$.fragment, local);
transition_in(title.$$.fragment, local);
transition_in(intro.$$.fragment, local);
transition_in(drawing.$$.fragment, local);
transition_in(knnchart.$$.fragment, local);
transition_in(conclusion.$$.fragment, local);
transition_in(drawing.$$.fragment, local);
transition_in(resources.$$.fragment, local);
current = true;
},
Expand All @@ -59999,8 +60013,9 @@ var app = (function () {
transition_out(meta.$$.fragment, local);
transition_out(title.$$.fragment, local);
transition_out(intro.$$.fragment, local);
transition_out(drawing.$$.fragment, local);
transition_out(knnchart.$$.fragment, local);
transition_out(conclusion.$$.fragment, local);
transition_out(drawing.$$.fragment, local);
transition_out(resources.$$.fragment, local);
current = false;
},
Expand All @@ -60013,10 +60028,12 @@ var app = (function () {
if (detaching) detach_dev(t2);
destroy_component(intro, detaching);
if (detaching) detach_dev(t3);
destroy_component(drawing, detaching);
destroy_component(knnchart, detaching);
if (detaching) detach_dev(t4);
destroy_component(conclusion, detaching);
if (detaching) detach_dev(t5);
destroy_component(drawing, detaching);
if (detaching) detach_dev(t6);
destroy_component(resources, detaching);
}
};
Expand Down
2 changes: 1 addition & 1 deletion public/build/bundle.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
<Meta />
<Title />
<Intro />
<!--<KnnChart />-->
<Drawing />
<KnnChart />
<!-- <TextAndMathEquations /> -->
<!-- <ScrollSide /> -->
<!-- <LineChart /> -->
<!-- <ScrollCenter /> -->
<Conclusion />
<Drawing />
<Resources />
Loading

0 comments on commit 23fbd96

Please sign in to comment.