Skip to content

feat: Change the model build, create separated encoder and decoder #8

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

andreanidouglas
Copy link

You dont need to keep track of the decoder layers in order to build it
later. Just craete them separatedelly and add to a everything to a
single model.

Model trained with 7000 images can be found on the link below:
https://1drv.ms/u/s!AmmF3hm-u1wQia5nSnLq1HAGk0Gsjw?e=GFO1vH

You dont need to keep track of the decoder layers in order to build it
later. Just craete them separatedelly and add to a everything to a
single model.
Copy link
Member

@shiffman shiffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you so much for this, it's incredibly helpful! I added some questions and comments but don't feel you have to answer all of them. Like with #3, I'm trying to decide how best to incorporate pull requests like this, if I should merge them or use them as a guide for a future session / video. I like having the code reflect what I did in the streams, but these are critical and important improvements!

@@ -1,6 +1,6 @@
console.log("Hello Autoencoder 🚂");

import * as tf from "@tensorflow/tfjs-node";
import * as tf from "@tensorflow/tfjs-node-gpu";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do I need to install CUDA or anything like that to run tf.js with node GPU?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, TensorFlow GPU only supports cuda.

From my Python experience it needs an extremely specific version of cuda, but for JS it worked with out of the box 11.2 version. I only used the GPU version to speed up training, the CPU version works fine.

const l4 = tf.layers.dense({units: 4, activation: "relu"}).apply(l3);
let encoded = tf.layers.dense({units: 2, activation: "relu", name: "encoder_output"}).apply(l4);

let encoder = tf.model({inputs: encoder_input, outputs: encoded, name: "encoder"});
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't used tf.model before, is it required for this methodology, or can I keep tf.sequential? Is tf.model preferred?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from https://js.tensorflow.org/api/latest/#sequential

The key difference between tf.model() and tf.sequential() is that tf.model() is more generic, supporting an arbitrary graph (without cycles) of layers. tf.sequential() is less generic and supports only a linear stack of layers.

autoencoder.compile({
optimizer: "adam",
loss: "meanSquaredError",
});
return { decoderLayers, autoencoder };
decoder.compile({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering when I built this if the decoder has to be "compiled" with an optimizer and loss given I'm not training it, only using it for inference?

@@ -179,7 +136,7 @@ async function loadImages(total) {
for (let i = 0; i < total; i++) {
const num = numeral(i).format("0000");
const img = await Jimp.read(
`AutoEncoder_TrainingData/data/square${num}.png`
`data/square${num}.png`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason you changed this? I like being able to pull the training data directly from the Processing sketch.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no specific reason, i didn't have processing installed, so i created a Python script to generate the images, i only changed to the output of that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants