'faster r-cnn test all images in folder

I have trained my model using faster-rcnn on my computer. As you know , using object_detection_image.py script you can only test 1 image. But I want to test all images in my test folder. I have to write a code (using loops) which enables me to do that. Is there anyone can help me about this problem. Thanks in advance. Sincerely.



Solution 1:[1]

Hello, Here you can find a function that I implemented for testing Faster R-CNN on a set of images:

def get_folder_results(detector, image_dir, device):
       ' The detector represents your Faster R-CNN model,
         image_dir represents the folderpath containing the images,
         device : the device used to train (CPU, GPU ...) '
 for image in os.listdir(image_dir):
    image_path = os.path.join(image_dir, image)
    input_images = [T.ToTensor()(Image.open(image_path)).to(device)]
    prediction = detector(images)
    print(prediction)

    

After executing this function you will get a prediction per image where each prediction represents the coordinates of the bounding boxes and the corresponding class).

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Markh