как правильно использовать карту и пакет в наборе данных тензорного потока? - PullRequest
0 голосов
/ 12 июля 2020
dataset = tf.data.Dataset.from_tensor_slices((images,new_boxes,labels))
run_train(dataset.map(resize_image_bbox2, num_parallel_calls=tf.data.experimental.AUTOTUNE).batch(batch_size).prefetch(tf.data.experimental.AUTOTUNE))

def resize_image_bbox2(image,boxes,labels):

    img = tf.io.read_file(image,"file_reader")
    img = tf.image.decode_jpeg(img, channels=3)
    img = tf.cast(img, tf.float32)
    newSize = (300, 300)
    new_img = tf.image.resize(img,newSize)
    return new_img,boxes,labels

щас делаю .map.batch (batch_size) но не уверен, что это правильный способ использования.

если мой пакет равен 3. тогда он сопоставляет 3 разных изображения и run_train? прямо сейчас он дает ошибку с

Traceback (most recent call last):
  File "/home/jake/Gits/ssd_tensorflow/train.py", line 64, in <module>
    main()
  File "/home/jake/Gits/ssd_tensorflow/train.py", line 62, in main
    train()
  File "/home/jake/Gits/ssd_tensorflow/train.py", line 49, in train
    run_train(dataset.map(resize_image_bbox2, num_parallel_calls=tf.data.experimental.AUTOTUNE).batch(batch_size).prefetch(tf.data.experimental.AUTOTUNE))
  File "/home/jake/Gits/ssd_tensorflow/train.py", line 26, in run_train
    for idx,(images,boxes,labels) in enumerate(dataset): # (batch_size (N), 300, 300, 3)
  File "/home/jake/venv/lib/python3.7/site-packages/tensorflow/python/data/ops/iterator_ops.py", line 631, in __next__
    return self.next()
  File "/home/jake/venv/lib/python3.7/site-packages/tensorflow/python/data/ops/iterator_ops.py", line 670, in next
    return self._next_internal()
  File "/home/jake/venv/lib/python3.7/site-packages/tensorflow/python/data/ops/iterator_ops.py", line 661, in _next_internal
    return structure.from_compatible_tensor_list(self._element_spec, ret)
  File "/usr/lib/python3.7/contextlib.py", line 130, in __exit__
    self.gen.throw(type, value, traceback)
  File "/home/jake/venv/lib/python3.7/site-packages/tensorflow/python/eager/context.py", line 1989, in execution_mode
    executor_new.wait()
  File "/home/jake/venv/lib/python3.7/site-packages/tensorflow/python/eager/executor.py", line 67, in wait
    pywrap_tfe.TFE_ExecutorWaitForAllPendingNodes(self._handle)
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot add tensor to the batch: number of elements does not match. Shapes are: [tensor]: [2], [batch]: [3]

Process finished with exit code 1
...