parameters: (im_size, polys, tags, image_name, scale_ratio)
return_statement: return seg_maps, training_mask
docstring: :param im_size: input image size
      :param polys: input text regions
      :param tags: ignore text regions tags
      :param image_index: for log
      :param scale_ratio:ground truth scale ratio, default[0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
      :return:
      seg_maps: segmentation results with different scale ratio, save in different channel
      training_mask: ignore text regions
docstring_summary: :param im_size: input image size
      :param polys: input text regions
      :param tags: ignore text regions tags
      :param image_index: for log
      :param scale_ratio:ground truth scale ratio, default[0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
      :return:
      seg_maps: segmentation results with different scale ratio, save in different channel
      training_mask: ignore text regions
docstring_tokens: : param im_size : input image size : param polys : input text regions : param tags : ignore text regions tags : param image_index : for log : param scale_ratio : ground truth scale ratio default [ 0 . 5 0 . 6 0 . 7 0 . 8 0 . 9 1 . 0 ] : return : seg_maps : segmentation results with different scale ratio save in different channel training_mask : ignore text regions
function: def generate_seg(im_size, polys, tags, image_name, scale_ratio):
      '''
      :param im_size: input image size
      :param polys: input text regions
      :param tags: ignore text regions tags
      :param image_index: for log
      :param scale_ratio:ground truth scale ratio, default[0.5, 0.6, 0.7, 0.8, 0.9, 1.0]
      :return:
      seg_maps: segmentation results with different scale ratio, save in different channel
      training_mask: ignore text regions
      '''
      h, w = im_size
      #mark different text poly
      seg_maps = np.zeros((h,w,6), dtype=np.uint8)
      # mask used during traning, to ignore some hard areas
      training_mask = np.ones((h, w), dtype=np.uint8)
      ignore_poly_mark = []
      for i in range(len(scale_ratio)):
          seg_map = np.zeros((h,w), dtype=np.uint8)
          for poly_idx, poly_tag in enumerate(zip(polys, tags)):
              poly = poly_tag[0]
              tag = poly_tag[1]
  
              # ignore ###
              if i == 0 and tag:
                  cv2.fillPoly(training_mask, poly.astype(np.int32)[np.newaxis, :, :], 0)
                  ignore_poly_mark.append(poly_idx)
  
              # seg map
              shrinked_polys = []
              if poly_idx not in ignore_poly_mark:
                  shrinked_polys = shrink_poly(poly.copy(), scale_ratio[i])
  
              if not len(shrinked_polys) and poly_idx not in ignore_poly_mark:
                  logger.info("before shrink poly area:{} len(shrinked_poly) is 0,image {}".format(
                      abs(pyclipper.Area(poly)),image_name))
                  # if the poly is too small, then ignore it during training
                  cv2.fillPoly(training_mask, poly.astype(np.int32)[np.newaxis, :, :], 0)
                  ignore_poly_mark.append(poly_idx)
                  continue
              for shrinked_poly in shrinked_polys:
                  seg_map = cv2.fillPoly(seg_map, [np.array(shrinked_poly).astype(np.int32)], 1)
  
          seg_maps[..., i] = seg_map
      return seg_maps, training_mask
function_tokens: def generate_seg ( im_size , polys , tags , image_name , scale_ratio ) : h , w = im_size #mark different text poly seg_maps = np . zeros ( ( h , w , 6 ) , dtype = np . uint8 ) # mask used during traning, to ignore some hard areas training_mask = np . ones ( ( h , w ) , dtype = np . uint8 ) ignore_poly_mark = [ ] for i in range ( len ( scale_ratio ) ) : seg_map = np . zeros ( ( h , w ) , dtype = np . uint8 ) for poly_idx , poly_tag in enumerate ( zip ( polys , tags ) ) : poly = poly_tag [ 0 ] tag = poly_tag [ 1 ] # ignore ### if i == 0 and tag : cv2 . fillPoly ( training_mask , poly . astype ( np . int32 ) [ np . newaxis , : , : ] , 0 ) ignore_poly_mark . append ( poly_idx ) # seg map shrinked_polys = [ ] if poly_idx not in ignore_poly_mark : shrinked_polys = shrink_poly ( poly . copy ( ) , scale_ratio [ i ] ) if not len ( shrinked_polys ) and poly_idx not in ignore_poly_mark : logger . info ( "before shrink poly area:{} len(shrinked_poly) is 0,image {}" . format ( abs ( pyclipper . Area ( poly ) ) , image_name ) ) # if the poly is too small, then ignore it during training cv2 . fillPoly ( training_mask , poly . astype ( np . int32 ) [ np . newaxis , : , : ] , 0 ) ignore_poly_mark . append ( poly_idx ) continue for shrinked_poly in shrinked_polys : seg_map = cv2 . fillPoly ( seg_map , [ np . array ( shrinked_poly ) . astype ( np . int32 ) ] , 1 ) seg_maps [ ... , i ] = seg_map return seg_maps , training_mask