public async Task TestResnetBatch() { using (Tensor imageTensor = ImageIO.ReadTensorFromImageFiles <float>( new string[] { "surfers.jpg", "surfers.jpg" }, 224, 224, 0, 1.0f / 255.0f)) using (Resnet resnet = new Resnet()) { await resnet.Init(); Resnet.RecognitionResult[][] results = resnet.Recognize(imageTensor); } }
public async Task TestResnet() { using (Tensor imageTensor = ImageIO.ReadTensorFromImageFile <float>("surfers.jpg", 224, 224, 0, 1.0f / 255.0f)) using (Resnet resnet = new Resnet()) { await resnet.Init(); MetaGraphDef metaGraphDef = MetaGraphDef.Parser.ParseFrom(resnet.MetaGraphDefBuffer.Data); var signatureDef = metaGraphDef.SignatureDef["serving_default"]; var inputNode = signatureDef.Inputs; var outputNode = signatureDef.Outputs; HashSet <string> opNames = new HashSet <string>(); HashSet <string> couldBeInputs = new HashSet <string>(); HashSet <string> couldBeOutputs = new HashSet <string>(); foreach (Operation op in resnet.Graph) { String name = op.Name; opNames.Add(name); if (op.NumInputs == 0 && op.OpType.Equals("Placeholder")) { couldBeInputs.Add(op.Name); AttrMetadata dtypeMeta = op.GetAttrMetadata("dtype"); AttrMetadata shapeMeta = op.GetAttrMetadata("shape"); DataType type = op.GetAttrType("dtype"); Int64[] shape = op.GetAttrShape("shape"); Buffer valueBuffer = op.GetAttrValueProto("shape"); Buffer shapeBuffer = op.GetAttrTensorShapeProto("shape"); Tensorflow.TensorShapeProto shapeProto = Tensorflow.TensorShapeProto.Parser.ParseFrom(shapeBuffer.Data); } if (op.OpType.Equals("Const")) { AttrMetadata dtypeMeta = op.GetAttrMetadata("dtype"); AttrMetadata valueMeta = op.GetAttrMetadata("value"); using (Tensor valueTensor = op.GetAttrTensor("value")) { var dim = valueTensor.Dim; } } if (op.OpType.Equals("Conv2D")) { AttrMetadata stridesMeta = op.GetAttrMetadata("strides"); AttrMetadata paddingMeta = op.GetAttrMetadata("padding"); AttrMetadata boolMeta = op.GetAttrMetadata("use_cudnn_on_gpu"); Int64[] strides = op.GetAttrIntList("strides"); bool useCudnn = op.GetAttrBool("use_cudnn_on_gpu"); String padding = op.GetAttrString("padding"); } foreach (Output output in op.Outputs) { int[] shape = resnet.Graph.GetTensorShape(output); if (output.NumConsumers == 0) { couldBeOutputs.Add(name); } } Buffer buffer = resnet.Graph.GetOpDef(op.OpType); Tensorflow.OpDef opDef = Tensorflow.OpDef.Parser.ParseFrom(buffer.Data); } using (Buffer versionDef = resnet.Graph.Versions()) { int l = versionDef.Length; } Resnet.RecognitionResult[][] results = resnet.Recognize(imageTensor); } }