Skip to content

Add deep learning detection func#2288

Closed
CousinRock wants to merge 6 commits intogee-community:masterfrom
CousinRock:master
Closed

Add deep learning detection func#2288
CousinRock wants to merge 6 commits intogee-community:masterfrom
CousinRock:master

Conversation

@CousinRock
Copy link
Copy Markdown

@CousinRock CousinRock commented Aug 5, 2025

@giswqs Dear Professor Wu,
I have recently developed a new feature for geemap that integrates GeoAI to perform model inference directly on imagery from GEE. This functionality enables users to apply local deep learning models for instance segmentation and semantic segmentation on GEE images in an intuitive and efficient way.
I have tested this extension and it works well for various applications such as building extraction and land cover classification using NAIP imagery. I would like to contribute this feature to the geemap project, and I would greatly appreciate your feedback or suggestions on the integration and contribution process. Thank you for your time and support.

Instance segmentation

import ee
import geemap

ee.Authenticate()
ee.Initialize(project='ee-renjiewu660')

m = geemap.Map(basemap = 'SATELLITE')
m

image = ee.Image('projects/ee-renjiewu660/assets/vgee/naip_test')
dataset = ee.ImageCollection('USDA/NAIP/DOQQ')
.filter(ee.Filter.date('2017-01-01', '2018-12-31')).median().toUint8()
roi = image.geometry()
TrueColor = dataset.select(['R', 'G', 'B']).clip(roi)
TrueColorVis = {
"bands": ['R', 'G', 'B'],
"min": 0,
"max": 255,
}
m.addLayer(TrueColor, TrueColorVis, 'True Color')
m.centerObject(image)
m

model_path = "/mnt/e/DATA/TrainModel/BuildingDec/best_model.pth"

infer_area = geemap.detect_instance_segmentation(
image=TrueColor,
model_path=model_path,
scale=0.6,
window_size=512,
overlap=128,
confidence_threshold=0.5,
batch_size=4,
num_channels=3,
min_area=0,
max_tile_size=1,
max_tile_dim=512,
region = roi
)
infer_area
image

m.addLayer(infer_area,{},'t')
m
image

semantic segmentation

import ee
import geemap

ee.Authenticate()
ee.Initialize(project='ee-renjiewu660')

m = geemap.Map(basemap = 'SATELLITE')
m

image = ee.Image('projects/ee-renjiewu660/assets/vgee/m_3807511_se_18_060_20181104')
dataset = ee.ImageCollection('USDA/NAIP/DOQQ')
.filter(ee.Filter.date('2017-01-01', '2018-12-31')).median().toUint8()
roi = m.user_roi
TrueColor = dataset.clip(roi)
TrueColorVis = {
"bands": ['R', 'G', 'B'],
"min": 0,
"max": 255,
}
m.addLayer(TrueColor, TrueColorVis, 'True Color')
m.centerObject(image)
m

model_path = "/mnt/e/DATA/TrainModel/LandcoverDec/best_model.pth"

infer_area = geemap.detect_semantic_segmentation(
image=TrueColor,
model_path=model_path,
scale=0.6,
window_size=512,
overlap=128,
confidence_threshold=0.95,
batch_size=4,
num_channels=4,
num_classes=13,
min_area=0,
max_tile_size=1,
max_tile_dim=512,
region = roi
)

infer_area
image

m.addLayer(infer_area,{},'t')
m
image

@giswqs
Copy link
Copy Markdown
Member

giswqs commented Aug 13, 2025

Thank you for your contribution. I am sorry that we won't be able to to merge this PR. The geoai package has a lot of heavy dependencies. We won't be able to add it as a dependency for geemap. You can try to contribute this PR to the geoai package.

@giswqs giswqs closed this Aug 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants