How to use the @tensorflow/tfjs-layers.sequential function in @tensorflow/tfjs-layers

To help you get started, we’ve selected a few @tensorflow/tfjs-layers examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tensorflow / tfjs / tfjs-layers / integration_tests / tfjs2keras / tfjs_save.js View on Github external
async function exportDepthwiseCNNModel(exportPath) {
  const model = tfl.sequential();

  // Cover depthwise 2D convoluational layer.
  model.add(tfl.layers.depthwiseConv2d({
    depthMultiplier: 2,
    kernelSize: [3, 3],
    strides: [2, 2],
    inputShape: [40, 40, 3],
    padding: 'valid',
  }));
  model.add(tfl.layers.batchNormalization({}));
  model.add(tfl.layers.activation({activation: 'relu'}));
  model.add(tfl.layers.dropout({rate: 0.5}));
  model.add(tfl.layers.maxPooling2d({poolSize: 2}));
  model.add(tfl.layers.flatten({}));
  model.add(tfl.layers.dense({units: 100, activation: 'softmax'}));
github tensorflow / tfjs / tfjs-layers / integration_tests / tfjs2keras / tfjs_save.js View on Github external
async function exportCNNModel(exportPath) {
  const model = tfl.sequential();

  // Cover separable and non-separable convoluational layers.
  const inputShape = [40, 40, 3];
  model.add(tfl.layers.conv2d({
    filters: 32,
    kernelSize: [3, 3],
    strides: [2, 2],
    inputShape,
    padding: 'valid',
  }));
  model.add(tfl.layers.batchNormalization({}));
  model.add(tfl.layers.activation({activation: 'relu'}));
  model.add(tfl.layers.dropout({rate: 0.5}));
  model.add(tfl.layers.maxPooling2d({poolSize: 2}));
  model.add(tfl.layers.separableConv2d({
    filters: 32,
github tensorflow / tfjs-layers / integration_tests / tfjs2keras / tfjs_save.js View on Github external
async function exportCNNModel(exportPath) {
  const model = tfl.sequential();

  // Cover separable and non-separable convoluational layers.
  const inputShape = [40, 40, 3];
  model.add(tfl.layers.conv2d({
    filters: 32,
    kernelSize: [3, 3],
    strides: [2, 2],
    inputShape,
    padding: 'valid',
  }));
  model.add(tfl.layers.batchNormalization({}));
  model.add(tfl.layers.activation({activation: 'relu'}));
  model.add(tfl.layers.dropout({rate: 0.5}));
  model.add(tfl.layers.maxPooling2d({poolSize: 2}));
  model.add(tfl.layers.separableConv2d({
    filters: 32,
github tensorflow / tfjs-layers / integration_tests / tfjs2keras / tfjs_save.js View on Github external
async function exportMLPModel(exportPath) {
  const model = tfl.sequential();
  // Test both activations encapsulated in other layers and as standalone
  // layers.
  model.add(
      tfl.layers.dense({units: 100, inputShape: [200], activation: 'relu'}));
  model.add(tfl.layers.dense({units: 50, activation: 'elu'}));
  model.add(tfl.layers.dense({units: 24}));
  model.add(tfl.layers.activation({activation: 'elu'}));
  model.add(tfl.layers.dense({units: 8, activation: 'softmax'}));

  await saveModelAndRandomInputsAndOutputs(model, exportPath);
}
github tensorflow / tfjs-layers / integration_tests / tfjs2keras / tfjs_save.js View on Github external
async function exportBidirectionalLSTMModel(exportPath) {
  const model = tfl.sequential();
  const inputDim = 100;
  model.add(tfl.layers.embedding({inputDim, outputDim: 20, inputShape: [10]}));
  // TODO(cais): Investigate why the `tfl.layers.RNN` typing doesn't work.
  const lstm = tfl.layers.lstm({units: 4, goBackwards: true});
  model.add(tfl.layers.bidirectional({layer: lstm, mergeMode: 'concat'}));

  await saveModelAndRandomInputsAndOutputs(model, exportPath, inputDim);
}
github tensorflow / tfjs-layers / integration_tests / tfjs2keras / tfjs_save.js View on Github external
async function exportDepthwiseCNNModel(exportPath) {
  const model = tfl.sequential();

  // Cover depthwise 2D convoluational layer.
  model.add(tfl.layers.depthwiseConv2d({
    depthMultiplier: 2,
    kernelSize: [3, 3],
    strides: [2, 2],
    inputShape: [40, 40, 3],
    padding: 'valid',
  }));
  model.add(tfl.layers.batchNormalization({}));
  model.add(tfl.layers.activation({activation: 'relu'}));
  model.add(tfl.layers.dropout({rate: 0.5}));
  model.add(tfl.layers.maxPooling2d({poolSize: 2}));
  model.add(tfl.layers.flatten({}));
  model.add(tfl.layers.dense({units: 100, activation: 'softmax'}));
github tensorflow / tfjs-layers / integration_tests / tfjs2keras / tfjs_save.js View on Github external
async function exportSimpleRNNModel(exportPath) {
  const model = tfl.sequential();
  const inputDim = 100;
  model.add(tfl.layers.embedding({inputDim, outputDim: 20, inputShape: [10]}));
  model.add(tfl.layers.simpleRNN({units: 4}));

  await saveModelAndRandomInputsAndOutputs(model, exportPath, inputDim);
}
github tensorflow / tfjs-layers / integration_tests / tfjs2keras / tfjs_save.js View on Github external
async function exportGRUModel(exportPath) {
  const model = tfl.sequential();
  const inputDim = 100;
  model.add(tfl.layers.embedding({inputDim, outputDim: 20, inputShape: [10]}));
  model.add(tfl.layers.gru({units: 4, goBackwards: true}));

  await saveModelAndRandomInputsAndOutputs(model, exportPath, inputDim);
}
github tensorflow / tfjs-layers / integration_tests / tfjs2keras / tfjs_save.js View on Github external
async function exportTimeDistributedLSTMModel(exportPath) {
  const model = tfl.sequential();
  const inputDim = 100;
  model.add(tfl.layers.embedding({inputDim, outputDim: 20, inputShape: [10]}));
  model.add(tfl.layers.lstm({units: 4, returnSequences: true}));
  model.add(tfl.layers.timeDistributed({
    layer:
        tfl.layers.dense({units: 2, useBias: false, activation: 'softmax'})
  }));

  await saveModelAndRandomInputsAndOutputs(model, exportPath, inputDim);
}