title: Get train data generator and save them
body: <p>I am developing a faster RCNN algorithm. I have a function get_anchor_gt that Generate the ground_truth anchors.I call the function in the following code</p>
  <pre><code># Get train data generator which generate X, Y, image_data
  data_gen_train = get_anchor_gt(train_imgs, C, get_img_output_length, mode='train')
  </code></pre>
  <p>When I execute the following code</p>
  <pre><code>X, Y, image_data, debug_img, debug_num_pos = next(data_gen_train)
  </code></pre>
  <p>it start to train and its saving in the jupyter notebook and the size grows up to 200 mbs and the notebook crush.Is there a way I can save then somewhere like in the harddisk and later load them?</p>
  <p>This is get_anchor_gt</p>
  <pre><code>#Generate the ground_truth anchors
  
  def get_anchor_gt(all_img_data, C, img_length_calc_function, mode='train'):
  &quot;&quot;&quot; Yield the ground-truth anchors as Y (labels)
  
  Args:
      all_img_data: list(filepath, width, height, list(bboxes))
      C: config
      img_length_calc_function: function to calculate final layer's feature map (of base model) size according to input image size
      mode: 'train' or 'test'; 'train' mode need augmentation
  
  Returns:
      x_img: image data after resized and scaling (smallest size = 300px)
      Y: [y_rpn_cls, y_rpn_regr]
      img_data_aug: augmented image data (original image with augmentation)
      debug_img: show image for debug
      num_pos: show number of positive anchors for debug
  &quot;&quot;&quot;
  while True:
  
      for img_data in all_img_data:
          try:
  
              # read in image, and optionally add augmentation
  
              if mode == 'train':
                  img_data_aug, x_img = augment(img_data, C, augment=True)
              else:
                  img_data_aug, x_img = augment(img_data, C, augment=False)
  
              (width, height) = (img_data_aug['width'], img_data_aug['height'])
              (rows, cols, _) = x_img.shape
  
              assert cols == width
              assert rows == height
  
              # get image dimensions for resizing
              (resized_width, resized_height) = get_new_img_size(width, height, C.im_size)
  
              # resize the image so that smalles side is length = 300px
              x_img = cv2.resize(x_img, (resized_width, resized_height), interpolation=cv2.INTER_CUBIC)
              debug_img = x_img.copy()
  
              try:
                  y_rpn_cls, y_rpn_regr, num_pos = calc_rpn(C, img_data_aug, width, height, resized_width, resized_height, img_length_calc_function)
              except:
                  continue
  
              # Zero-center by mean pixel, and preprocess image
  
              x_img = x_img[:,:, (2, 1, 0)]  # BGR -&gt; RGB
              x_img = x_img.astype(np.float32)
              x_img[:, :, 0] -= C.img_channel_mean[0]
              x_img[:, :, 1] -= C.img_channel_mean[1]
              x_img[:, :, 2] -= C.img_channel_mean[2]
              x_img /= C.img_scaling_factor
  
              x_img = np.transpose(x_img, (2, 0, 1))
              x_img = np.expand_dims(x_img, axis=0)
  
              y_rpn_regr[:, y_rpn_regr.shape[1]//2:, :, :] *= C.std_scaling
  
              x_img = np.transpose(x_img, (0, 2, 3, 1))
              y_rpn_cls = np.transpose(y_rpn_cls, (0, 2, 3, 1))
              y_rpn_regr = np.transpose(y_rpn_regr, (0, 2, 3, 1))
  
              yield np.copy(x_img), [np.copy(y_rpn_cls), np.copy(y_rpn_regr)], img_data_aug, debug_img, num_pos
  
          except Exception as e:
              print(e)
              continue
  </code></pre>