Pengumuman: Semua project nonkomersial yang terdaftar untuk menggunakan Earth Engine sebelum
15 April 2025 harus
memverifikasi kelayakan nonkomersial untuk mempertahankan akses Earth Engine.
Export.classifier.toAsset
Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Membuat tugas batch untuk mengekspor ee.Classifier sebagai aset Earth Engine.
Hanya didukung untuk ee.Classifier.smileRandomForest, ee.Classifier.smileCart, ee.Classifier.DecisionTree, dan ee.Classifier.DecisionTreeEnsemble.
Penggunaan | Hasil |
---|
Export.classifier.toAsset(classifier, description, assetId, priority) | |
Argumen | Jenis | Detail |
---|
classifier | ComputedObject | Pengklasifikasi yang akan diekspor. |
description | String, opsional | Nama tugas yang dapat dibaca manusia. Defaultnya adalah "myExportClassifierTask". |
assetId | String, opsional | ID aset tujuan. |
priority | Angka, opsional | Prioritas tugas dalam project. Tugas dengan prioritas lebih tinggi akan dijadwalkan lebih cepat. Harus berupa bilangan bulat antara 0 dan 9999. Setelan defaultnya adalah 100. |
Contoh
Editor Kode (JavaScript)
// First gather the training data for a random forest classifier.
// Let's use MCD12Q1 yearly landcover for the labels.
var landcover = ee.ImageCollection('MODIS/061/MCD12Q1')
.filterDate('2022-01-01', '2022-12-31')
.first()
.select('LC_Type1');
// A region of interest for training our classifier.
var region = ee.Geometry.BBox(17.33, 36.07, 26.13, 43.28);
// Training features will be based on a Landsat 8 composite.
var l8 = ee.ImageCollection('LANDSAT/LC08/C02/T1')
.filterBounds(region)
.filterDate('2022-01-01', '2023-01-01');
// Draw the Landsat composite, visualizing true color bands.
var landsatComposite = ee.Algorithms.Landsat.simpleComposite({
collection: l8,
asFloat: true
});
Map.addLayer(landsatComposite, {
min: 0,
max: 0.3,
bands: ['B3', 'B2', 'B1']
}, 'Landsat composite');
// Make a training dataset by sampling the stacked images.
var training = landcover.addBands(landsatComposite).sample({
region: region,
scale: 30,
// With export to Classifier we can bump this higher to say 10,000.
numPixels: 1000
});
var classifier = ee.Classifier.smileRandomForest({
// We can also increase the number of trees higher to ~100 if needed.
numberOfTrees: 3
}).train({features: training, classProperty: 'LC_Type1'});
// Create an export classifier task to run.
var assetId = 'projects/<project-name>/assets/<asset-name>'; // <> modify these
Export.classifier.toAsset({
classifier: classifier,
description: 'classifier_export',
assetId: assetId
});
// Load the classifier after the export finishes and visualize.
var savedClassifier = ee.Classifier.load(assetId)
var landcoverPalette = '05450a,086a10,54a708,78d203,009900,c6b044,dcd159,' +
'dade48,fbff13,b6ff05,27ff87,c24f44,a5a5a5,ff6d4c,69fff8,f9ffa4,1c0dff';
var landcoverVisualization = {
palette: landcoverPalette,
min: 0,
max: 16,
format: 'png'
};
Map.addLayer(
landsatComposite.classify(savedClassifier),
landcoverVisualization,
'Upsampled landcover, saved');
Penyiapan Python
Lihat halaman
Lingkungan Python untuk mengetahui informasi tentang Python API dan penggunaan
geemap
untuk pengembangan interaktif.
import ee
import geemap.core as geemap
Colab (Python)
# First gather the training data for a random forest classifier.
# Let's use MCD12Q1 yearly landcover for the labels.
landcover = (ee.ImageCollection('MODIS/061/MCD12Q1')
.filterDate('2022-01-01', '2022-12-31')
.first()
.select('LC_Type1'))
# A region of interest for training our classifier.
region = ee.Geometry.BBox(17.33, 36.07, 26.13, 43.28)
# Training features will be based on a Landsat 8 composite.
l8 = (ee.ImageCollection('LANDSAT/LC08/C02/T1')
.filterBounds(region)
.filterDate('2022-01-01', '2023-01-01'))
# Draw the Landsat composite, visualizing true color bands.
landsatComposite = ee.Algorithms.Landsat.simpleComposite(
collection=l8, asFloat=True)
Map = geemap.Map()
Map # Render the map in the notebook.
Map.addLayer(landsatComposite, {
'min': 0,
'max': 0.3,
'bands': ['B3', 'B2', 'B1']
}, 'Landsat composite')
# Make a training dataset by sampling the stacked images.
training = landcover.addBands(landsatComposite).sample(
region=region,
scale=30,
# With export to Classifier we can bump this higher to say 10,000.
numPixels=1000
)
# We can also increase the number of trees higher to ~100 if needed.
classifier = ee.Classifier.smileRandomForest(
numberOfTrees=3).train(features=training, classProperty='LC_Type1')
# Create an export classifier task to run.
asset_id = 'projects/<project-name>/assets/<asset-name>' # <> modify these
ee.batch.Export.classifier.toAsset(
classifier=classifier,
description='classifier_export',
assetId=asset_id
)
# Load the classifier after the export finishes and visualize.
savedClassifier = ee.Classifier.load(asset_id)
landcover_palette = [
'05450a', '086a10', '54a708', '78d203', '009900',
'c6b044', 'dcd159', 'dade48', 'fbff13', 'b6ff05',
'27ff87', 'c24f44', 'a5a5a5', 'ff6d4c', '69fff8',
'f9ffa4', '1c0dff']
landcoverVisualization = {
'palette': landcover_palette,
'min': 0,
'max': 16,
'format': 'png'
}
Map.addLayer(
landsatComposite.classify(savedClassifier),
landcoverVisualization,
'Upsampled landcover, saved')
Kecuali dinyatakan lain, konten di halaman ini dilisensikan berdasarkan Lisensi Creative Commons Attribution 4.0, sedangkan contoh kode dilisensikan berdasarkan Lisensi Apache 2.0. Untuk mengetahui informasi selengkapnya, lihat Kebijakan Situs Google Developers. Java adalah merek dagang terdaftar dari Oracle dan/atau afiliasinya.
Terakhir diperbarui pada 2025-07-25 UTC.
[null,null,["Terakhir diperbarui pada 2025-07-25 UTC."],[[["\u003cp\u003eExports an Earth Engine classifier as an asset for later use.\u003c/p\u003e\n"],["\u003cp\u003eAllows customization of the export task with description, asset ID, and priority settings.\u003c/p\u003e\n"],["\u003cp\u003eProvides code examples in JavaScript and Python demonstrating the export and subsequent use of the saved classifier.\u003c/p\u003e\n"],["\u003cp\u003eUtilizes a Landsat-based composite and MODIS landcover data for training the classifier in the examples.\u003c/p\u003e\n"],["\u003cp\u003eEnables efficient saving and loading of trained classifiers within the Earth Engine platform.\u003c/p\u003e\n"]]],["This content details exporting an `ee.Classifier` as an Earth Engine asset using `Export.classifier.toAsset`. Key actions include: creating a classifier, defining a training dataset using landcover data and Landsat composites, sampling training data, and then training the classifier. The export process involves specifying the `classifier`, `description`, `assetId`, and `priority`. After export, the saved classifier can be loaded and used for classification, then visualized.\n"],null,["# Export.classifier.toAsset\n\n\u003cbr /\u003e\n\nCreates a batch task to export an ee.Classifier as an Earth Engine asset.\n\n\u003cbr /\u003e\n\nOnly supported for ee.Classifier.smileRandomForest, ee.Classifier.smileCart, ee.Classifier.DecisionTree and ee.Classifier.DecisionTreeEnsemble.\n\n| Usage | Returns |\n|---------------------------------------------------------------------------------------|---------|\n| `Export.classifier.toAsset(classifier, `*description* `, `*assetId* `, `*priority*`)` | |\n\n| Argument | Type | Details |\n|---------------|------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|\n| `classifier` | ComputedObject | The classifier to export. |\n| `description` | String, optional | A human-readable name of the task. Defaults to \"myExportClassifierTask\". |\n| `assetId` | String, optional | The destination asset ID. |\n| `priority` | Number, optional | The priority of the task within the project. Higher priority tasks are scheduled sooner. Must be an integer between 0 and 9999. Defaults to 100. |\n\nExamples\n--------\n\n### Code Editor (JavaScript)\n\n```javascript\n// First gather the training data for a random forest classifier.\n// Let's use MCD12Q1 yearly landcover for the labels.\nvar landcover = ee.ImageCollection('MODIS/061/MCD12Q1')\n .filterDate('2022-01-01', '2022-12-31')\n .first()\n .select('LC_Type1');\n// A region of interest for training our classifier.\nvar region = ee.Geometry.BBox(17.33, 36.07, 26.13, 43.28);\n\n// Training features will be based on a Landsat 8 composite.\nvar l8 = ee.ImageCollection('LANDSAT/LC08/C02/T1')\n .filterBounds(region)\n .filterDate('2022-01-01', '2023-01-01');\n\n// Draw the Landsat composite, visualizing true color bands.\nvar landsatComposite = ee.Algorithms.Landsat.simpleComposite({\n collection: l8,\n asFloat: true\n});\nMap.addLayer(landsatComposite, {\n min: 0,\n max: 0.3,\n bands: ['B3', 'B2', 'B1']\n}, 'Landsat composite');\n\n// Make a training dataset by sampling the stacked images.\nvar training = landcover.addBands(landsatComposite).sample({\n region: region,\n scale: 30,\n // With export to Classifier we can bump this higher to say 10,000.\n numPixels: 1000\n});\n\nvar classifier = ee.Classifier.smileRandomForest({\n // We can also increase the number of trees higher to ~100 if needed.\n numberOfTrees: 3\n}).train({features: training, classProperty: 'LC_Type1'});\n\n// Create an export classifier task to run.\nvar assetId = 'projects/\u003cproject-name\u003e/assets/\u003casset-name\u003e'; // \u003c\u003e modify these\nExport.classifier.toAsset({\n classifier: classifier,\n description: 'classifier_export',\n assetId: assetId\n});\n\n// Load the classifier after the export finishes and visualize.\nvar savedClassifier = ee.Classifier.load(assetId)\nvar landcoverPalette = '05450a,086a10,54a708,78d203,009900,c6b044,dcd159,' +\n 'dade48,fbff13,b6ff05,27ff87,c24f44,a5a5a5,ff6d4c,69fff8,f9ffa4,1c0dff';\nvar landcoverVisualization = {\n palette: landcoverPalette,\n min: 0,\n max: 16,\n format: 'png'\n};\nMap.addLayer(\n landsatComposite.classify(savedClassifier),\n landcoverVisualization,\n 'Upsampled landcover, saved');\n```\nPython setup\n\nSee the [Python Environment](/earth-engine/guides/python_install) page for information on the Python API and using\n`geemap` for interactive development. \n\n```python\nimport ee\nimport geemap.core as geemap\n```\n\n### Colab (Python)\n\n```python\n# First gather the training data for a random forest classifier.\n# Let's use MCD12Q1 yearly landcover for the labels.\nlandcover = (ee.ImageCollection('MODIS/061/MCD12Q1')\n .filterDate('2022-01-01', '2022-12-31')\n .first()\n .select('LC_Type1'))\n\n# A region of interest for training our classifier.\nregion = ee.Geometry.BBox(17.33, 36.07, 26.13, 43.28)\n\n# Training features will be based on a Landsat 8 composite.\nl8 = (ee.ImageCollection('LANDSAT/LC08/C02/T1')\n .filterBounds(region)\n .filterDate('2022-01-01', '2023-01-01'))\n\n# Draw the Landsat composite, visualizing true color bands.\nlandsatComposite = ee.Algorithms.Landsat.simpleComposite(\n collection=l8, asFloat=True)\n\nMap = geemap.Map()\nMap # Render the map in the notebook.\nMap.addLayer(landsatComposite, {\n 'min': 0,\n 'max': 0.3,\n 'bands': ['B3', 'B2', 'B1']\n}, 'Landsat composite')\n\n# Make a training dataset by sampling the stacked images.\ntraining = landcover.addBands(landsatComposite).sample(\n region=region,\n scale=30,\n # With export to Classifier we can bump this higher to say 10,000.\n numPixels=1000\n)\n\n# We can also increase the number of trees higher to ~100 if needed.\nclassifier = ee.Classifier.smileRandomForest(\n numberOfTrees=3).train(features=training, classProperty='LC_Type1')\n\n# Create an export classifier task to run.\nasset_id = 'projects/\u003cproject-name\u003e/assets/\u003casset-name\u003e' # \u003c\u003e modify these\nee.batch.Export.classifier.toAsset(\n classifier=classifier,\n description='classifier_export',\n assetId=asset_id\n)\n\n# Load the classifier after the export finishes and visualize.\nsavedClassifier = ee.Classifier.load(asset_id)\nlandcover_palette = [\n '05450a', '086a10', '54a708', '78d203', '009900',\n 'c6b044', 'dcd159', 'dade48', 'fbff13', 'b6ff05',\n '27ff87', 'c24f44', 'a5a5a5', 'ff6d4c', '69fff8',\n 'f9ffa4', '1c0dff']\nlandcoverVisualization = {\n 'palette': landcover_palette,\n 'min': 0,\n 'max': 16,\n 'format': 'png'\n}\nMap.addLayer(\n landsatComposite.classify(savedClassifier),\n landcoverVisualization,\n 'Upsampled landcover, saved')\n```"]]