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.4 kB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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.models.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]
  28. public void Embedding()
  29. {
  30. var model = new Sequential();
  31. var layer = tf.keras.layers.Embedding(1000, 64, input_length: 10);
  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.random.randint(1000, size: (32, 10));
  40. // model.compile("rmsprop", "mse");
  41. // output_array = model.predict(input_array)
  42. }
  43. /// <summary>
  44. /// https://www.tensorflow.org/api_docs/python/tf/keras/layers/Dense
  45. /// </summary>
  46. [TestMethod]
  47. public void Dense()
  48. {
  49. // Create a `Sequential` model and add a Dense layer as the first layer.
  50. var model = tf.keras.Sequential();
  51. model.add(tf.keras.Input(shape: 16));
  52. model.add(tf.keras.layers.Dense(32, activation: tf.keras.activations.Relu));
  53. // Now the model will take as input arrays of shape (None, 16)
  54. // and output arrays of shape (None, 32).
  55. // Note that after the first layer, you don't need to specify
  56. // the size of the input anymore:
  57. model.add(tf.keras.layers.Dense(32));
  58. Assert.AreEqual((-1, 32), model.output_shape);
  59. }
  60. [TestMethod]
  61. public void SimpleRNN()
  62. {
  63. }
  64. }
  65. }