Я пытался объединить два набора данных в tenorflow (я работаю с tf.data.Dataset
api).Ниже мой код:
with tf.name_scope('TFRecords_1'):
# Size of filenames_1 is 34
for file_name in filenames_1:
dataset_1 = tf.data.TFRecordDataset(file_name).map(_parse_function)
datasets_1_all.append(dataset_1)
dataset_1_all = tf.data.Dataset.zip(tuple(datasets_1_all))\
.shuffle(10000, seed=mseed)\
.batch(batch_size)
with tf.name_scope('TFRecords_2'):
# Size of filenames_2 is 14
for file_name in filenames_2:
dataset_2 = tf.data.TFRecordDataset(file_name).map(_parse_function)
datasets_2_all.append(dataset_2)
dataset_2_all = tf.data.Dataset.zip(tuple(datasets_2_iterators)).batch(batch_size)
with tf.name_scope('TFRecordsAll'):
dataset = dataset_1_all.concatenate(dataset_2_all)
iterator = dataset.make_initializable_iterator()
Я получил следующую ошибку:
File "C:\Users\iayou005\AppData\Local\Continuum\anaconda3\lib\site-packages\tensorflow\python\data\util\nest.py", line 188, in assert_same_structure
% (nest1, nest2))
ValueError: The two structures don't have the same number of elements. First structure: ((tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8)), second structure: ((tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8), (tf.string, tf.int64, tf.float32, tf.float32, tf.float32, tf.float32, tf.int64, tf.uint8)).
Я думал, что ответ должен быть вдохновлен https://www.tensorflow.org/api_docs/python/tf/data/TFRecordDataset#concatenate;где даже мысли a
и b
имеют разное количество элементов, но код должен работать.Пример этого можно увидеть здесь: Есть ли способ сложить два набора данных tenorflow? ;и даже если мы заменим 70
на 90
;пока код работает.Так почему же мой код не работает выше?
Примечание: после распечатки dataset_1_all
и dataset_2_all
;Я получил следующее:
<BatchDataset shapes: ((?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,)), types: (tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string)>
<BatchDataset shapes: ((?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,), (?,)), types: (tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string, tf.string)>
Поэтому теперь я понимаю, как разные формы, но как я могу решить эту проблему? Возможно, как я могу объединить набор данных 2?Такой метод, как: tf.data.Dataset.merge () ???
Любая помощь очень ценится !!