0
votes

I made a code for shuffling the images with XML format. It looks so work very well but when I apply this shuffled images using my code to Faster R-CNN model.

Before randomly splitting the whole original dataset into train and test dataset using my code, an object detection model with the original dataset does work. However, after splitting it with my code, an object detection model does not work.

I think that I just moved and shuffled the images not touch any inside of XML format.

Please read my code and could you kindly give me answer?

import os
from glob import glob
import shutil
from sklearn.model_selection import train_test_split

# source path
source_dir = r"C:\dataset\original_data\"

# destination_path
train_dir = r"C:\dataset\original_data\train\"
test_dir = r"C:\dataset\original_data\test\"

os.makedirs(train_dir, exist_ok=True)
os.makedirs(test_dir, exist_ok=True)

# find image names
image_files = glob(source_dir + '*.jpg')

# remove file extension
image_path = []

for name in image_files:
    file_path = os.path.splitext(name)[0]
    file_name = file_path.split('/')[-1]
    image_path.append(file_name)


# Use scikit learn function for convenience
train_names, test_names = train_test_split(image_path, test_size=0.2)

def batch_move_files(file_list, source_path, destination_path):
    for file in file_list:
        file = os.path.basename(file)
        image = file + r'.jpg'
        xml = file + r'.xml'
        shutil.move(os.path.join(source_path, image), os.path.join(destination_path, image))
        shutil.move(os.path.join(source_path, xml),os.path.join(destination_path, xml))
    return

batch_move_files(train_names, source_dir, train_dir)
batch_move_files(test_names, source_dir, test_dir)
What do you mean by "shuffling the images with XML format"? "...it does not work." - How exactly does it not work?mzjn
Before randomly splitting the whole original dataset into train and test dataset using my code, an object detection model with the original dataset does work. However, after splitting it with my code, an object detection model does not work. Sorry for making to get confused.user12388610