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.

ImageRecognition.cs 880 B

12345678910111213141516171819202122232425262728293031
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.IO.Compression;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Text;
  8. using Tensorflow;
  9. namespace TensorFlowNET.Examples
  10. {
  11. public class ImageRecognition : Python, IExample
  12. {
  13. public void Run()
  14. {
  15. var graph = new Graph();
  16. // 从文件加载序列化的GraphDef
  17. //导入GraphDef
  18. graph.Import("tmp/tensorflow_inception_graph.pb");
  19. with<Session>(tf.Session(graph), sess =>
  20. {
  21. var labels = File.ReadAllLines("tmp/imagenet_comp_graph_label_strings.txt");
  22. var files = Directory.GetFiles("img");
  23. foreach(var file in files)
  24. {
  25. var tensor = new Tensor(File.ReadAllBytes(file));
  26. }
  27. });
  28. }
  29. }
  30. }

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