* 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)
| 40 | * @returns {tf.LayersModel} the encoder model. |
| 41 | */ |
| 42 | function 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 |
no test coverage detected