简体   繁体   English

Java中的Tensorflow:inferenceInterface.fetch转换为多维数组

[英]Tensorflow in Java: inferenceInterface.fetch convert to multi-dimension array

I am using a trained Tensorflow model in Java on Android. 我在Android上的Java中使用训练有素的Tensorflow模型。 I am trying to extract the output of an intermediary op. 我正在尝试提取中间操作的输出。

The Tensor I am extracting has shape (150, 150, 256). 我提取的张量具有形状(150、150、256)。

I have declared the output target to be 我已经声明输出目标为

private float[] hybridValues;
hybridValues = new float[150 * 150 * 256];

I am then getting the output using. 然后,我得到使用的输出。

inferenceInterface.fetch(OUTPUT_NODE, hybridValues);

The values are fine but they are stored as a 1D array. 这些值很好,但是它们存储为一维数组。 Is there a way to get inferenceinterface.fetch to return a multi-dimentional array? 有没有办法让inferenceinterface.fetch返回多维数组?

I tried declaring hybridValue to be a three dimensional float array but that doesn't work as the fetch method expects a 1D array. 我尝试将hybridValue声明为三维浮点数组,但由于fetch方法期望使用1D数组,因此该方法不起作用。

The end goal is to pass my output to a Python program that will feed the values to a Tensor of the same shape (150, 150, 256). 最终目标是将我的输出传递给Python程序,该程序会将值馈入相同形状(150、150、256)的Tensor。

For comparison the Python a_output = graph.get_tensor_by_name('a2b_generator/Conv_7/Relu:0') returns an ndarray with values in the same shape as the target tensor. 为了进行比较,Python a_output = graph.get_tensor_by_name('a2b_generator/Conv_7/Relu:0')返回一个ndarray,其值与目标张量的形状相同。

我在桌面上使用tensorflow和java(可能有所不同),我要做的就是创建一个具有正确大小的多维数组,然后将值复制到上面,例如Tensor.copyTo(Object dst)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM