When I try to train the U-net model with a custom data generator function I get an error from tensorflow. I tried changing the shapes etc and troubleshooted a lot.There is some logical error i guess, please help solving this issue
Data Generator Function
def dataGeneratorCoco(images, classes, coco, folder,
input_image_size=(224,224), batch_size=4, mode='train', mask_type='binary'):
img_folder = '{}/{}-data/images'.format(folder,mode)
dataset_size = len(images)
catIds = coco.getCatIds(catNms=classes)
c = 0
while(True):
img = np.zeros((batch_size, input_image_size[0], input_image_size[1], 3)).astype('float')
mask = np.zeros((batch_size, input_image_size[0], input_image_size[1], 1)).astype('float')
for i in range(c, c+batch_size): #initially from 0 to batch_size, when c = 0
imageObj = images[i]
### Retrieve Image ###
train_img = getImage(imageObj, img_folder, input_image_size)
### Create Mask ###
if mask_type=="binary":
train_mask = getBinaryMask(imageObj, coco, catIds, input_image_size)
elif mask_type=="normal":
train_mask = getNormalMask(imageObj, classes, coco, catIds, input_image_size)
# Add to respective batch sized arrays
# print(img.shape,train_img.shape)
img[i-c] = train_img
mask[i-c] = train_mask
c+=batch_size
if(c + batch_size >= dataset_size):
c=0
random.shuffle(images)
yield img, mask
Data Augmentation Generator
def augmentationsGenerator(gen, augGeneratorArgs, seed=None):
# Initialize the image data generator with args provided
image_gen = ImageDataGenerator(**augGeneratorArgs)
# Remove the brightness argument for the mask. Spatial arguments similar to image.
augGeneratorArgs_mask = augGeneratorArgs.copy()
_ = augGeneratorArgs_mask.pop('brightness_range', None)
# Initialize the mask data generator with modified args
mask_gen = ImageDataGenerator(**augGeneratorArgs_mask)
np.random.seed(seed if seed is not None else np.random.choice(range(9999)))
while(True):
for img, mask in gen:
seed = np.random.choice(range(9999))
# keep the seeds syncronized otherwise the augmentation of the images
# will end up different from the augmentation of the masks
g_x = image_gen.flow(255*img,
batch_size = img.shape[0],
seed = seed,
shuffle=True)
g_y = mask_gen.flow(mask,
batch_size = mask.shape[0],
seed = seed,
shuffle=True)
img_aug = next(g_x)/255.0
mask_aug = next(g_y)
yield img_aug, mask_aug
But when I try training the model i get the corresponding error
UnknownError: Graph execution error:
2 root error(s) found.
(0) UNKNOWN: Exception: input type is not supported.
Traceback (most recent call last):
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 270, in __call__
ret = func(*args)
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 642, in wrapper
return func(*args, **kwargs)
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1030, in generator_py_func
values = next(generator_state.get_iterator(iterator_id))
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/keras/engine/data_adapter.py", line 831, in wrapped_generator
for data in generator_fn():
File "/tmp/ipykernel_284939/3839959985.py", line 15, in augmentationsGenerator
for img, mask in gen:
File "/tmp/ipykernel_284939/728327123.py", line 25, in dataGeneratorCoco
train_mask = getNormalMask(imageObj, classes, coco, catIds, input_image_size)
File "/tmp/ipykernel_284939/2567587607.py", line 29, in getNormalMask
new_mask = cv2.resize(coco.annToMask(anns[a])*pixel_value, input_image_size)
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/pycocotools/coco.py", line 442, in annToMask
rle = self.annToRLE(ann)
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/pycocotools/coco.py", line 427, in annToRLE
rles = maskUtils.frPyObjects(segm, h, w)
File "pycocotools/_mask.pyx", line 308, in pycocotools._mask.frPyObjects
Exception: input type is not supported.
[[{{node PyFunc}}]]
[[IteratorGetNext]]
[[Shape/_10]]
(1) UNKNOWN: Exception: input type is not supported.
Traceback (most recent call last):
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/tensorflow/python/ops/script_ops.py", line 270, in __call__
ret = func(*args)
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/tensorflow/python/autograph/impl/api.py", line 642, in wrapper
return func(*args, **kwargs)
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/tensorflow/python/data/ops/dataset_ops.py", line 1030, in generator_py_func
values = next(generator_state.get_iterator(iterator_id))
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/keras/engine/data_adapter.py", line 831, in wrapped_generator
for data in generator_fn():
File "/tmp/ipykernel_284939/3839959985.py", line 15, in augmentationsGenerator
for img, mask in gen:
File "/tmp/ipykernel_284939/728327123.py", line 25, in dataGeneratorCoco
train_mask = getNormalMask(imageObj, classes, coco, catIds, input_image_size)
File "/tmp/ipykernel_284939/2567587607.py", line 29, in getNormalMask
new_mask = cv2.resize(coco.annToMask(anns[a])*pixel_value, input_image_size)
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/pycocotools/coco.py", line 442, in annToMask
rle = self.annToRLE(ann)
File "/home/navneeth/anaconda3/lib/python3.9/site-packages/pycocotools/coco.py", line 427, in annToRLE
rles = maskUtils.frPyObjects(segm, h, w)
File "pycocotools/_mask.pyx", line 308, in pycocotools._mask.frPyObjects
Exception: input type is not supported.
[[{{node PyFunc}}]]
[[IteratorGetNext]]
0 successful operations.
0 derived errors ignored. [Op:__inference_train_function_3047]
Please Help Me
I tried multiple ways for solving could not get through please help me in getting this done.