MCPcopy Create free account
hub / github.com/tensorflow/tfjs-examples / encoder

Function encoder

fashion-mnist-vae/model.js:42–64  ·  view source on GitHub ↗

* The encoder portion of the model. * * @param {object} opts encoder configuration, includnig the following fields: * - originaDim {number} Length of the input flattened image. * - intermediateDim {number} Number of units of the intermediate (i.e., * hidden) dense layer. * - latentDi

(opts)

Source from the content-addressed store, hash-verified

40 * @returns {tf.LayersModel} the encoder model.
41 */
42function encoder(opts) {
43 const {originalDim, intermediateDim, latentDim} = opts;
44
45 const inputs = tf.input({shape: [originalDim], name: 'encoder_input'});
46 const x = tf.layers.dense({units: intermediateDim, activation: 'relu'})
47 .apply(inputs);
48 const zMean = tf.layers.dense({units: latentDim, name: 'z_mean'}).apply(x);
49 const zLogVar =
50 tf.layers.dense({units: latentDim, name: 'z_log_var'}).apply(x);
51
52 const z =
53 new ZLayer({name: 'z', outputShape: [latentDim]}).apply([zMean, zLogVar]);
54
55 const enc = tf.model({
56 inputs: inputs,
57 outputs: [zMean, zLogVar, z],
58 name: 'encoder',
59 });
60
61 // console.log('Encoder Summary');
62 // enc.summary();
63 return enc;
64}
65
66/**
67 * This layer implements the 'reparameterization trick' described in

Callers 3

seq2seq_modelFunction · 0.85
model_test.jsFile · 0.85
trainFunction · 0.85

Calls 1

applyMethod · 0.45

Tested by

no test coverage detected