| 47 | static readonly className = 'InputLayer'; |
| 48 | sparse: boolean; |
| 49 | constructor(args: InputLayerArgs) { |
| 50 | super({ |
| 51 | dtype: args.dtype, |
| 52 | name: args.name != null ? args.name : getUid('input').toString() |
| 53 | }); |
| 54 | // Normalize config.batchSize and config.sparse |
| 55 | if (args.batchSize == null) { |
| 56 | args.batchSize = null; |
| 57 | } |
| 58 | if (args.sparse == null) { |
| 59 | args.sparse = false; |
| 60 | } |
| 61 | |
| 62 | this.trainable = false; |
| 63 | this.built = true; |
| 64 | this.sparse = args.sparse; |
| 65 | |
| 66 | if (args.inputShape != null && args.batchInputShape != null) { |
| 67 | throw new ValueError( |
| 68 | 'Only provide the inputShape OR ' + |
| 69 | 'batchInputShape argument to inputLayer, not both at the same time.'); |
| 70 | } |
| 71 | let batchInputShape = args.batchInputShape; |
| 72 | if (batchInputShape == null) { |
| 73 | if (args.inputShape == null) { |
| 74 | throw new ValueError( |
| 75 | 'An InputLayer should be passed either a ' + |
| 76 | '`batchInputShape` or an `inputShape`.'); |
| 77 | } else { |
| 78 | batchInputShape = [args.batchSize].concat(args.inputShape); |
| 79 | } |
| 80 | } else { |
| 81 | // TODO(michaelterry): Backport to PyKeras |
| 82 | if (args.batchSize != null) { |
| 83 | throw new ValueError( |
| 84 | 'Cannot specify batchSize if batchInputShape is ' + |
| 85 | 'specified when creating an InputLayer.'); |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | const dtype = args.dtype || 'float32'; |
| 90 | |
| 91 | this.batchInputShape = batchInputShape; |
| 92 | this.dtype = dtype; |
| 93 | // TODO(michaelterry): Backport this to PyKeras? |
| 94 | this.inputSpec = [{shape: batchInputShape}]; |
| 95 | |
| 96 | const inputTensor = new SymbolicTensor( |
| 97 | this.dtype, this.batchInputShape, this, [], {}, this.name); |
| 98 | inputTensor.nodeIndex = 0; |
| 99 | inputTensor.tensorIndex = 0; |
| 100 | |
| 101 | // Create an input node to add to this.outboundNode. |
| 102 | // (This call has side effects.) |
| 103 | // tslint:disable-next-line:no-unused-expression |
| 104 | new Node({ |
| 105 | outboundLayer: this, |
| 106 | inboundLayers: [], |