将图像数组导出到Google Earth Engine中的TFRecord [英] Exporting image array to TFRecord in Google Earth Engine

查看:326
本文介绍了将图像数组导出到Google Earth Engine中的TFRecord的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将3个Landsat图像(每个12波段)的集合转换为单个图像数组,然后以TFRecord格式导出.我用下面的代码.我的输入集合名为images. imageT是从零带开始的累积图像,该零带在末尾掉落.最终imageOfSeries图片的每个像素都包含一个3x12大小的矩阵:

I want to convert a collection of 3 Landsat images (each 12 band) to a single image array and then export it in TFRecord format. I used below code. My input collection is named images. imageT is the accumulated image, starting with a zero band which is dropped at the end. Each pixel of final imageOfSeries image contain a matrix of size 3x12:

var imageT = ee.Image(0)
images = images.map(function(image){
  return image.toArray();
})   
var accumulate = function(image, imageT) {
  return(ee.Image(imageT).addBands(image)) 
};
var imageOfSeries = ee.Image(images.iterate(accumulate, imageT))
                             .slice(1).toArray(1).matrixTranspose()        
Export.image.toDrive({
  image: imageOfSeries,
  description: 'imageOfSeriesExample',
  scale: 30,
  region: geometry,
  fileFormat: 'TFRecord',
  formatOptions: {
    patchDimensions: [10,10],
    tensorDepths: [3,12]
  }
});

但是GEE在运行导出任务时返回错误,并说Arrays must have dimensions = 1. 我该怎么做?在这种情况下,我还需要更多有关如何解码TFRecord文件的信息,在GEE教程中找不到该示例.

But GEE returns an error when running the export task and says that Arrays must have dimensions = 1. How can I do my task? I also need to have more information on how to decode the TFRecord file in such a case, for which I couldn't find any example in GEE tutorial.

推荐答案

要执行所需的操作,您需要将矩阵展平以导出:导出到TFRecord仅支持一维数组(错误指出).目前,EE不支持直接数组展平,而是希望为数组中每个展平的元素添加标签.

To do what you want you'll need to flatten your matrix for export: export to TFRecord only supports 1D arrays (as pointed out by the error). For now EE doesn't support direct array flattening and wants labels per flattened element of the array.

张量深度还需要按顺序排列数组带的一维长度.

Also tensor depth wants the 1D length of your array bands in order.

假设您的图像恰好具有一个阵列带,这应该可以工作(详细说明):

Assuming your image has exactly one array band, this should work (verbose to make a point):

var imageT = ee.Image(0)
images = images.map(function(image){
  return image.toArray();
})   
var accumulate = function(image, imageT) {
  return(ee.Image(imageT).addBands(image)) 
};
var imageOfSeries = ee.Image(images.iterate(accumulate, imageT))
                             .slice(1).toArray(1).matrixTranspose()  

imageOfSeriesFlattened = imageOfSeries
    .arrayFlatten([
        ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
        ['13', '14', '15', '16', '17', '18', '19', '20', '21', '22', '23', '24'],
        ['25', '26', '27', '28', '29', '30', '31', '32', '33', '34', '35', '36']])
    .toArray();  

Export.image.toDrive({
  image: imageOfSeriesFlattened,
  description: 'imageOfSeriesExample',
  scale: 30,
  region: geometry,
  fileFormat: 'TFRecord',
  formatOptions: {
    patchDimensions: [10,10],
    tensorDepths: [36]
  }
});

这篇关于将图像数组导出到Google Earth Engine中的TFRecord的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆