目前,我正在尝试让Keras后端函数k_gather在R中工作,到目前为止还没有成功。我只能找到关于tensorflow gather函数的适当文档。如果我遵循这个文档,下面的代码段应该提取张量a的(1,1,1)-entry。
library(keras)
a = k_constant(c(1L, 2L,3L,4L), dtype = 'int32' , shape = c(1L, 1L, 4L ))
c = k_constant(c(1L, 0L,0L,0L), dtype = 'int32' , shape = c(1L, 1L, 4L ))
out = k_gather(a , indices = c )
sess$run(out)然而,它似乎不是这样工作的。当我运行它时,我得到了错误
Error in py_call_impl(callable, dots$args, dots$keywords) :
InvalidArgumentError: indices[0,0,0] = 1 is not in [0, 1)错误并不像out的形状那样让我感到惊讶
shape=(1, 1, 4, 1, 4)而不是仅仅
shape=(1, 1, 4)它怎麽工作。如何提取我可爱的张量a的第一个分量?
发布于 2018-05-24 05:18:15
我找到了解决这个k_gather问题的方法。现在,我使用以下过程将张量置换为
library(keras)
a = k_constant(c(1L, 2L,3L,4L), dtype = 'int32' , shape = c(1L, 1L, 4L ))
a_1 = a[,,1:2]
a_2 = a[,,3:4]
a_new = k_concatenate( list(a_2, a_1))
sess = k_get_session()
sess$run(a_new)它不能解决我与k_gather的问题,但它能做我想要的事情。
https://stackoverflow.com/questions/50473701
复制相似问题