I am reading a csv file into a pandas dataframe.
train_data = pd.read_csv('mnist_test.csv');
Sample data
label pixel1 pixel2 pixel3 ... pixel781 pixel782 pixel783 pixel784
0 6 149 149 150 ... 106 112 120 107
1 5 126 128 131 ... 184 184 182 180
2 10 85 88 92 ... 226 225 224 222
3 0 203 205 207 ... 230 240 253 255
4 3 188 191 193 ... 49 46 46 53
how can I convert this dataframe into a tensorflow dataset.
import tensorflow as tf
ds = tf.data.Dataset.from_tensor_slices(dict(train_data))
See tensorflow.org/tutorials/load_data/pandas_dataframe for details.
For the sake of completeness,
import tensorflow as tf
ds = tf.data.Dataset.from_tensor_slices(train_data.to_dict(orient="list"))
print(ds)
TensorSliceDataset element_spec={'label': TensorSpec(shape=(), dtype=tf.int32, name=None), ...}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With