Obtaining a TensorArray

Trying to look at the value of a tensor, I hit an internal error. Here is a reprex:

model <- keras_model_sequential() %>% layer_lstm(units=2, input_shape=c(10,2));
# this tensor exists, but cannot be retrieved:
#> Tensor("lstm_1/TensorArray:0", shape=(2,), dtype=resource)
X <- array(0, c(5,10,2))
k_get_session()$run("lstm_1/TensorArray:0", feed_dict=list("lstm_1_input:0"=X))
#> Error in py_call_impl(callable, dots$args, dots$keywords): InternalError: ndarray was 1 bytes but TF_Tensor was 127 bytes
#> Detailed traceback: 
#>   File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 905, in run
#>     run_metadata_ptr)
#>   File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1140, in _run
#>     feed_dict_tensor, options, run_metadata)
#>   File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1321, in _do_run
#>     run_metadata)
#>   File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/client/session.py", line 1340, in _do_call
#>     raise type(e)(node_def, op, message)

Created on 2019-05-29 by the reprex package (v0.3.0)

The issue seems specific to this type of tensor, dtype=resource. I can compute other tensors with dtype float32 or int32 successfully. Jacob Buckman's article recommends tf.Print; I assume this corresponds to k_print_tensor, but that hits exactly the same internal error. The error is raised in function TF_Tensor_to_PyObject() in tf_session_helper.cc; in commit 94d27b6 it's line 365. The above happens with keras 2.2.0, reticulate 1.10, python 2.7.12 and numpy 1.14.2.

On another computer, with keras 2.2.4, reticulate 1.10, python 2.7.6 and numpy 1.16.1, I get a different error:

#> Error in py_ref_to_r(x): Conversion from numpy array type 20 is not supported

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.