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.

LayersTest.cs 2.6 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Tensorflow.Keras.Engine;
  6. using Tensorflow.Keras.Layers;
  7. using NumSharp;
  8. using Tensorflow.UnitTest;
  9. using static Tensorflow.Binding;
  10. namespace TensorFlowNET.UnitTest.Keras
  11. {
  12. /// <summary>
  13. /// https://www.tensorflow.org/versions/r2.3/api_docs/python/tf/keras/layers
  14. /// </summary>
  15. [TestClass]
  16. public class LayersTest : EagerModeTestBase
  17. {
  18. [TestMethod]
  19. public void Sequential()
  20. {
  21. var model = tf.keras.Sequential();
  22. model.add(tf.keras.Input(shape: 16));
  23. }
  24. /// <summary>
  25. /// https://www.tensorflow.org/api_docs/python/tf/keras/layers/Embedding
  26. /// </summary>
  27. [TestMethod, Ignore]
  28. public void Embedding()
  29. {
  30. var model = tf.keras.Sequential();
  31. var layer = tf.keras.layers.Embedding(7, 2, input_length: 4);
  32. model.add(layer);
  33. // the model will take as input an integer matrix of size (batch,
  34. // input_length).
  35. // the largest integer (i.e. word index) in the input should be no larger
  36. // than 999 (vocabulary size).
  37. // now model.output_shape == (None, 10, 64), where None is the batch
  38. // dimension.
  39. var input_array = np.array(new int[,]
  40. {
  41. { 1, 2, 3, 4 },
  42. { 2, 3, 4, 5 },
  43. { 3, 4, 5, 6 }
  44. });
  45. model.compile("rmsprop", "mse");
  46. var output_array = model.predict(input_array);
  47. Assert.AreEqual((32, 10, 64), output_array.TensorShape);
  48. }
  49. /// <summary>
  50. /// https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense
  51. /// </summary>
  52. [TestMethod]
  53. public void Dense()
  54. {
  55. // Create a `Sequential` model and add a Dense layer as the first layer.
  56. var model = tf.keras.Sequential();
  57. model.add(tf.keras.Input(shape: 16));
  58. model.add(tf.keras.layers.Dense(32, activation: "relu"));
  59. // Now the model will take as input arrays of shape (None, 16)
  60. // and output arrays of shape (None, 32).
  61. // Note that after the first layer, you don't need to specify
  62. // the size of the input anymore:
  63. model.add(tf.keras.layers.Dense(32));
  64. Assert.AreEqual((-1, 32), model.output_shape);
  65. }
  66. [TestMethod]
  67. public void SimpleRNN()
  68. {
  69. }
  70. }
  71. }