Visual-Behavior / detr-tensorflow

Tensorflow implementation of DETR : Object Detection with Transformers
MIT License
169 stars 53 forks source link

Issue iterating over custom dataset in COCO format #23

Closed coleyjthomp closed 3 years ago

coleyjthomp commented 3 years ago

Hi,

First off, thanks for sharing this code--it is immensely useful and I appreciate it.

I'm working on using this to finetune a dataset, when I follow the instructions to load my own COCO format dataset as described in your tutorial on my personal machine using Tensorflow 2.3 built from source, Python 3.7 and have all the dependencies installed that you are required.

Here is the code (following the tutorial):

`class MyConfig(TrainingConfig): def init(self): super().init() self.data_dir = "path/to/this/dataset/zzz_Weld_COCO" self.data = DataConfig(data_dir=self.data_dir, img_dir='train_resize', ann_file="annotations\custom_train_0427_v2.json") self.batch_size = 1

config = MyConfig() iterator, class_names = load_coco_dataset(config, config.batch_size, augmentation=True)

from pycocotools.coco import COCO import tensorflow as tf import numpy as np import imageio from skimage.color import gray2rgb from random import sample, shuffle import os

from detr_tf.data import transformation from detr_tf.data import processing from detr_tf.data import coco as CoCo import matplotlib.pyplot as plt`

for images, target_bbox, target_class in iterator: print("image.shape", images.shape) print("target_bbox.shape", target_bbox.shape) print("target_class.shape", target_class.shape)`

Each time I go to iterate over the dataset as noted in the load dataset tutorial ( and noted above), I get the following error:

`InvalidArgumentError Traceback (most recent call last) D:\Python\envs\VS\lib\site-packages\tensorflow\python\eager\context.py in execution_mode(mode) 2101 ctx.executor = executor_new -> 2102 yield 2103 finally:

D:\Python\envs\VS\lib\site-packages\tensorflow\python\data\ops\iterator_ops.py in _next_internal(self) 757 output_types=self._flat_output_types, --> 758 output_shapes=self._flat_output_shapes) 759

D:\Python\envs\VS\lib\site-packages\tensorflow\python\ops\gen_dataset_ops.py in iterator_get_next(iterator, output_types, output_shapes, name) 2636 except _core._NotOkStatusException as e: -> 2637 _ops.raise_from_not_ok_status(e, name) 2638 except _core._FallbackException:

D:\Python\envs\VS\lib\site-packages\tensorflow\python\framework\ops.py in raise_from_not_ok_status(e, name) 6842 # pylint: disable=protected-access -> 6843 six.raise_from(core._status_to_exception(e.code, message), None) 6844 # pylint: enable=protected-access

D:\Python\envs\VS\lib\site-packages\six.py in raise_from(value, from_value)

InvalidArgumentError: 3-th value returned by pyfunc_0 is int32, but expects int64 [[{{node PyFunc}}]] [Op:IteratorGetNext]

During handling of the above exception, another exception occurred:

InvalidArgumentError Traceback (most recent call last)

in ----> 1 for images, target_bbox, target_class in iterator: 2 print("image.shape", images.shape) 3 print("target_bbox.shape", target_bbox.shape) 4 print("target_class.shape", target_class.shape) D:\Python\envs\VS\lib\site-packages\tensorflow\python\data\ops\iterator_ops.py in __next__(self) 734 735 def __next__(self): # For Python 3 compatibility --> 736 return self.next() 737 738 def _next_internal(self): D:\Python\envs\VS\lib\site-packages\tensorflow\python\data\ops\iterator_ops.py in next(self) 770 def next(self): 771 try: --> 772 return self._next_internal() 773 except errors.OutOfRangeError: 774 raise StopIteration D:\Python\envs\VS\lib\site-packages\tensorflow\python\data\ops\iterator_ops.py in _next_internal(self) 762 return self._element_spec._from_compatible_tensor_list(ret) # pylint: disable=protected-access 763 except AttributeError: --> 764 return structure.from_compatible_tensor_list(self._element_spec, ret) 765 766 @property D:\Python\envs\VS\lib\contextlib.py in __exit__(self, type, value, traceback) 128 value = type() 129 try: --> 130 self.gen.throw(type, value, traceback) 131 except StopIteration as exc: 132 # Suppress StopIteration *unless* it's the same exception that D:\Python\envs\VS\lib\site-packages\tensorflow\python\eager\context.py in execution_mode(mode) 2103 finally: 2104 ctx.executor = executor_old -> 2105 executor_new.wait() 2106 2107 D:\Python\envs\VS\lib\site-packages\tensorflow\python\eager\executor.py in wait(self) 65 def wait(self): 66 """Waits for ops dispatched in this executor to finish.""" ---> 67 pywrap_tfe.TFE_ExecutorWaitForAllPendingNodes(self._handle) 68 69 def clear_error(self): InvalidArgumentError: 3-th value returned by pyfunc_0 is int32, but expects int64 [[{{node PyFunc}}]]` I'm sorry if this isn't descriptive enough--this is my first time ever posting an issue, so please let me know if there is anything I can do anything to be more helpful. EDIT: When working on Colab without using a GPU, this is not an issue, but when I switch to using a GPU, the same issue occurs in Colab.
thibo73800 commented 3 years ago

Hi,

Please, let me know if this quick fix solve your issue: https://github.com/Visual-Behavior/detr-tensorflow/commit/9a2e194e66d615cd4257f4f319ff5f5f1cbcadb5