[英]Import .pb file using EmguCV C#
我想使用EmguCV
在 C# 中导入.pb文件。 我在 Python 中使用Keras in Python
。 我冻结了我的 model 总结如下:
层(类型)Output 形状参数 #
input_1 (InputLayer) (无, 120, 50, 1) 0
conv2d_1 (Conv2D) (无, 120, 50, 64) 640
conv2d_2 (Conv2D) (无, 120, 50, 64) 36928
batch_normalization_1 (批次 (无, 120, 50, 64) 256
max_pooling2d_1 (MaxPooling2 (无, 60, 25, 64) 0
conv2d_3 (Conv2D) (无, 60, 25, 64) 36928
conv2d_4 (Conv2D) (无, 60, 25, 128) 73856
batch_normalization_2 (批次 (无, 60, 25, 128) 512
max_pooling2d_2 (MaxPooling2 (无, 30, 12, 128) 0
conv2d_5 (Conv2D) (无, 30, 12, 128) 147584
conv2d_6 (Conv2D) (无, 30, 12, 128) 147584
batch_normalization_3 (批次 (无, 30, 12, 128) 512
reshape_1 (重塑) (无, 30, 1536) 0
dropout_1(辍学)(无,30,1536)0
dense_1(密集)(无、30、256)393472
bidirectional_1(双向(无、30、256)1050624
bidirectional_2(双向(无、30、256)394240
dropout_2(辍学)(无、30、256)0
dense_2(密集)(无、30、43)11051
我使用如下所示的 C# class 来导入.pb文件并在其中使用UMat
图像:
public class ClassifierDnn
{
private readonly Emgu.CV.Dnn.Net _net;
private readonly string _inputName;
private readonly string _outputName;
public ClassifierDnn(
string tensorflowModelFilePath,
string inputName,
string outputName)
{
var b = File.Exists(tensorflowModelFilePath);
_net = Emgu.CV.Dnn.DnnInvoke.ReadNetFromTensorflow(tensorflowModelFilePath);
_inputName = inputName;
_outputName = outputName;
}
public int Classify(UMat umat)
{
using (var mat = umat.GetMat(Emgu.CV.CvEnum.AccessType.Fast))
{
return Classify(mat);
}
}
}
我使用以下代码调用Classify
方法:
var dnn = new ClassifierDnn(
"crnn.pb",
"input_1",
"dense_2");
using (var u = new UMat(dlg.FileName, ImreadModes.Grayscale))
{
var m = dnn.Classify(u);
}
但我得到下面描述的这个错误:
问题是什么?
我没有给你完整的解决方案,但你可以查看 OpenCV 源代码来找到它。 As a start the error you got is found in getTensorContent
function in tf_graph_simplifier.cpp , you can track it back to tf_importer.cpp where it is found in 21 locations within populateNet
function, the main function for readNetFromTensorflow
, in this file, lines 705 to 2044.您可以跟踪其中的每一个,以找出与您的问题相关的一个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.