如何在TensorFlow Java中创建TensorList作为操作数的输入?

时间:2019-07-20 11:24:11

标签: java tensorflow

我有一个用例,我想使用TensorFlow Java API连接两个Tensor。

在TensorFlow Python API中进行串联的代码为:

t1 = [[1, 2, 3], [4, 5, 6]]
t2 = [[7, 8, 9], [10, 11, 12]]
tf.concat(0, [t1, t2])

虽然我尝试在TensorFlow Java API中进行操作,但是我发现需要将列表作为输入传递给Concat Op,但是我不知道如何创建操作数作为两个Tensors的列表,但是很遗憾,我找不到有关它的文档。我在Java中尝试过的代码是

try (Graph g = new Graph()) {

     Scope scope = new Scope(g);

     Constant t1 = Constant.create(scope, new float[][]{
          new float[]{1, 2, 3},
          new float[]{4, 5, 6}
     });
     Constant t2 = Constant.create(scope, new float[][]{
          new float[]{7, 8, 9},
          new float[]{10, 11, 12}
     });
     Concat concat = Concat.create(
          scope,
          ?,  // how to create a values list as input from t1 and t2?
          Constant.create(scope, 0)
     );

}

这是我使用的TensorFlow Java版本:

<dependency>
     <groupId>org.tensorflow</groupId>
     <artifactId>tensorflow</artifactId>
     <version>1.13.1</version>
</dependency>

您能给我一些有关如何在TensorFlow Java API中创建列表作为Concat op输入的建议吗?

谢谢!

0 个答案:

没有答案