小编Rob*_*ank的帖子

如何将 Byte[](解码为 PNG 或 JPG)转换为 Tensorflows Tensor

我正在尝试在 Unity 的项目中使用 Tensorflowsharp。

我面临的问题是,对于转换,您通常使用第二个 Graph 将输入转换为张量。Android 不支持使用的函数 DecodeJpg 和 DecodePng 那么如何将该输入转换为张量?

private static void ConstructGraphToNormalizeImage(out TFGraph graph, out TFOutput input, out TFOutput output, TFDataType destinationDataType = TFDataType.Float)
{

    const int W = 224;
    const int H = 224;
    const float Mean = 117;
    const float Scale = 1;
    graph = new TFGraph();
    input = graph.Placeholder(TFDataType.String);
    output = graph.Cast(graph.Div(
        x: graph.Sub(
            x: graph.ResizeBilinear(
                images: graph.ExpandDims(
                    input: graph.Cast(
                        graph.DecodeJpeg(contents: input, channels: 3), DstT: TFDataType.Float),
                    dim: graph.Const(0, "make_batch")),
                size: graph.Const(new int[] { …
Run Code Online (Sandbox Code Playgroud)

c# android opencv tensorflow tensorflowsharp

3
推荐指数
1
解决办法
3608
查看次数

标签 统计

android ×1

c# ×1

opencv ×1

tensorflow ×1

tensorflowsharp ×1