Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
d09b86d
[Core] Introduce convLSTM2D to KernelBackend
dikatok Jul 31, 2020
50f34cb
initial skeleton for ConvLSTM2DCell
dikatok Jul 31, 2020
ebc2535
ConvLSTM2DCellArgs to extend LSTMCellLayerArgs
dikatok Aug 3, 2020
960a236
Merge branch 'master' into conv-lstm
dikatok Aug 3, 2020
0a5c622
Merge branch 'conv-lstm' of https://github.com/dikatok/tfjs into conv…
dikatok Aug 3, 2020
0b58c7e
Create helper function getCartesianProductOfValues
dikatok Aug 4, 2020
78656a7
Merge branch 'master' into conv-lstm
dikatok Aug 5, 2020
5cb8c8a
ConvLSTM2DCell
dikatok Aug 5, 2020
4fa4bca
Clean ConvLSTM2DCell
dikatok Aug 5, 2020
886e7a1
Skeleton for ConvLSTM2D
dikatok Aug 5, 2020
a93a50d
Support more than 3D input spec in RNN layer
dikatok Aug 5, 2020
25e3a9f
Test ConvLSTM2D Serialization and Deserialization
dikatok Aug 5, 2020
e4bffa9
Tidy up convolutional_recurrent imports
dikatok Aug 5, 2020
a9cd1e0
Exports convLstm2d in export_layers
dikatok Aug 5, 2020
56a1217
Unit test ConvLSTM2D Symbolic
dikatok Aug 5, 2020
1d5fcd0
Omit cell arg from ConvLSTM2D
dikatok Aug 5, 2020
27cd0e7
More ConvLSTM2D Symbolic tests
dikatok Aug 5, 2020
3c41f9a
update convolutional_recurrent tests
dikatok Aug 6, 2020
85fc2a5
Revert "update convolutional_recurrent tests"
dikatok Aug 6, 2020
7dbbd45
Update convolutional_recurrent tests
dikatok Aug 6, 2020
806152d
Add reference Python code to obtain results for ConvLSTM2DCell test
dikatok Aug 6, 2020
5748c51
Revert "Add reference Python code to obtain results for ConvLSTM2DCel…
dikatok Aug 6, 2020
15032e4
Add reference Python code to obtain results for ConvLSTM2DCell test
dikatok Aug 6, 2020
49d387c
Revert "[Core] Introduce convLSTM2D to KernelBackend"
dikatok Aug 6, 2020
c2c0ba5
Merge branch 'master' into conv-lstm
dikatok Aug 7, 2020
9e08898
Rename ConvLSTM2D recurrentKernel to recurrent_kernel
dikatok Aug 11, 2020
74972f8
Merge branch 'conv-lstm' of https://github.com/dikatok/tfjs into conv…
dikatok Aug 11, 2020
e41ad12
Merge branch 'master' into conv-lstm
dikatok Aug 11, 2020
ed69273
Merge branch 'master' into conv-lstm
dikatok Aug 12, 2020
d091cc0
Fix mul with undefined dropout
dikatok Aug 12, 2020
9157a54
Fix dropout not created
dikatok Aug 12, 2020
15cf9c3
Allow boolean in getCartesianProductOfValues
dikatok Aug 12, 2020
ff799f8
ConvLSTM2D Tensor args combination tests
dikatok Aug 12, 2020
cc131c7
Merge branch 'conv-lstm' of https://github.com/dikatok/tfjs into conv…
dikatok Aug 12, 2020
52cdced
Clean up convolutional_recurrent_test.ts
dikatok Aug 13, 2020
d30a886
Unit test ConvLSTM2D Tensor
dikatok Aug 13, 2020
425c40a
ConvLSTM2D unit test - nested model and BPPT
dikatok Aug 13, 2020
e796f39
Merge branch 'master' into conv-lstm
dikatok Aug 13, 2020
77e755b
BPPT > BPTT
dikatok Aug 13, 2020
9be0ed9
Merge branch 'conv-lstm' of https://github.com/dikatok/tfjs into conv…
dikatok Aug 13, 2020
06ab1e8
Merge branch 'master' into conv-lstm
dikatok Aug 16, 2020
592dc46
Merge branch 'conv-lstm' of https://github.com/dikatok/tfjs into conv…
dikatok Aug 16, 2020
8b1cc45
Re-factor convolutional_recurrent to not directly extends RNN classes…
dikatok Aug 17, 2020
a349db7
Merge branch 'master' into conv-lstm
dikatok Aug 17, 2020
38a20d2
Merge branch 'master' into conv-lstm
dikatok Aug 27, 2020
4d475e2
code review fix
dikatok Sep 1, 2020
ed190d2
Merge branch 'conv-lstm' of https://github.com/dikatok/tfjs into conv…
dikatok Sep 1, 2020
9e7227e
Merge branch 'master' into conv-lstm
dikatok Sep 1, 2020
d5f4417
code review fix: more meaningful BPTT tests
dikatok Sep 1, 2020
aac3b79
Merge branch 'conv-lstm' of https://github.com/dikatok/tfjs into conv…
dikatok Sep 1, 2020
4864f63
code review fix: fix golden value python code indentation
dikatok Sep 1, 2020
5891fd0
combine generateDropoutMask function for both rnn and convrnn
dikatok Sep 1, 2020
53c9008
fix lint error
dikatok Sep 1, 2020
df871e9
jsdoc
dikatok Sep 1, 2020
a2a177c
fix jsdoc
dikatok Sep 1, 2020
bdff063
update convlstm jsdoc to use tf namespace
dikatok Sep 2, 2020
44d5ba3
fix snippets
dikatok Sep 3, 2020
b2e4582
Merge branch 'master' into conv-lstm
dikatok Sep 3, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 69 additions & 0 deletions tfjs-layers/src/exports_layers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {input} from './exports';
import {ELU, ELULayerArgs, LeakyReLU, LeakyReLULayerArgs, PReLU, PReLULayerArgs, ReLU, ReLULayerArgs, Softmax, SoftmaxLayerArgs, ThresholdedReLU, ThresholdedReLULayerArgs} from './layers/advanced_activations';
import {Conv1D, Conv2D, Conv2DTranspose, Conv3D, ConvLayerArgs, Cropping2D, Cropping2DLayerArgs, SeparableConv2D, SeparableConvLayerArgs, UpSampling2D, UpSampling2DLayerArgs} from './layers/convolutional';
import {DepthwiseConv2D, DepthwiseConv2DLayerArgs} from './layers/convolutional_depthwise';
import {ConvLSTM2D, ConvLSTM2DArgs, ConvLSTM2DCell, ConvLSTM2DCellArgs} from './layers/convolutional_recurrent';
import {Activation, ActivationLayerArgs, Dense, DenseLayerArgs, Dropout, DropoutLayerArgs, Flatten, FlattenLayerArgs, Masking, MaskingArgs, Permute, PermuteLayerArgs, RepeatVector, RepeatVectorLayerArgs, Reshape, ReshapeLayerArgs, SpatialDropout1D, SpatialDropout1DLayerConfig} from './layers/core';
import {Embedding, EmbeddingLayerArgs} from './layers/embeddings';
import {Add, Average, Concatenate, ConcatenateLayerArgs, Dot, DotLayerArgs, Maximum, Minimum, Multiply} from './layers/merge';
Expand Down Expand Up @@ -1352,6 +1353,74 @@ export function simpleRNNCell(args: SimpleRNNCellLayerArgs): RNNCell {
return new SimpleRNNCell(args);
}

/**
* Convolutional LSTM layer - Xingjian Shi 2015.
*
* This is an `ConvRNN2D` layer consisting of one `ConvLSTM2DCell`. However,
* unlike the underlying `ConvLSTM2DCell`, the `apply` method of `ConvLSTM2D`
* operates on a sequence of inputs. The shape of the input (not including the
* first, batch dimension) needs to be 4-D, with the first dimension being time
* steps. For example:
*
* ```js
* const filters = 3;
* const kernelSize = 3;
*
* const batchSize = 4;
* const sequenceLength = 2;
* const size = 5;
* const channels = 3;
*
* const inputShape = [batchSize, sequenceLength, size, size, channels];
* const input = tf.ones(inputShape);
*
* const layer = tf.layers.convLstm2d({filters, kernelSize});
*
* const output = layer.apply(input);
* ```
*/
/** @doc {heading: 'Layers', subheading: 'Recurrent', namespace: 'layers'} */
export function convLstm2d(args: ConvLSTM2DArgs): ConvLSTM2D {
return new ConvLSTM2D(args);
}

/**
* Cell class for `ConvLSTM2D`.
*
* `ConvLSTM2DCell` is distinct from the `ConvRNN2D` subclass `ConvLSTM2D` in
* that its `call` method takes the input data of only a single time step and
* returns the cell's output at the time step, while `ConvLSTM2D` takes the
* input data over a number of time steps. For example:
*
* ```js
* const filters = 3;
* const kernelSize = 3;
*
* const sequenceLength = 1;
* const size = 5;
* const channels = 3;
*
* const inputShape = [sequenceLength, size, size, channels];
* const input = tf.ones(inputShape);
*
* const cell = tf.layers.convLstm2dCell({filters, kernelSize});
*
* cell.build(input.shape);
*
* const outputSize = size - kernelSize + 1;
* const outShape = [sequenceLength, outputSize, outputSize, filters];
*
* const initialH = tf.zeros(outShape);
* const initialC = tf.zeros(outShape);
*
* const [o, h, c] = cell.call([input, initialH, initialC], {});
* ```
*/
/** @doc {heading: 'Layers', subheading: 'Recurrent', namespace: 'layers'} */
export function convLstm2dCell(args: ConvLSTM2DCellArgs): ConvLSTM2DCell {
return new ConvLSTM2DCell(args);
}

/**
* Base class for recurrent layers.
*
Expand Down
5 changes: 2 additions & 3 deletions tfjs-layers/src/initializers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,8 @@ export class Orthogonal extends Initializer {

apply(shape: Shape, dtype?: DataType): Tensor {
return tidy(() => {
if (shape.length !== 2) {
throw new NotImplementedError(
'The Orthogonal Initializer does not support non-2D shapes yet.');
if (shape.length < 2) {
Copy link
Contributor Author

@dikatok dikatok Aug 5, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dsmilkov @pyu10055

I modified this check since the default recurrent initializer in ConvLSTM2DCell is orthogonal which needs to support 4D.

This update seems to be inline too with Python implementation (link below).

https://github.com/tensorflow/tensorflow/blob/6016e8009ff8d9b3afa5ae5bafd052ed51d22f74/tensorflow/python/ops/init_ops.py#L571

throw new NotImplementedError('Shape must be at least 2D.');
}
if (shape[0] * shape[1] > 2000) {
console.warn(
Expand Down
Loading