- 
                Notifications
    
You must be signed in to change notification settings  - Fork 2k
 
Support for ConvLSTM2D #3702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for ConvLSTM2D #3702
Conversation
| if (shape.length !== 2) { | ||
| throw new NotImplementedError( | ||
| 'The Orthogonal Initializer does not support non-2D shapes yet.'); | ||
| if (shape.length < 2) { | 
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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).
| 
           Known incompatible things: 
  | 
    
          
How verbose would this docstring need to be? Actually, I was following the way it is structured in recurrent cells, not quite sure about the why either since I could not find any from the commit changes. Should I update the one in recurrent.ts with mine? I think it looks cleaner.  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How verbose would this docstring need to be?
What you added seems fine to me.
Actually, I was following the way it is structured in recurrent cells, not quite sure about the why either since I could not find any from the commit changes.
I understand it now.
Should I update the one in recurrent.ts with mine? I think it looks cleaner.
Yes please. Make sure they are functionally equivalent (they are covered by tests, so as long as tests all pass we are good).
Reviewable status: 0 of 1 approvals obtained (waiting on @dikatok, @dsmilkov, and @pyu10055)
tfjs-layers/src/layers/convolutional_recurrent.ts, line 127 at r6 (raw file):
Previously, caisq (Shanqing Cai) wrote…
if (this.cell.dropoutMask != null) { tfc.dispose(this.cell.dropoutMask); this.cell.dropoutMask = null; }I'm not sure I understand the logic here. Why discard
dropoutMaskif it is set?
I think I understand now. The previous dropout mask should be disposed to make way for new ones.
tfjs-layers/src/layers/convolutional_recurrent_test.ts, line 520 at r9 (raw file):
'padding': padding,
Please fix the indentation in the Python code here.
Same below.
tfjs-layers/src/layers/convolutional_recurrent_test.ts, line 536 at r9 (raw file):
Quoted 4 lines of code…
s_1 = np.ones([batch_size, sequence_len, data_size, data_size, * data_channel]) xs_2 = np.zeros([batch_size, sequence_len, data_size, * data_size, data_channel]) xs = np.concatenate([xs_1, xs_2], 0) ys = * np.array([[1], [1], [1], [1], [0], [0], [0], [0]])
The new line characters are incorrectly discarded, it appears. Can you fix it?
Same for the Python code in the comments below.
| 
           @caisq Done! Thanks for the quick feedback loop, by the way, I thought the PR would be dangling for quite a while. Also, would you mind taking a look at my previous comments up there and see if you have any suggestions?  | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 
           Looks like there are lint errors. 
 @dikatok Can you run   | 
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reviewed 1 of 3 files at r3, 1 of 3 files at r5, 2 of 6 files at r6, 2 of 3 files at r10, 1 of 1 files at r11.
Reviewable status:complete! 2 of 1 approvals obtained (waiting on @dikatok, @dsmilkov, and @pyu10055)
tfjs-layers/src/exports_layers.ts, line 1356 at r11 (raw file):
} export function convLstm2d(args: ConvLSTM2DArgs): ConvLSTM2D {
are jsdoc missing for these two methods?
| 
           @dikatok The code snippet in the comments should use  const filters = 3;
const kernelSize = 3;
const sequenceLength = 1;
const size = 5;
const channels = 3;
const inputShape = [sequenceLength, size, size, channels];
const input = tfc.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 = tfc.zeros(outShape);
const initialC = tfc.zeros(outShape);
const [o, h, c] = cell.call([x, initialH, initialC], {}); | 
    
| 
           @caisq ah okay, will fix it later  | 
    
| 
           @caisq can this jsdoc assertion performed locally? or it is only run in CI?  | 
    
| 
           @dikatok The snippet-testing code is here: I'm not sure about the correct command to invoke it. But you can try figuring it out or maybe @pyu10055 can tell you more. It runs on CI for sure.  | 
    
| 
           Actually, running   | 
    
| 
           Ah my bad, it should be fixed now. About these issues I encountered earlier, should they be handled in separate issues/PR in the future? 
  | 
    
| 
           @pyu10055 PTAL? I think PR is ready to merge.  | 
    
| 
           @caisq BTW, is it acceptable for outside contributors like me to do code refactoring? I kind of want to refactor the   | 
    
| 
           @dikatok I think it is acceptable. I'd suggest doing it as a separate PR from this one, though.  | 
    
Support for ConvLSTM2D.
Fixes #3637.
This change is