I’m trying to fine-tune VGG16 pre-trained model for multi-class object detection.
I’m storing the annotation bounding boxes and class labels as list of tuples and converting them to ragged tensor due to non-uniformity (different number of objects in different images). Then creating a list of both to create a dataset using tf.data.Dataset.from_tensor_slices().
for example:
1. train_labels = [(class1), (class1, class2), (class 2), ...] #has number of tuples equal to number of images
2. train_bboxes = [(xmin, ymin, xmax, ymax), ((xmin, ymin, xmax, ymax), (xmin, ymin, xmax, ymax)), (xmin, ymin, xmax, ymax), ...] #this too has same number of tuples as no. of images
4.
5. train_labels = tf.ragged.constant(train_labels)
6. train_bboxes = tf.ragged.constant(train_bboxes)
7.
8. train_targets = [train_labels, train_bboxes]
9.
10. train_dataset = tf.data.Dataset((train_images, train_targets))
I’m getting the error “ValueError: TypeError: object of type ‘RaggedTensor’ has no len()” in line 10.
So, if a dataset cannot be created using ragged tensors, no one should be able to train a multi-class object detection model. But, that’s certainly not the case.
Also, no dataset will have images with same number of objects or objects belonging to the same class.
What am I missing here?
python version = 3.10.11, tensorflow = 2.16.1
Aryan Malewar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.