|
1 | 1 | using System; |
| 2 | +using Tensorflow.Framework.Models; |
2 | 3 | using Tensorflow.Keras.ArgsDefinition; |
3 | 4 | using Tensorflow.Keras.ArgsDefinition.Core; |
4 | 5 | using Tensorflow.Keras.ArgsDefinition.Rnn; |
@@ -471,20 +472,56 @@ public ILayer Flatten(string data_format = null) |
471 | 472 | /// In this case, values of 'None' in the 'shape' argument represent ragged dimensions. For more information about RaggedTensors, see this guide. |
472 | 473 | /// </param> |
473 | 474 | /// <returns>A tensor.</returns> |
474 | | - public Tensors Input(Shape shape, |
| 475 | + public Tensors Input(Shape shape = null, |
475 | 476 | int batch_size = -1, |
476 | 477 | string name = null, |
| 478 | + TF_DataType dtype = TF_DataType.DtInvalid, |
477 | 479 | bool sparse = false, |
478 | | - bool ragged = false) |
| 480 | + Tensor tensor = null, |
| 481 | + bool ragged = false, |
| 482 | + TypeSpec type_spec = null, |
| 483 | + Shape batch_input_shape = null, |
| 484 | + Shape batch_shape = null) |
479 | 485 | { |
480 | | - var input_layer = new InputLayer(new InputLayerArgs |
| 486 | + if(sparse && ragged) |
| 487 | + { |
| 488 | + throw new ValueError("Cannot set both `sparse` and `ragged` to `true` in a Keras `Input`."); |
| 489 | + } |
| 490 | + |
| 491 | + InputLayerArgs input_layer_config = new() |
481 | 492 | { |
482 | | - InputShape = shape, |
483 | | - BatchSize= batch_size, |
484 | 493 | Name = name, |
| 494 | + DType = dtype, |
485 | 495 | Sparse = sparse, |
486 | | - Ragged = ragged |
487 | | - }); |
| 496 | + Ragged = ragged, |
| 497 | + InputTensor = tensor, |
| 498 | + // skip the `type_spec` |
| 499 | + }; |
| 500 | + |
| 501 | + if(shape is not null && batch_input_shape is not null) |
| 502 | + { |
| 503 | + throw new ValueError("Only provide the `shape` OR `batch_input_shape` argument " |
| 504 | + + "to Input, not both at the same time."); |
| 505 | + } |
| 506 | + |
| 507 | + if(batch_input_shape is null && shape is null && tensor is null && type_spec is null) |
| 508 | + { |
| 509 | + throw new ValueError("Please provide to Input a `shape` or a `tensor` or a `type_spec` argument. Note that " + |
| 510 | + "`shape` does not include the batch dimension."); |
| 511 | + } |
| 512 | + |
| 513 | + if(batch_input_shape is not null) |
| 514 | + { |
| 515 | + shape = batch_input_shape["1:"]; |
| 516 | + input_layer_config.BatchInputShape = batch_input_shape; |
| 517 | + } |
| 518 | + else |
| 519 | + { |
| 520 | + input_layer_config.BatchSize = batch_size; |
| 521 | + input_layer_config.InputShape = shape; |
| 522 | + } |
| 523 | + |
| 524 | + var input_layer = new InputLayer(input_layer_config); |
488 | 525 |
|
489 | 526 | return input_layer.InboundNodes[0].Outputs; |
490 | 527 | } |
|
0 commit comments