Skip to content

Instantly share code, notes, and snippets.

@Tusharsharma118
Created October 14, 2019 10:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Tusharsharma118/658d12cc22a93fe13bfd389e89f481c3 to your computer and use it in GitHub Desktop.
Save Tusharsharma118/658d12cc22a93fe13bfd389e89f481c3 to your computer and use it in GitHub Desktop.
method for loading traffic sign images into memory
def load_images(data_directory):
# lists to store Images and labels
images = []
labels = []
log_index = 0
# get list of all directories present in the data_directory path
directories = [dir for dir in os.listdir(data_directory)
if os.path.isdir(os.path.join(data_directory,dir))] # to make sure that we include only directories and not any files present in the folder
print(len(directories))
for dir in directories:
current_directory = os.path.join(data_directory,dir)
# Gather all fileNames in the given directory to load images into images array using sklearn
file_names = [os.path.join(current_directory,file)
for file in os.listdir(current_directory)
if file.endswith('.ppm')
]
# Load all given Images into the Images array
for file in file_names:
images.append(skimage.data.imread(file))
labels.append(int(dir))
log_index+=1
# print('Loading File: {0}'.format(log_index))
print('Successfully Loadded {0} images!'.format(len(images)))
return np.array(images),np.array(labels)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment