parameters: (volpath,
              segpath,
              batch_size=1,
              verbose=False,
              nb_restart_cycle=None,
              name='img_seg', # name, optional
              ext='.png',
              vol_rand_seed=None,
              **kwargs)
docstring: generator for (image, segmentation)
docstring_summary: generator for (image, segmentation)
docstring_tokens: generator for ( image segmentation )
function: def img_seg(volpath,
              segpath,
              batch_size=1,
              verbose=False,
              nb_restart_cycle=None,
              name='img_seg', # name, optional
              ext='.png',
              vol_rand_seed=None,
              **kwargs):
      """
      generator for (image, segmentation)
      """
  
      def imggen(path, ext, nb_restart_cycle=None):
          """
          TODO: should really use the volume generators for this
          """
          files = _get_file_list(path, ext, vol_rand_seed)
          if nb_restart_cycle is None:
              nb_restart_cycle = len(files)
  
          idx = -1
          while 1:
              idx = np.mod(idx+1, nb_restart_cycle)
              im = scipy.misc.imread(os.path.join(path, files[idx]))[:, :, 0]
              yield im.reshape((1,) + im.shape)
  
      img_gen = imggen(volpath, ext, nb_restart_cycle)
      seg_gen = imggen(segpath, ext)
  
      # on next (while):
      while 1:
          input_vol = np.vstack([next(img_gen).astype('float16')/255 for i in range(batch_size)])
          input_vol = np.expand_dims(input_vol, axis=-1)
  
          output_vols = [np_utils.to_categorical(next(seg_gen).astype('int8'), num_classes=2) for i in range(batch_size)]
          output_vol = np.vstack([np.expand_dims(f, axis=0) for f in output_vols])
  
          # output input and output
          yield (input_vol, output_vol)
function_tokens: def img_seg ( volpath , segpath , batch_size = 1 , verbose = False , nb_restart_cycle = None , name = 'img_seg' , # name, optional ext = '.png' , vol_rand_seed = None , * * kwargs ) : def imggen ( path , ext , nb_restart_cycle = None ) : """
          TODO: should really use the volume generators for this
          """ files = _get_file_list ( path , ext , vol_rand_seed ) if nb_restart_cycle is None : nb_restart_cycle = len ( files ) idx = - 1 while 1 : idx = np . mod ( idx + 1 , nb_restart_cycle ) im = scipy . misc . imread ( os . path . join ( path , files [ idx ] ) ) [ : , : , 0 ] yield im . reshape ( ( 1 , ) + im . shape ) img_gen = imggen ( volpath , ext , nb_restart_cycle ) seg_gen = imggen ( segpath , ext ) # on next (while): while 1 : input_vol = np . vstack ( [ next ( img_gen ) . astype ( 'float16' ) / 255 for i in range ( batch_size ) ] ) input_vol = np . expand_dims ( input_vol , axis = - 1 ) output_vols = [ np_utils . to_categorical ( next ( seg_gen ) . astype ( 'int8' ) , num_classes = 2 ) for i in range ( batch_size ) ] output_vol = np . vstack ( [ np . expand_dims ( f , axis = 0 ) for f in output_vols ] ) # output input and output yield ( input_vol , output_vol )