1 | /**
|
2 | * @license
|
3 | * Copyright 2018 Google LLC
|
4 | *
|
5 | * Use of this source code is governed by an MIT-style
|
6 | * license that can be found in the LICENSE file or at
|
7 | * https://opensource.org/licenses/MIT.
|
8 | * =============================================================================
|
9 | */
|
10 | /// <amd-module name="@tensorflow/tfjs-layers/dist/exports" />
|
11 | /**
|
12 | * Exported functions.
|
13 | */
|
14 | import { BaseCallbackConstructor } from './base_callbacks';
|
15 | import { ContainerArgs } from './engine/container';
|
16 | import { InputConfig } from './engine/input_layer';
|
17 | import { SymbolicTensor } from './engine/topology';
|
18 | import { LayersModel } from './engine/training';
|
19 | import { Sequential, SequentialArgs } from './models';
|
20 | export { loadLayersModel } from './models';
|
21 | /**
|
22 | * A model is a data structure that consists of `Layers` and defines inputs
|
23 | * and outputs.
|
24 | *
|
25 | * The key difference between `tf.model` and `tf.sequential` is that
|
26 | * `tf.model` is more generic, supporting an arbitrary graph (without
|
27 | * cycles) of layers. `tf.sequential` is less generic and supports only a linear
|
28 | * stack of layers.
|
29 | *
|
30 | * When creating a `tf.LayersModel`, specify its input(s) and output(s). Layers
|
31 | * are used to wire input(s) to output(s).
|
32 | *
|
33 | * For example, the following code snippet defines a model consisting of
|
34 | * two `dense` layers, with 10 and 4 units, respectively.
|
35 | *
|
36 | * ```js
|
37 | * // Define input, which has a size of 5 (not including batch dimension).
|
38 | * const input = tf.input({shape: [5]});
|
39 | *
|
40 | * // First dense layer uses relu activation.
|
41 | * const denseLayer1 = tf.layers.dense({units: 10, activation: 'relu'});
|
42 | * // Second dense layer uses softmax activation.
|
43 | * const denseLayer2 = tf.layers.dense({units: 4, activation: 'softmax'});
|
44 | *
|
45 | * // Obtain the output symbolic tensor by applying the layers on the input.
|
46 | * const output = denseLayer2.apply(denseLayer1.apply(input));
|
47 | *
|
48 | * // Create the model based on the inputs.
|
49 | * const model = tf.model({inputs: input, outputs: output});
|
50 | *
|
51 | * // The model can be used for training, evaluation and prediction.
|
52 | * // For example, the following line runs prediction with the model on
|
53 | * // some fake data.
|
54 | * model.predict(tf.ones([2, 5])).print();
|
55 | * ```
|
56 | * See also:
|
57 | * `tf.sequential`, `tf.loadLayersModel`.
|
58 | *
|
59 | * @doc {heading: 'Models', subheading: 'Creation'}
|
60 | */
|
61 | export declare function model(args: ContainerArgs): LayersModel;
|
62 | /**
|
63 | * Creates a `tf.Sequential` model. A sequential model is any model where the
|
64 | * outputs of one layer are the inputs to the next layer, i.e. the model
|
65 | * topology is a simple 'stack' of layers, with no branching or skipping.
|
66 | *
|
67 | * This means that the first layer passed to a `tf.Sequential` model should have
|
68 | * a defined input shape. What that means is that it should have received an
|
69 | * `inputShape` or `batchInputShape` argument, or for some type of layers
|
70 | * (recurrent, Dense...) an `inputDim` argument.
|
71 | *
|
72 | * The key difference between `tf.model` and `tf.sequential` is that
|
73 | * `tf.sequential` is less generic, supporting only a linear stack of layers.
|
74 | * `tf.model` is more generic and supports an arbitrary graph (without
|
75 | * cycles) of layers.
|
76 | *
|
77 | * Examples:
|
78 | *
|
79 | * ```js
|
80 | * const model = tf.sequential();
|
81 | *
|
82 | * // First layer must have an input shape defined.
|
83 | * model.add(tf.layers.dense({units: 32, inputShape: [50]}));
|
84 | * // Afterwards, TF.js does automatic shape inference.
|
85 | * model.add(tf.layers.dense({units: 4}));
|
86 | *
|
87 | * // Inspect the inferred shape of the model's output, which equals
|
88 | * // `[null, 4]`. The 1st dimension is the undetermined batch dimension; the
|
89 | * // 2nd is the output size of the model's last layer.
|
90 | * console.log(JSON.stringify(model.outputs[0].shape));
|
91 | * ```
|
92 | *
|
93 | * It is also possible to specify a batch size (with potentially undetermined
|
94 | * batch dimension, denoted by "null") for the first layer using the
|
95 | * `batchInputShape` key. The following example is equivalent to the above:
|
96 | *
|
97 | * ```js
|
98 | * const model = tf.sequential();
|
99 | *
|
100 | * // First layer must have a defined input shape
|
101 | * model.add(tf.layers.dense({units: 32, batchInputShape: [null, 50]}));
|
102 | * // Afterwards, TF.js does automatic shape inference.
|
103 | * model.add(tf.layers.dense({units: 4}));
|
104 | *
|
105 | * // Inspect the inferred shape of the model's output.
|
106 | * console.log(JSON.stringify(model.outputs[0].shape));
|
107 | * ```
|
108 | *
|
109 | * You can also use an `Array` of already-constructed `Layer`s to create
|
110 | * a `tf.Sequential` model:
|
111 | *
|
112 | * ```js
|
113 | * const model = tf.sequential({
|
114 | * layers: [tf.layers.dense({units: 32, inputShape: [50]}),
|
115 | * tf.layers.dense({units: 4})]
|
116 | * });
|
117 | * console.log(JSON.stringify(model.outputs[0].shape));
|
118 | * ```
|
119 | *
|
120 | * @doc {heading: 'Models', subheading: 'Creation'}
|
121 | */
|
122 | export declare function sequential(config?: SequentialArgs): Sequential;
|
123 | /**
|
124 | * Used to instantiate an input to a model as a `tf.SymbolicTensor`.
|
125 | *
|
126 | * Users should call the `input` factory function for
|
127 | * consistency with other generator functions.
|
128 | *
|
129 | * Example:
|
130 | *
|
131 | * ```js
|
132 | * // Defines a simple logistic regression model with 32 dimensional input
|
133 | * // and 3 dimensional output.
|
134 | * const x = tf.input({shape: [32]});
|
135 | * const y = tf.layers.dense({units: 3, activation: 'softmax'}).apply(x);
|
136 | * const model = tf.model({inputs: x, outputs: y});
|
137 | * model.predict(tf.ones([2, 32])).print();
|
138 | * ```
|
139 | *
|
140 | * Note: `input` is only necessary when using `model`. When using
|
141 | * `sequential`, specify `inputShape` for the first layer or use `inputLayer`
|
142 | * as the first layer.
|
143 | *
|
144 | * @doc {heading: 'Models', subheading: 'Inputs'}
|
145 | */
|
146 | export declare function input(config: InputConfig): SymbolicTensor;
|
147 | export declare function registerCallbackConstructor(verbosityLevel: number, callbackConstructor: BaseCallbackConstructor): void;
|