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.

TrainSaverTest.cs 957 B

123456789101112131415161718192021222324252627282930313233
  1. using Microsoft.VisualStudio.TestTools.UnitTesting;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using Tensorflow;
  6. namespace TensorFlowNET.UnitTest
  7. {
  8. [TestClass]
  9. public class TrainSaverTest : Python
  10. {
  11. [TestMethod]
  12. public void Save()
  13. {
  14. var v1 = tf.get_variable("v1", shape: new TensorShape(3), initializer: tf.zeros_initializer);
  15. var v2 = tf.get_variable("v2", shape: new TensorShape(5), initializer: tf.zeros_initializer);
  16. var inc_v1 = v1.assign(v1 + 1.0f);
  17. var dec_v2 = v2.assign(v2 - 1.0f);
  18. // Add an op to initialize the variables.
  19. var init_op = tf.global_variables_initializer();
  20. // Add ops to save and restore all the variables.
  21. var saver = tf.train.Saver();
  22. with<Session>(tf.Session(), sess =>
  23. {
  24. sess.run(init_op);
  25. });
  26. }
  27. }
  28. }

tensorflow框架的.NET版本,提供了丰富的特性和API,可以借此很方便地在.NET平台下搭建深度学习训练与推理流程。