My objective is to save tensorflow dataset objects to disk and then read them on a different machine.
Here's the source code to get dataset:
import tensorflow_datasets as tfds
datasets, info = tfds.load("imdb_reviews", as_supervised=True, with_info=True)
Now how do I save datasets
and info
to location such as './'? Also, this will be saved on Linux machine and read on Windows machine. So, I'd want the format to be platform independent.
I did try doing this myself using the link https://github.com/tensorflow/tensorflow/issues/38483:
def save(dataset, location='data/tf-records/'):
dataset = dataset.map(tf.io.serialize_tensor)
writer = tf.data.experimental.TFRecordWriter(location)
writer.write(dataset)
return location
def load(tf_record='data/tf-records/'):
dataset = tf.data.TFRecordDataset(tf_record)
dataset = dataset.map(lambda x: tf.io.parse_tensor(x, tf.int64))
return dataset
However, when I run this code, I get the following error:
AttributeError: 'dict' object has no attribute 'map'
It has been a couple of days since I started working on tensorflow. So, I am not too sure how to fix these. I am a beginner.
Thanks for any help.
I have tensorflow 2.3 on Python 3.7.9