Iterating over a Dataset TF 2.0 with for loop

后端 未结 1 1024
太阳男子
太阳男子 2021-01-15 02:52

This problem is about how to iterate over a TF Dataset given that make_initializable_iterator() is deprecated.

I read a data set with the function below

相关标签:
1条回答
  • 2021-01-15 03:27

    It is not very clear what you want to get at your output. If you want to get the values of the dataset output you should execute eagerly. Example:

    tf.compat.v1.enable_eager_execution()
    
    def read_dataset_new(filename, target='delay'):
        ds = tf.data.TFRecordDataset(filename)
        ds = ds.map(lambda buf: parse(buf, target=target))
        ds = ds.batch(1)
        return ds
    # This should return your key values for each example.
    for features, labels in read_dataset_new(self.tf_rcrds_fl_nm):
        features_keys = features.keys()
    # This should return your tensor values if they supposed to be numeric.
    for features, labels in read_dataset_new(self.tf_rcrds_fl_nm):
        features_array = numpy.array(features)
    
    0 讨论(0)
提交回复
热议问题