feat: Change the model build, create separated encoder and decoder#8
feat: Change the model build, create separated encoder and decoder#8andreanidouglas wants to merge 1 commit intoCodingTrain:mainfrom
Conversation
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.
shiffman
left a comment
There was a problem hiding this comment.
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!
| console.log("Hello Autoencoder 🚂"); | ||
|
|
||
| import * as tf from "@tensorflow/tfjs-node"; | ||
| import * as tf from "@tensorflow/tfjs-node-gpu"; |
There was a problem hiding this comment.
Do I need to install CUDA or anything like that to run tf.js with node GPU?
There was a problem hiding this comment.
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"}); |
There was a problem hiding this comment.
I haven't used tf.model before, is it required for this methodology, or can I keep tf.sequential? Is tf.model preferred?
There was a problem hiding this comment.
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.
| loss: "meanSquaredError", | ||
| }); | ||
| return { decoderLayers, autoencoder }; | ||
| decoder.compile({ |
There was a problem hiding this comment.
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?
| const num = numeral(i).format("0000"); | ||
| const img = await Jimp.read( | ||
| `AutoEncoder_TrainingData/data/square${num}.png` | ||
| `data/square${num}.png` |
There was a problem hiding this comment.
Is there a reason you changed this? I like being able to pull the training data directly from the Processing sketch.
There was a problem hiding this comment.
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
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