* A custom layer used to obtain the last time step of an RNN sequential * output.
| 23 | * output. |
| 24 | */ |
| 25 | class GetLastTimestepLayer extends tf.layers.Layer { |
| 26 | constructor(config) { |
| 27 | super(config || {}); |
| 28 | this.supportMasking = true; |
| 29 | } |
| 30 | |
| 31 | computeOutputShape(inputShape) { |
| 32 | const outputShape = inputShape.slice(); |
| 33 | outputShape.splice(outputShape.length - 2, 1); |
| 34 | return outputShape; |
| 35 | } |
| 36 | |
| 37 | call(input) { |
| 38 | if (Array.isArray(input)) { |
| 39 | input = input[0]; |
| 40 | } |
| 41 | const inputRank = input.shape.length; |
| 42 | tf.util.assert(inputRank === 3, `Invalid input rank: ${inputRank}`); |
| 43 | return input.gather([input.shape[1] - 1], 1).squeeze([1]); |
| 44 | } |
| 45 | |
| 46 | static get className() { |
| 47 | return 'GetLastTimestepLayer'; |
| 48 | } |
| 49 | } |
| 50 | tf.serialization.registerClass(GetLastTimestepLayer); |
| 51 | |
| 52 | /** |
nothing calls this directly
no outgoing calls
no test coverage detected