You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

MapDataset.cs 1.0 kB

4 years ago
4 years ago
12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using Tensorflow.Functions;
  3. using static Tensorflow.Binding;
  4. namespace Tensorflow
  5. {
  6. /// <summary>
  7. /// A `Dataset` that maps a function over elements in its input.
  8. /// </summary>
  9. public class MapDataset : UnaryDataset
  10. {
  11. public MapDataset(IDatasetV2 input_dataset,
  12. Func<Tensor, Tensor> map_func,
  13. bool use_inter_op_parallelism = true,
  14. bool preserve_cardinality = false,
  15. bool use_legacy_function = false) : base(input_dataset)
  16. {
  17. using var func = new ConcreteFunction($"autograph_{map_func.Method.Name}");
  18. var input = tf.placeholder(input_dataset.element_spec[0].dtype);
  19. var output = map_func(input);
  20. func.ToGraph(input, output);
  21. structure = func.OutputStructure;
  22. variant_tensor = ops.map_dataset(input_dataset.variant_tensor,
  23. func,
  24. output_types,
  25. output_shapes);
  26. }
  27. }
  28. }