def image_preloader(target_path, image_shape, mode='file', normalize=True, grayscale=False, categorical_labels=True, files_extension=None, filter_channel=False):
 assert (mode in ['folder', 'file'])
 if (mode == 'folder'):
  (images, labels) = directory_to_samples(target_path, flags=files_extension, filter_channel=filter_channel)
 else:
  with open(target_path, 'r') as f:
   (images, labels) = ([], [])
   for l in f.readlines():
    l = l.strip('\n').split()
    if ((not files_extension) or any(((flag in l[0]) for flag in files_extension))):
     if filter_channel:
      if (get_img_channel(l[0]) != 3):
       continue
     images.append(l[0])
     labels.append(int(l[1]))
 n_classes = (np.max(labels) + 1)
 X = ImagePreloader(images, image_shape, normalize, grayscale)
 Y = LabelPreloader(labels, n_classes, categorical_labels)
 return (X, Y)

def image_preloader ( target_path , image_shape , mode = 'file' , normalize = True , grayscale = False , categorical_labels = True , files_extension = None , filter_channel = False ) : assert ( mode in [ 'folder' , 'file' ] ) if ( mode == 'folder' ) : ( images , labels ) = directory_to_samples ( target_path , flags = files_extension , filter_channel = filter_channel ) else : with open ( target_path , 'r' ) as f : ( images , labels ) = ( [ ] , [ ] ) for l in f . readlines ( ) : l = l . strip ( '\n' ) . split ( ) if ( ( not files_extension ) or any ( ( ( flag in l [ 0 ] ) for flag in files_extension ) ) ) : if filter_channel : if ( get_img_channel ( l [ 0 ] ) != 3 ) : continue images . append ( l [ 0 ] ) labels . append ( int ( l [ 1 ] ) ) n_classes = ( np . max ( labels ) + 1 ) X = ImagePreloader ( images , image_shape , normalize , grayscale ) Y = LabelPreloader ( labels , n_classes , categorical_labels ) return ( X , Y )
image preloader .