I have been attempting to use tfio.IODataset.from_parquet to train a model large parquet files. Below is a minimal example of the parquet loading procedure I am using:
pd.DataFrame({'a':[.1,.2], 'b':[.01,.02]}).to_parquet('file.parquet')
ds = tfio.IODataset.from_parquet('file.parquet', columns = ['a','b'])
for batch in ds.batch(5):
print(batch)
OrderedDict([('a', <tf.Tensor: shape=(2,), dtype=float64, numpy=array([0.1, 0.2])>), ('b', <tf.Tensor: shape=(2,), dtype=float64, numpy=array([0.01, 0.02])>)])
The batched dataset is type OrderedDict with keys a and b. For training my model I would like something more akin to a "dense" feature vector, instead of two separate keys in an ordereddict. How can I convert the OrderedDict to a dense tuple?
Try 1
As per this example, I tried the following to transform the dataset into "dense" features:
def make_dense(features):
features = tf.stack(list(features), axis=1)
return features
ds = ds.map(make_dense)
Unfortunately, that throws errors. I have tried several variations to this theme, including
- changing
axis=1toaxis=0 - using
ds = ds.map(lambda *items: tf.stack(items))instead of mymake_densefunction.
I imagine this is a very basic operation for IODataset; I just do not know how to accomplish it.