How to export a Tensorflow dataset to csv?

Viewed 877

Seeking advice how to create TF dataset mapping two lists and save the dataset to CSV file.

I've created two lists: Original: [b'File 1.JPG', b'File 2.JPG', b'File 3.JPG', b'File 4.JPG']

Duplicate: [b'Copy of File 1.JPG', b'Copy of File 2.JPG', b'Copy of File 3.JPG', b'Copy of File 4.JPG']

Need to map each original to relevant duplicate file and save them into a CSV file with the columns Original : Duplicate

I try to convert TF to pandas dataframe by running:

dataset = tf.data.Dataset.from_tensor_slices((original, dublicate))

def convert_to_dataframe(original, dublicate):
 print(pd.DataFrame.from_records(original))
 return original, dublicate

df = dataset.map( lambda original, dublicate: 
                 tf.py_function(convert_to_dataframe,
                 [original, dublicate], Tout =tf.string)

iterator = df.make_one_shot_iterator()
original, dublicate = iterator.get_next()

When I try to check whether df is pandas dataframe and save it to CSV file I receive the following error: AttributeError Traceback (most recent call last) in () ----> 1 iterator = df.make_one_shot_iterator() 2 original, dublicate = iterator.get_next()

AttributeError: 'MapDataset' object has no attribute 'make_one_shot_iterator'

Thanks in advance

1 Answers

I would recommend you to look at this question which is very similar to yours. After getting the weights of the nn you can use pandas to_csv() function to export the data.

Related