【问题标题】:Exporting TFRecords training patches with Google Earth Engine (kernelSize issues)使用 Google Earth Engine 导出 TFRecords 训练补丁(kernelSize 问题)
【发布时间】:2020-07-01 08:47:51
【问题描述】:

我一直在使用 GEE 从 Sentinel-2 中导出一些训练补丁,以便在 Python 中使用。 我可以通过遵循 GEE 指南 https://developers.google.com/earth-engine/tfrecord 并使用 Export.image.toDrive 函数使其工作,然后我可以解析导出的 TFRecord 文件以重建我的图块。

var image_export_options = {
  'patchDimensions': [366, 366],
  'maxFileSize': 104857600,
  // 'kernelSize': [366, 366],
  'compressed': true
}

Export.image.toDrive({
  image: clipped_img.select(bands.concat(['classes'])),
  description: 'PatchesExport',
  fileNamePrefix: 'Oros_1',
  scale: 10,
  folder: 'myExportFolder',
  fileFormat: 'TFRecord',
  region: export_area,
  formatOptions: image_export_options,  
})

但是,当我尝试在 formatOptions 中指定 kernelSize 时(应该 “将相邻的图块重叠 [kernelSize[0]/2, kernelSize[1]/2]” ,根据指南)文件已导出,但“*mixer.json”并未反映补丁数量的增加,之后我无法遍历补丁。以下命令使 google colab 会话崩溃:

image_dataset = tf.data.TFRecordDataset(str(path/(file_prefix+'-00000.tfrecord.gz')), compression_type='GZIP')
first = next(iter(image_dataset))
first

奇怪的是,只有当我将 kernelSize 添加到 formatOptions 时才会出现问题。

【问题讨论】:

    标签: tensorflow training-data google-earth-engine tfrecord


    【解决方案1】:

    在尝试解决这个问题一段时间后,我发现当使用内核大小从 GEE 导出补丁时,我发现了一种没有很好记录的行为。 与导出的 TFRecord 捆绑在一起,存在一个名为 mixerxml 文件。 我们是否使用都没关系:

    'patchDimensions': [184, 184],
    'kernelSize': [1, 1],  #default for no overlapping
    

    'patchDimensions': [184, 184],
    'kernelSize': [184, 184],  #half patch overlapping
    

    混合器文件保持不变,没有提及内核/重叠大小:

    {'patchDimensions': [184, 184],
     'patchesPerRow': 8,
     'projection': {'affine': {'doubleMatrix': [10.0,
        0.0,
        493460.0,
        0.0,
        -10.0,
        9313540.0]},
      'crs': 'EPSG:32724'},
     'totalPatches': 40}
    

    在第二种情况下,如果我们尝试使用 tf.io.parse_single_example(example_proto, image_features_dict) 解析补丁,其中 image_features_dict 等于:

    {'B2': FixedLenFeature(shape=[184, 184], dtype=tf.float32, default_value=None),
     'B3': FixedLenFeature(shape=[184, 184], dtype=tf.float32, default_value=None),
     'B4': FixedLenFeature(shape=[184, 184], dtype=tf.float32, default_value=None)}
    

    它会引发错误:

    _FallbackException: This function does not handle the case of the path where all inputs are not already EagerTensors.
    Can't parse serialized Example. [Op:ParseExampleV2]
    

    相反,要解析这些 kernelSize > 1 的记录,我们必须将 patchDimentions + kernelSize 视为生成的补丁大小,即使 mixer.xml 文件相反。在本例中,我们的 patchSize 为 368(原始补丁大小 + kernelSize)。请注意,对于奇数内核大小,要添加到原始补丁大小的数字是 kernelSize - 1。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-26
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2019-03-29
      • 1970-01-01
      • 2021-06-03
      • 1970-01-01
      相关资源
      最近更新 更多