Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Augmentor Error #23

Open
Yung-zi opened this issue Jun 17, 2022 · 3 comments
Open

Augmentor Error #23

Yung-zi opened this issue Jun 17, 2022 · 3 comments

Comments

@Yung-zi
Copy link

Yung-zi commented Jun 17, 2022

I tried to reproduce this code. However, an error occurred in "img_aug.py". The error is listed as follows.

raise IndexError("There are no images in the pipeline. "
IndexError: There are no images in the pipeline. Add a directory using add_directory(), pointing it to a directory containing images.

@JuChanSeo
Copy link

JuChanSeo commented Aug 23, 2022

I tried to reproduce this code. However, an error occurred in "img_aug.py". The error is listed as follows.

raise IndexError("There are no images in the pipeline. " IndexError: There are no images in the pipeline. Add a directory using add_directory(), pointing it to a directory containing images.

Hi, I had a similar problem and in my case, changing the path from relative path to absolute path when initializing "dataset_root_dir" solved this problem. Hope this helps!

@SinHanYang
Copy link

The above solution doesn't work for me.

@IkerSancho
Copy link

IkerSancho commented Dec 11, 2024

have fixed it like this:

import Augmentor
import os

def makedir(path):
    '''
    if path does not exist in the file system, create it
    '''
    if not os.path.exists(path):
        os.makedirs(path)
        os.chmod(path, 0o777)

datasets_root_dir = os.path.abspath('/home/capacity/ProtoPNet/datasets/cub200_cropped/')
dir = os.path.join(datasets_root_dir, 'train_cropped/')
target_dir = os.path.join(datasets_root_dir, 'train_cropped_augmented/')
makedir(target_dir)

folders = [os.path.join(dir, folder) for folder in next(os.walk(dir))[1]]
target_folders = [os.path.join(target_dir, folder) for folder in next(os.walk(dir))[1]]

#print("Folders to process:")
#for folder in folders:
#    images = os.listdir(folder)
#    print(f"Images found in {folder}: {len(images)}")
#print("\n")

#print("Target folders:")
#for folder in target_folders:
#    print(folder)
#print("\n")

for i in range(len(folders)):
    fd = folders[i]
    tfd = target_folders[i]
    makedir(tfd)

    '''
    img1 = os.listdir(fd)
    img2 = os.listdir(tfd)
    print(f"\nSource directory:{fd}\t n_images :: {len(img1)}")
    print(f"Destination directory:{tfd}\t n_images :: {len(img2)}\n")
    '''

    # Check if there are images in the folder
    images = os.listdir(fd)
    if len(images) == 0:
        print(f"No images found in folder: {fd}")
        continue

    print(f"Processing folder: {fd} with {len(images)} images")

    # Apply augmentation pipeline (rotation)
    try:
        p = Augmentor.Pipeline(source_directory=fd, output_directory=tfd)
        p.rotate(probability=1, max_left_rotation=15, max_right_rotation=15)
        p.flip_left_right(probability=0.5)
        for _ in range(10):  # Process 10 batches
            p.process()
        del p
    except Exception as e:
        print(f"Error processing rotation in folder {fd}: {e}")

    # Apply skew pipeline
    try:
        p = Augmentor.Pipeline(source_directory=fd, output_directory=tfd)
        p.skew(probability=1, magnitude=0.2)  # max 45 degrees
        p.flip_left_right(probability=0.5)
        for _ in range(10):  # Process 10 batches
            p.process()
        del p
    except Exception as e:
        print(f"Error processing skew in folder {fd}: {e}")

    # Apply shear pipeline
    try:
        p = Augmentor.Pipeline(source_directory=fd, output_directory=tfd)
        p.shear(probability=1, max_shear_left=10, max_shear_right=10)
        p.flip_left_right(probability=0.5)
        for _ in range(10):  # Process 10 batches
            p.process()
        del p
    except Exception as e:
        print(f"Error processing shear in folder {fd}: {e}")

    # Uncomment to process random distortion if needed
    #try:
    #    p = Augmentor.Pipeline(source_directory=fd, output_directory=tfd)
    #    p.random_distortion(probability=1.0, grid_width=10, grid_height=10, magnitude=5)
    #    p.flip_left_right(probability=0.5)
    #    for _ in range(10):
    #        p.process()
    #    del p
    #except Exception as e:
    #    print(f"Error processing random distortion in folder {fd}: {e}")   
    

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants