Git Product home page Git Product logo

customvision-tensorflow-csharp's Introduction

C#调用PB模型

Fork from https://github.com/daltskin/CustomVision-TensorFlow-CSharp

说明:pb模型是什么以及为什么要使用pb模型,请参考这里,我们不做过多的说明。这里我们只分享如何使用CustomVision-TensorFlow-CSharp调用我们自己的pb模型。

我们的应用场景:

单个宫颈细胞图像分类,是一个三分类任务,三个类别分别是:垃圾细胞(Junk)、正常细胞(Negative)、异常细胞(Positive)三个类别的示例图片分别如下图所示:

junkmneg

首先,使用大量带标签的数据集训练出分类器,并将模型保存为pb格式。请参考这里

针对我们自身的网络结构对CustomVision-TensorFlow-CSharp进行修改:

替换文件:将CustomVision-TensorFlow-CSharp中的model.pb、test.jpg、labels.txt替换为自己相应的文件,如下图所示:

1552999259937

修改代码:项目的目录结构如下图所示,其中被红色方框框住的两个文件是需要修改的文件:

1552998851896

CustomVision.cs修改如下图所示:

为网络模型的placeholder赋值:

1552998923468

上图中的Placeholder以及Placeholder_2实际为网络结构中定义的placeholder的名字,在定义网络结构时可以通过如下方式指定placeholder的名字:

inputs = tf.placeholder(tf.float32, [None, 224, 224, 3],name="inputs")  
labels = tf.placeholder(tf.float32, [None, self.class_num],name="labels")
is_training = tf.placeholder(tf.bool,name="is_training")

假如没有特别为placeholder指定名字,tensorflow也会为placeholder指定默认的名字,可以直接将placeholder tensor打印出来如下所示:

print inputs
print labels
print is_training

# 打印结果
Tensor("Placeholder:0", shape=(?, 128, 128, 3), dtype=float32)
Tensor("Placeholder_1:0", shape=(?, 3), dtype=float32)
Tensor("Placeholder_2:0", dtype=bool)

假如已经生成好了pb模型,但是确实不知道placeholder的name,可以通过这里查看pb模型各网络层的name。

ImageUtil.cs修改如下图所示:

根据模型输入图片的长宽修改如下W、H变量,同时该函数还提供对输入图片去均值化最大值归一化等操作。

1552998966037

运行结果如下所示:

1552999124723

customvision-tensorflow-csharp's People

Contributors

daltskin avatar jiashengliu111 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.