def directory_to_samples(directory, flags=None, filter_channel=False):
 samples = []
 targets = []
 label = 0
 try:
  classes = sorted(os.walk(directory).next()[1])
 except Exception:
  classes = sorted(os.walk(directory).__next__()[1])
 for c in classes:
  c_dir = os.path.join(directory, c)
  try:
   walk = os.walk(c_dir).next()
  except Exception:
   walk = os.walk(c_dir).__next__()
  for sample in walk[2]:
   if ((not flags) or any(((flag in sample) for flag in flags))):
    if filter_channel:
     if (get_img_channel(os.path.join(c_dir, sample)) != 3):
      continue
    samples.append(os.path.join(c_dir, sample))
    targets.append(label)
  label += 1
 return (samples, targets)

def directory_to_samples ( directory , flags = None , filter_channel = False ) : samples = [ ] targets = [ ] label = 0 try : classes = sorted ( os . walk ( directory ) . next ( ) [ 1 ] ) except Exception : classes = sorted ( os . walk ( directory ) . __next__ ( ) [ 1 ] ) for c in classes : c_dir = os . path . join ( directory , c ) try : walk = os . walk ( c_dir ) . next ( ) except Exception : walk = os . walk ( c_dir ) . __next__ ( ) for sample in walk [ 2 ] : if ( ( not flags ) or any ( ( ( flag in sample ) for flag in flags ) ) ) : if filter_channel : if ( get_img_channel ( os . path . join ( c_dir , sample ) ) != 3 ) : continue samples . append ( os . path . join ( c_dir , sample ) ) targets . append ( label ) label += 1 return ( samples , targets )
read a directory .