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.

PbtxtParser.cs 1.9 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. using Newtonsoft.Json;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. namespace TensorFlowNET.Examples.Utility
  6. {
  7. public class PbtxtItem
  8. {
  9. public string name { get; set; }
  10. public int id { get; set; }
  11. public string display_name { get; set; }
  12. }
  13. public class PbtxtItems
  14. {
  15. public List<PbtxtItem> items { get; set; }
  16. }
  17. public class PbtxtParser
  18. {
  19. public static PbtxtItems ParsePbtxtFile(string filePath)
  20. {
  21. string line;
  22. string newText = "{\"items\":[";
  23. using (System.IO.StreamReader reader = new System.IO.StreamReader(filePath))
  24. {
  25. while ((line = reader.ReadLine()) != null)
  26. {
  27. string newline = string.Empty;
  28. if (line.Contains("{"))
  29. {
  30. newline = line.Replace("item", "").Trim();
  31. //newText += line.Insert(line.IndexOf("=") + 1, "\"") + "\",";
  32. newText += newline;
  33. }
  34. else if (line.Contains("}"))
  35. {
  36. newText = newText.Remove(newText.Length - 1);
  37. newText += line;
  38. newText += ",";
  39. }
  40. else
  41. {
  42. newline = line.Replace(":", "\":").Trim();
  43. newline = "\"" + newline;// newline.Insert(0, "\"");
  44. newline += ",";
  45. newText += newline;
  46. }
  47. }
  48. newText = newText.Remove(newText.Length - 1);
  49. newText += "]}";
  50. reader.Close();
  51. }
  52. PbtxtItems items = JsonConvert.DeserializeObject<PbtxtItems>(newText);
  53. return items;
  54. }
  55. }
  56. }

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