4

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

Maksim
  • 41
  • 3
  • check this https://stackoverflow.com/questions/55510265/how-to-save-a-tensorflow-dataset-to-csv/73036596#73036596 – sakeesh Jul 19 '22 at 12:07

1 Answers1

0

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.

Ege
  • 515
  • 5
  • 14
  • Thank you @Ege. But I 'm not running nn. I'm just trying to map two lists into one dataset. As far as I'm aware a dataset could be saved to CSV by applying pandas dataframe. I tried to create tf.dataset (no error), then convert it to pandas dataframe. At this stage can't check the status. – Maksim Jul 30 '20 at 20:26