简体   繁体   中英

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

I am using a trained Tensorflow model in Java on Android. I am trying to extract the output of an intermediary op.

The Tensor I am extracting has shape (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?

I tried declaring hybridValue to be a three dimensional float array but that doesn't work as the fetch method expects a 1D array.

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).

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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