object_detector.DataLoader.from_pascal_voc returning empty data

Viewed 802

train_data = object_detector.DataLoader.from_pascal_voc( 'images_jpg_splitted/train/img', 'images_jpg_splitted/train/xml', ['bat'] )

val_data = object_detector.DataLoader.from_pascal_voc( 'images_jpg_splitted/test/img', 'images_jpg_splitted/test/xml', ['bat'] )

I am trying to detect bat from images. I have labeled the data using labelImg. While trying to load the data from tflite_model_maker, object_detector.DataLoader.from_pascal_voc returns empty data. I have tried not splitting the image and XML file and it still did not work.

3 Answers

The error was in the image file. The file supported was only jpeg but although the extension was a jpeg, it was not recognizing the images as jpeg maybe because it was a png file and the extension was renamed. So, I used PIL to convert them to jpeg.

import PIL.Image
import glob
import os

if not "converted" in os.listdir():
    os.mkdir("converted")

lst_imgs = [i for i in glob.glob("*.jpeg")]
print(lst_imgs)
for i in lst_imgs:
    img = PIL.Image.open(i)
    img = img.convert("RGB")
    img.save("converted\\"+i, "JPEG")


print("Done.")
os.startfile("converted")

I ran into this issue because I was specifying the path to my annotations using ~. Starting my path with /home/myuser fixed this for me.

could you please write the code in below style?

dataloader = object_detector.DataLoader.from_pascal_voc(image_dir, annotations_dir, label_map={1: "person", 2: "notperson"})

It may be a syntax issue.

Related