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.

Main.cs 2.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Text;
  5. using Tensorflow;
  6. using Tensorflow.Contrib.Train;
  7. using Tensorflow.Estimators;
  8. using Tensorflow.Models.ObjectDetection;
  9. using static Tensorflow.Binding;
  10. namespace TensorFlowNET.Examples.ImageProcessing.ObjectDetection
  11. {
  12. public class Main : IExample
  13. {
  14. public bool Enabled { get; set; } = true;
  15. public bool IsImportingGraph { get; set; } = true;
  16. public string Name => "Object Detection API";
  17. ModelLib model_lib = new ModelLib();
  18. string model_dir = "D:/Projects/PythonLab/tf-models/research/object_detection/models/model";
  19. string pipeline_config_path = "ObjectDetection/Models/faster_rcnn_resnet101_voc07.config";
  20. int num_train_steps = 50;
  21. int sample_1_of_n_eval_examples = 1;
  22. int sample_1_of_n_eval_on_train_examples = 5;
  23. public bool Run()
  24. {
  25. var config = tf.estimator.RunConfig(model_dir: model_dir);
  26. var train_and_eval_dict = model_lib.create_estimator_and_inputs(run_config: config,
  27. hparams: new HParams(true),
  28. pipeline_config_path: pipeline_config_path,
  29. train_steps: num_train_steps,
  30. sample_1_of_n_eval_examples: sample_1_of_n_eval_examples,
  31. sample_1_of_n_eval_on_train_examples: sample_1_of_n_eval_on_train_examples);
  32. var estimator = train_and_eval_dict.estimator;
  33. var train_input_fn = train_and_eval_dict.train_input_fn;
  34. var eval_input_fns = train_and_eval_dict.eval_input_fns;
  35. var eval_on_train_input_fn = train_and_eval_dict.eval_on_train_input_fn;
  36. var predict_input_fn = train_and_eval_dict.predict_input_fn;
  37. var train_steps = train_and_eval_dict.train_steps;
  38. var (train_spec, eval_specs) = model_lib.create_train_and_eval_specs(train_input_fn,
  39. eval_input_fns,
  40. eval_on_train_input_fn,
  41. predict_input_fn,
  42. train_steps,
  43. eval_on_train_data: false);
  44. // Currently only a single Eval Spec is allowed.
  45. tf.estimator.train_and_evaluate(estimator, train_spec, eval_specs[0]);
  46. return true;
  47. }
  48. public Graph BuildGraph()
  49. {
  50. throw new NotImplementedException();
  51. }
  52. public Graph ImportGraph()
  53. {
  54. throw new NotImplementedException();
  55. }
  56. public void Predict(Session sess)
  57. {
  58. throw new NotImplementedException();
  59. }
  60. public void PrepareData()
  61. {
  62. }
  63. public void Train(Session sess)
  64. {
  65. throw new NotImplementedException();
  66. }
  67. void IExample.Test(Session sess)
  68. {
  69. throw new NotImplementedException();
  70. }
  71. }
  72. }