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.

Resizing.cs 1.3 kB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Text;
  5. using Tensorflow.Keras.ArgsDefinition;
  6. using Tensorflow.Keras.Saving;
  7. using Tensorflow.Common.Types;
  8. namespace Tensorflow.Keras.Layers
  9. {
  10. /// <summary>
  11. /// Resize the batched image input to target height and width.
  12. /// The input should be a 4-D tensor in the format of NHWC.
  13. /// </summary>
  14. public class Resizing : PreprocessingLayer
  15. {
  16. ResizingArgs args;
  17. public Resizing(ResizingArgs args) : base(args)
  18. {
  19. this.args = args;
  20. }
  21. protected override Tensors Call(Tensors inputs, Tensors state = null, bool? training = null, IOptionalArgs? optional_args = null)
  22. {
  23. return image_ops_impl.resize_images_v2(inputs, new[] { args.Height, args.Width }, method: args.Interpolation);
  24. }
  25. public override Shape ComputeOutputShape(Shape input_shape)
  26. {
  27. return new Shape(input_shape.dims[0], args.Height, args.Width, input_shape.dims[3]);
  28. }
  29. public static Resizing from_config(JObject config)
  30. {
  31. var args = JsonConvert.DeserializeObject<ResizingArgs>(config.ToString());
  32. args.IsFromConfig = true;
  33. return new Resizing(args);
  34. }
  35. }
  36. }