I am using tensorflow 2.0.0-beta1 and python 3.7
First consider the following piece of code where tensor.numpy() works correctly:
import tensorflow as tf
import numpy as np
np.save('data.npy',np.ones(1024))
def func(mystr):
return np.load(mystr.numpy())
mystring = tf.constant('data.npy')
print(func(mystring))
The above code works correctly and outputs [1. 1. 1. ... 1. 1. 1.].
Now consider the following code in which tensor.numpy() doesn't work.
import tensorflow as tf
import numpy as np
np.save('data.npy',np.ones(1024))
def func(mystr):
return np.load(mystr.numpy())
mystring = tf.constant('data.npy')
data = tf.data.Dataset.from_tensor_slices([mystring])
data.map(func,1)
The above code gives the following error AttributeError: 'Tensor' object has no attribute 'numpy'
I am unable to figure out why tensor.numpy() doesn't work in the case of tf.data.Dataset.map()
EDIT
The following paragraph clarifies my purpose:
I have a dataset folder which contains millions of data pair (image,time-series). The entire dataset wont fit into memory, so I am using the tf.data.Dataset.map(func). Inside the func() function I want to load a numpy file which contains the time series as well as load the image. For loading the image there are inbuilt functions in tensorflow like tf.io.read_file and tf.image.decode_jpeg that accept string tensor. But np.load() does not accept string tensor. Thats why I want to convert the string tensor into a standard python string.