Issue
I have 1970 npy files in (vid_frames) directory each npy file contains 20 frame of MSVD dataset. I need to load all these npy at once to be as tensor dataset.
When I use np_read = np.load(all_npy_path)
, I get this error
TypeError: expected str, bytes or os.PathLike object, not Tensor
where all_npy_path contains all npy path as tensor:
all_npy_path =
['vid_frames/m1NR0uNNs5Y_104_110.avi.npy',
'vid_frames/9Q0JfdP36kI_23_28.avi.npy',
'vid_frames/WTf5EgVY5uU_18_23.avi.npy',
'vid_frames/WZTGqvbqOFE_28_34.avi.npy', ..... ]
Solution
The following code solved the problem:
def decode_and_resize(img_path):
tensor = tf.py_function(
func=lambda path: np.load(path.numpy().decode("utf-8")),
inp=[img_path],
Tout=tf.float32
)
tensor.set_shape(IMAGE_SIZE_np)
return tensor
Answered By - adeljalalyousif
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.