È possibile Ritagliare, Ridimensionare le immagini per lotto ?
Sto usando Tensorflow set di dati API, come di seguito:
dataset = dataset.shuffle().repeat().batch(batch_size, drop_remainder=True)
Voglio, all'interno del batch tutte le immagini devono avere la stessa dimensione. Tuttavia in tutto il batch può avere diverse dimensioni.
Per esempio, 1 ° lotto dispone di tutte le immagini di forma (batch_size, 300, 300, 3). La prossima partita può avere immagini di forma (batch_size, 224, 224, 3). Un altro batch può avere immagini di forma (batch_size, 400, 400, 3).
Fondamentalmente voglio avere dymanically a forma di lotti, tuttavia, tutte le immagini in batch hanno statico forme.
Se facciamo come segue:
dataset = dataset.shuffle().repeat().batch(batch_size, drop_remainder=True).map(lambda x, y: map_fn(x, y))
Il sopra .mappa() vale per ogni partita separatamente o sull'intero set di dati ?
Se in precedenza .mappa() non si applicano separatamente per ciascun lotto, come possiamo fare questo ? Possiamo definire qualsiasi iteratore dopo il set di dati.batch(), applicare tf.immagine.crop_and_resize() su ogni immagine per lotto e dopo l'uso del set di dati.concatena() per combinare tutti trasformati lotti ?
Sto creando il set di dati come qui di seguito:
# Dataset creation (read image data from files of COCO dataset)
dataset = tf.data.Dataset.list_files(self._file_pattern, shuffle=False)
dataset = dataset.shard(dataset_num_shards, dataset_shard_index)
dataset = dataset.shuffle(tf.cast(256 / dataset_num_shards, tf.int64))
dataset = dataset.interleave(map_func=tf.data.TFRecordDataset(filename).prefetch(1), cycle_length=32, block_length=1, num_parallel_calls=tf.data.experimental.AUTOTUNE)
dataset = dataset.map(tf_example_decoder.TfExampleDecoder().decode, num_parallel_calls=64)
dataset = dataset.shuffle(64).repeat()
# Parse each image for preprocessing
dataset = dataset.map(lambda data, _: _parse_example(data), num_parallel_calls=64)
dataset = dataset.batch(batch_size=batch_size, drop_remainder=True)
# Below code suggested by you to resize images to fixed shape in each batch
def resize_data(images, labels):
tf.print('Original shape -->', tf.shape(images))
SIZE = (300, 300)
return tf.image.resize(images, SIZE), labels
dataset = dataset.map(resize_data)
dataset = dataset.prefetch(tf.data.experimental.AUTOTUNE)
tf.estimator.Estimator(...).train(
input_fn=dataset,
steps=steps,
hooks=train_hooks)
INVALID_ARGUMENT: Cannot add tensor to the batch: number of elements does not match. Shapes are: [tensor]: [640,426,3], [batch]: [480,640,3]
Anche se ho dato la DIMENSIONE = (300, 300) in tf.immagine.ridimensionare(immagini, DIMENSIONI), batch SIZE = (480, 640). E come l'immagine successiva è diversa DIMENSIONE = (640, 426), non è riuscita ad aggiungere al lotto. Ciò significa che, in qualche modo, non è in grado di applicare .mappa() funzione di ogni singolo lotto. Qualsiasi aiuto/idea ?