parameters: (df, resize_shape, n_classes=34, batch_size=1, horizontal_flip=True,
                           vertical_flip=False, brightness=0.1, rotation=5.0, zoom=0.1, training=True)
docstring: the default fusion training generator for mid fusion ICNet
  
      :param df: the dataframe. provided by the csv
      :param crop_shape: cropped size of the image.
      :param n_classes: number of classes to classify
      :param batch_size: the training batch size. usually default to 5
      :param horizontal_flip: boolean, apply hori flip to image during training.
      :param vertical_flip: boolean, apply vert flip to image during training
      :param brightness:
      :param rotation:
      :param zoom:
      :param training: boolean, if yes, apply augmentation
      :return:
docstring_summary: the default fusion training generator for mid fusion ICNet
docstring_tokens: the default fusion training generator for mid fusion ICNet
function: def fusion_generator(df, resize_shape, n_classes=34, batch_size=1, horizontal_flip=True,
                           vertical_flip=False, brightness=0.1, rotation=5.0, zoom=0.1, training=True):
  
      """
      the default fusion training generator for mid fusion ICNet
  
      :param df: the dataframe. provided by the csv
      :param crop_shape: cropped size of the image.
      :param n_classes: number of classes to classify
      :param batch_size: the training batch size. usually default to 5
      :param horizontal_flip: boolean, apply hori flip to image during training.
      :param vertical_flip: boolean, apply vert flip to image during training
      :param brightness:
      :param rotation:
      :param zoom:
      :param training: boolean, if yes, apply augmentation
      :return:
      """
  
      X_color = np.zeros((batch_size, resize_shape[1], resize_shape[0], 3), dtype='float32')
      X_depth = np.zeros((batch_size, resize_shape[1], resize_shape[0], 3), dtype='float32')
  
      Y1 = np.zeros((batch_size, resize_shape[1] // 4, resize_shape[0] // 4, n_classes), dtype='float32')
      Y2 = np.zeros((batch_size, resize_shape[1] // 8, resize_shape[0] // 8, n_classes), dtype='float32')
      Y3 = np.zeros((batch_size, resize_shape[1] // 16, resize_shape[0] // 16, n_classes), dtype='float32')
  
      while 1:
          j = 0
  
          for index in np.random.permutation(len(df)):
  
              image, image_depth, label = _load_rgb_depth_image_label(df[index])
  
              image = cv2.resize(image, resize_shape)
              image_depth = cv2.resize(image_depth, resize_shape)
              label = cv2.resize(label, resize_shape)
  
              # Do augmentation (only if training)
              if training:
                  if horizontal_flip and random.randint(0, 1):
                      image = cv2.flip(image, 1)
                      label = cv2.flip(label, 1)
                  if vertical_flip and random.randint(0, 1):
                      image = cv2.flip(image, 0)
                      label = cv2.flip(label, 0)
                  if brightness and random.randint(0, 1):
                      factor = 1.0 + abs(random.gauss(mu=0.0, sigma=brightness))
                      if random.randint(0, 1):
                          factor = 1.0 / factor
                      table = np.array([((i / 255.0) ** factor) * 255 for i in np.arange(0, 256)]).astype(np.uint8)
                      image = cv2.LUT(image, table)
  
                  # get rotation or zoom
                  if rotation and random.randint(0, 1):
                      angle = random.gauss(mu=0.0, sigma=rotation)
                  else:
                      angle = 0.0
                  if zoom and random.randint(0, 1):
                      scale = random.gauss(mu=1.0, sigma=zoom)
                  else:
                      scale = 1.0
  
                  # perform rotation or zoom
                  if rotation or zoom:
                      M = cv2.getRotationMatrix2D((image.shape[1] // 2, image.shape[0] // 2), angle, scale)
                      image = cv2.warpAffine(image, M, (image.shape[1], image.shape[0]))
                      label = cv2.warpAffine(label, M, (label.shape[1], label.shape[0]))
  
              X_color[j, :, :, :] = image
              X_depth[j, :, :, :] = image_depth
  
              Y1[j] = to_categorical(cv2.resize(label, (label.shape[1] // 4, label.shape[0] // 4)), n_classes)
              Y2[j] = to_categorical(cv2.resize(label, (label.shape[1] // 8, label.shape[0] // 8)), n_classes)
              Y3[j] = to_categorical(cv2.resize(label, (label.shape[1] // 16, label.shape[0] // 16)), n_classes)
  
              j += 1
              if j == batch_size:
                  break
  
          yield [X_color, X_depth], [Y1, Y2, Y3]
function_tokens: def fusion_generator ( df , resize_shape , n_classes = 34 , batch_size = 1 , horizontal_flip = True , vertical_flip = False , brightness = 0.1 , rotation = 5.0 , zoom = 0.1 , training = True ) : X_color = np . zeros ( ( batch_size , resize_shape [ 1 ] , resize_shape [ 0 ] , 3 ) , dtype = 'float32' ) X_depth = np . zeros ( ( batch_size , resize_shape [ 1 ] , resize_shape [ 0 ] , 3 ) , dtype = 'float32' ) Y1 = np . zeros ( ( batch_size , resize_shape [ 1 ] // 4 , resize_shape [ 0 ] // 4 , n_classes ) , dtype = 'float32' ) Y2 = np . zeros ( ( batch_size , resize_shape [ 1 ] // 8 , resize_shape [ 0 ] // 8 , n_classes ) , dtype = 'float32' ) Y3 = np . zeros ( ( batch_size , resize_shape [ 1 ] // 16 , resize_shape [ 0 ] // 16 , n_classes ) , dtype = 'float32' ) while 1 : j = 0 for index in np . random . permutation ( len ( df ) ) : image , image_depth , label = _load_rgb_depth_image_label ( df [ index ] ) image = cv2 . resize ( image , resize_shape ) image_depth = cv2 . resize ( image_depth , resize_shape ) label = cv2 . resize ( label , resize_shape ) # Do augmentation (only if training) if training : if horizontal_flip and random . randint ( 0 , 1 ) : image = cv2 . flip ( image , 1 ) label = cv2 . flip ( label , 1 ) if vertical_flip and random . randint ( 0 , 1 ) : image = cv2 . flip ( image , 0 ) label = cv2 . flip ( label , 0 ) if brightness and random . randint ( 0 , 1 ) : factor = 1.0 + abs ( random . gauss ( mu = 0.0 , sigma = brightness ) ) if random . randint ( 0 , 1 ) : factor = 1.0 / factor table = np . array ( [ ( ( i / 255.0 ) ** factor ) * 255 for i in np . arange ( 0 , 256 ) ] ) . astype ( np . uint8 ) image = cv2 . LUT ( image , table ) # get rotation or zoom if rotation and random . randint ( 0 , 1 ) : angle = random . gauss ( mu = 0.0 , sigma = rotation ) else : angle = 0.0 if zoom and random . randint ( 0 , 1 ) : scale = random . gauss ( mu = 1.0 , sigma = zoom ) else : scale = 1.0 # perform rotation or zoom if rotation or zoom : M = cv2 . getRotationMatrix2D ( ( image . shape [ 1 ] // 2 , image . shape [ 0 ] // 2 ) , angle , scale ) image = cv2 . warpAffine ( image , M , ( image . shape [ 1 ] , image . shape [ 0 ] ) ) label = cv2 . warpAffine ( label , M , ( label . shape [ 1 ] , label . shape [ 0 ] ) ) X_color [ j , : , : , : ] = image X_depth [ j , : , : , : ] = image_depth Y1 [ j ] = to_categorical ( cv2 . resize ( label , ( label . shape [ 1 ] // 4 , label . shape [ 0 ] // 4 ) ) , n_classes ) Y2 [ j ] = to_categorical ( cv2 . resize ( label , ( label . shape [ 1 ] // 8 , label . shape [ 0 ] // 8 ) ) , n_classes ) Y3 [ j ] = to_categorical ( cv2 . resize ( label , ( label . shape [ 1 ] // 16 , label . shape [ 0 ] // 16 ) ) , n_classes ) j += 1 if j == batch_size : break yield [ X_color , X_depth ] , [ Y1 , Y2 , Y3 ]