You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have already tried to answer the question on the known support pages but have not found a satisfying answer yet, so I will try it here.
I want to convert data augmentation with imgaug into Tensorflow. The current state is that I have a working form in python but due to the conversion of the bounding boxes the code does not seem to work. Is it possible to implement a data augmentation pipline in Tensorflow with tf.data.Dataset for object detection (with transformation of bounding boxes)?
With the function call 3 parameters are passed - a batch of images, a batch of several bounding boxes per image and the image size.
In the following you will find the code that is not yet working in Tensorflow 2 but in python.
Function call:
train_dataset=train_dataset.map(lambdax, y: (image_batch_augmentation(x, y, image_size)))
@tf.functiondeftf_image_batch_augmentation(batch_images, batch_bbox, image_shape):
defcreate_BoundingBox(bbox, w, h):
returnBoundingBox(bbox[0]*h, bbox[1]*w, bbox[2]*h, bbox[3]*w, tf.cast(bbox[4], tf.int32))
defdissolve_BoundingBox_to_array(bbox, image_size):
# returns a numpy array with normalized bounding box coordinatesreturnnp.asarray([bbox.x1, bbox.y1, bbox.x2, bbox.y2, bbox.label]).astype('float32') /image_sizedefadd_zerso_BoundingBox(batch):
returnnp.concatenate((batch, np.zeros(shape=((100-len(batch)),5), dtype='float32')))
w=image_shapeh=image_shape# Create BoundingBox-Object from imgaug frameworkbbox= [[create_BoundingBox(bbox, float(w), float(h)) forbboxinbatchifsum(bbox) !=0] forbatchinbatch_bbox]
# Proprocess BoundingBoxes for Batch Processingbbox= [BoundingBoxesOnImage(batch, shape=(int(w),int(h))) forbatchinbbox]
# Activate deterministic so that the image and the corresponding bounding boxes are transformed identicallyseq_det=seq.to_deterministic()
# Data augmentation stepimages_aug, bbsoi_aug=seq_det(images=batch_images.numpy(), bounding_boxes=bbox)
bbsoi_aug= [batch.remove_out_of_image().clip_out_of_image() forbatchinbbsoi_aug]
bbsoi=np.asarray([[dissolve_BoundingBox_to_array(box, w) forboxinbatch] forbatchinbbsoi_aug])
bbsoi= ([add_zerso_BoundingBox(batch) forbatchinbbsoi])
returnimages_aug, bbsoi
The text was updated successfully, but these errors were encountered:
I have already tried to answer the question on the known support pages but have not found a satisfying answer yet, so I will try it here.
I want to convert data augmentation with imgaug into Tensorflow. The current state is that I have a working form in python but due to the conversion of the bounding boxes the code does not seem to work. Is it possible to implement a data augmentation pipline in Tensorflow with tf.data.Dataset for object detection (with transformation of bounding boxes)?
With the function call 3 parameters are passed - a batch of images, a batch of several bounding boxes per image and the image size.
In the following you will find the code that is not yet working in Tensorflow 2 but in python.
Function call:
The text was updated successfully, but these errors were encountered: