geoai 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/@geobase.js/geoai.js +11347 -0
- package/CHANGELOG.md +62 -0
- package/LICENSE.md +9 -0
- package/README.md +67 -0
- package/index.d.ts +545 -0
- package/package.json +79 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to the @geobase.js/geoai project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [0.0.7] - 2024-12-19
|
|
9
|
+
|
|
10
|
+
### Fixed
|
|
11
|
+
|
|
12
|
+
- Resolved CSS Module compilation issues in Next.js examples
|
|
13
|
+
- Fixed TypeScript type errors in color theme configuration
|
|
14
|
+
- Improved build process reliability
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- Updated package version for npm release
|
|
19
|
+
|
|
20
|
+
## [0.0.2] - 2024-12-19
|
|
21
|
+
|
|
22
|
+
### Changed
|
|
23
|
+
|
|
24
|
+
- Updated package version for npm release
|
|
25
|
+
|
|
26
|
+
## [0.0.1] - 2024-12-19
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- Initial public release of @geobase.js/geoai
|
|
31
|
+
- Support for multiple Geo AI models:
|
|
32
|
+
- Object Detection
|
|
33
|
+
- Building Footprint Segmentation
|
|
34
|
+
- Land Cover Classification
|
|
35
|
+
- Zero-shot Object Detection
|
|
36
|
+
- Oriented Object Detection
|
|
37
|
+
- Oil Storage Tank Detection
|
|
38
|
+
- Solar Panel Detection
|
|
39
|
+
- Ship Detection
|
|
40
|
+
- Car Detection
|
|
41
|
+
- Wetland Segmentation
|
|
42
|
+
- TypeScript support with full type definitions
|
|
43
|
+
- ESM module support
|
|
44
|
+
- CDN distribution via unpkg and jsDelivr
|
|
45
|
+
- Comprehensive test suite
|
|
46
|
+
- Documentation and examples
|
|
47
|
+
|
|
48
|
+
### Features
|
|
49
|
+
|
|
50
|
+
- Core GeoAI class for model interaction
|
|
51
|
+
- GeoRawImage class for image data handling
|
|
52
|
+
- Support for various image formats and sources
|
|
53
|
+
- Configurable confidence thresholds and parameters
|
|
54
|
+
- Framework-agnostic design for use with any JavaScript framework
|
|
55
|
+
|
|
56
|
+
### Technical
|
|
57
|
+
|
|
58
|
+
- Built with Vite 5.x
|
|
59
|
+
- TypeScript compilation and type generation
|
|
60
|
+
- ESLint and Prettier for code quality
|
|
61
|
+
- Vitest for testing
|
|
62
|
+
- Husky for pre-commit hooks
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Kamil Bysiec
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
[](https://github.com/decision-labs/geobase.js/actions/workflows/main.yml)
|
|
2
|
+
|
|
3
|
+
# `@geobase.js/geoai`
|
|
4
|
+
|
|
5
|
+
A Javascript library for running Geo AI models in frontend applications.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @geobase.js/geoai
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
### Core Library (Node.js and Browser)
|
|
16
|
+
|
|
17
|
+
```javascript
|
|
18
|
+
import { geoai } from "@geobase.js/geoai";
|
|
19
|
+
|
|
20
|
+
// Initialize the pipeline
|
|
21
|
+
const pipeline = await geoai.pipeline([{ task: "object-detection" }], {
|
|
22
|
+
provider: "geobase",
|
|
23
|
+
apikey: "your-api-key",
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// Run inference
|
|
27
|
+
const result = await pipeline.inference({
|
|
28
|
+
inputs: {
|
|
29
|
+
polygon: geoJsonFeature,
|
|
30
|
+
},
|
|
31
|
+
mapSourceParams: {
|
|
32
|
+
zoomLevel: 18,
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Architecture
|
|
38
|
+
|
|
39
|
+
- **Core Module** (`@geobase.js/geoai`): Pure Javascript/TypeScript library that works in both Node.js and browser environments
|
|
40
|
+
|
|
41
|
+
## API Reference
|
|
42
|
+
|
|
43
|
+
### Core API
|
|
44
|
+
|
|
45
|
+
- `geoai.pipeline(tasks, config)` - Initialize a pipeline with tasks
|
|
46
|
+
- `pipeline.inference(params)` - Run inference with the pipeline
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
## Supported Tasks
|
|
50
|
+
|
|
51
|
+
- Object Detection
|
|
52
|
+
- Building Footprint Segmentation
|
|
53
|
+
- Land Cover Classification
|
|
54
|
+
- Zero-shot Object Detection
|
|
55
|
+
- Oriented Object Detection
|
|
56
|
+
- Oil Storage Tank Detection
|
|
57
|
+
- Ship Detection
|
|
58
|
+
- Solar Panel Detection
|
|
59
|
+
- Wetland Segmentation
|
|
60
|
+
- Mask Generation
|
|
61
|
+
- Car-Detection
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
MIT
|
|
66
|
+
|
|
67
|
+
~~togglebuild~~
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,545 @@
|
|
|
1
|
+
// Generated by dts-bundle-generator v9.5.1
|
|
2
|
+
|
|
3
|
+
import { PretrainedModelOptions, RawImage } from '@huggingface/transformers';
|
|
4
|
+
import * as ort from 'onnxruntime-web';
|
|
5
|
+
|
|
6
|
+
export interface Bounds {
|
|
7
|
+
north: number;
|
|
8
|
+
south: number;
|
|
9
|
+
east: number;
|
|
10
|
+
west: number;
|
|
11
|
+
}
|
|
12
|
+
declare class GeoRawImage extends RawImage {
|
|
13
|
+
private bounds;
|
|
14
|
+
private transform;
|
|
15
|
+
private crs;
|
|
16
|
+
constructor(data: Uint8ClampedArray | Uint8Array, width: number, height: number, channels: 1 | 2 | 3 | 4, bounds: Bounds, crs?: string);
|
|
17
|
+
/**
|
|
18
|
+
* Convert pixel coordinates to world coordinates
|
|
19
|
+
*/
|
|
20
|
+
pixelToWorld(x: number, y: number): [
|
|
21
|
+
number,
|
|
22
|
+
number
|
|
23
|
+
];
|
|
24
|
+
/**
|
|
25
|
+
* Convert world coordinates to pixel coordinates
|
|
26
|
+
*/
|
|
27
|
+
worldToPixel(lon: number, lat: number): [
|
|
28
|
+
number,
|
|
29
|
+
number
|
|
30
|
+
];
|
|
31
|
+
/**
|
|
32
|
+
* Get the bounds of the image
|
|
33
|
+
*/
|
|
34
|
+
getBounds(): Bounds;
|
|
35
|
+
/**
|
|
36
|
+
* Get the CRS of the image
|
|
37
|
+
*/
|
|
38
|
+
getCRS(): string;
|
|
39
|
+
/**
|
|
40
|
+
* Create a new GeoRawImage from a RawImage and georeferencing information
|
|
41
|
+
*/
|
|
42
|
+
static fromRawImage(rawImage: RawImage, bounds: Bounds, crs?: string): GeoRawImage;
|
|
43
|
+
/**
|
|
44
|
+
* Override the clone method to include georeferencing information
|
|
45
|
+
*/
|
|
46
|
+
clone(): GeoRawImage;
|
|
47
|
+
}
|
|
48
|
+
export type ObjectDectection = {
|
|
49
|
+
label: string;
|
|
50
|
+
score: number;
|
|
51
|
+
box: [
|
|
52
|
+
number,
|
|
53
|
+
number,
|
|
54
|
+
number,
|
|
55
|
+
number
|
|
56
|
+
];
|
|
57
|
+
};
|
|
58
|
+
declare const postProcessYoloOutput: (model_outputs: any, pixel_values: {
|
|
59
|
+
dims: number[];
|
|
60
|
+
}, rawImage: RawImage, id2label: {
|
|
61
|
+
[key: number]: string;
|
|
62
|
+
}) => ObjectDectection[];
|
|
63
|
+
declare const parametersChanged: (instance: any, model_id: string, providerParams: any, modelParams?: PretrainedModelOptions) => boolean;
|
|
64
|
+
declare const detectionsToGeoJSON: (detections: ObjectDectection[], geoRawImage: GeoRawImage) => GeoJSON.FeatureCollection;
|
|
65
|
+
declare const getPolygonFromMask: (mask: number[][], geoRawImage: GeoRawImage) => [
|
|
66
|
+
number,
|
|
67
|
+
number
|
|
68
|
+
][];
|
|
69
|
+
declare const maskToGeoJSON: (masks: any, geoRawImage: GeoRawImage, topN?: number) => GeoJSON.FeatureCollection;
|
|
70
|
+
declare const refineMasks: (binaryMasks: RawImage[], geoRawImage: GeoRawImage, classes?: string[], minArea?: number) => GeoJSON.FeatureCollection[];
|
|
71
|
+
declare const polygonsEqual: (polygon1: GeoJSON.Feature | null, polygon2: GeoJSON.Feature | null) => boolean;
|
|
72
|
+
declare abstract class MapSource {
|
|
73
|
+
protected abstract getTileUrlFromTileCoords(tileCoords: [
|
|
74
|
+
number,
|
|
75
|
+
number,
|
|
76
|
+
number
|
|
77
|
+
], instance: any, bands?: number[], expression?: string): string;
|
|
78
|
+
getImage(polygon: any, bands?: number[], expression?: string, zoomLevel?: number, requiresSquare?: boolean): Promise<GeoRawImage>;
|
|
79
|
+
}
|
|
80
|
+
declare class Mapbox extends MapSource {
|
|
81
|
+
apiKey: string;
|
|
82
|
+
style: string;
|
|
83
|
+
constructor(apiKey: string, style: string);
|
|
84
|
+
protected getTileUrlFromTileCoords(tileCoords: [
|
|
85
|
+
number,
|
|
86
|
+
number,
|
|
87
|
+
number
|
|
88
|
+
], instance: Mapbox): string;
|
|
89
|
+
}
|
|
90
|
+
export interface GeobaseConfig {
|
|
91
|
+
projectRef: string;
|
|
92
|
+
cogImagery: string;
|
|
93
|
+
apikey: string;
|
|
94
|
+
}
|
|
95
|
+
declare class Geobase extends MapSource {
|
|
96
|
+
projectRef: string;
|
|
97
|
+
cogImagery: string;
|
|
98
|
+
apikey: string;
|
|
99
|
+
constructor(config: GeobaseConfig);
|
|
100
|
+
protected getTileUrlFromTileCoords(tileCoords: [
|
|
101
|
+
number,
|
|
102
|
+
number,
|
|
103
|
+
number
|
|
104
|
+
], instance: Geobase, bands?: number[], expression?: string): string;
|
|
105
|
+
}
|
|
106
|
+
export interface EsriConfig {
|
|
107
|
+
serviceUrl?: string;
|
|
108
|
+
serviceName?: string;
|
|
109
|
+
tileSize?: number;
|
|
110
|
+
attribution?: string;
|
|
111
|
+
}
|
|
112
|
+
declare class Esri extends MapSource {
|
|
113
|
+
serviceUrl: string;
|
|
114
|
+
serviceName: string;
|
|
115
|
+
tileSize: number;
|
|
116
|
+
attribution: string;
|
|
117
|
+
constructor(config: EsriConfig);
|
|
118
|
+
protected getTileUrlFromTileCoords(tileCoords: [
|
|
119
|
+
number,
|
|
120
|
+
number,
|
|
121
|
+
number
|
|
122
|
+
], instance: Esri): string;
|
|
123
|
+
}
|
|
124
|
+
declare abstract class BaseModel {
|
|
125
|
+
protected static instance: BaseModel | null;
|
|
126
|
+
protected providerParams: ProviderParams;
|
|
127
|
+
protected dataProvider: Mapbox | Geobase | Esri | undefined;
|
|
128
|
+
protected model_id: string;
|
|
129
|
+
protected initialized: boolean;
|
|
130
|
+
protected modelParams?: PretrainedModelOptions;
|
|
131
|
+
protected constructor(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions);
|
|
132
|
+
protected initialize(): Promise<void>;
|
|
133
|
+
protected initializeDataProvider(): void;
|
|
134
|
+
/**
|
|
135
|
+
* Converts a GeoJSON polygon feature into a GeoRawImage using the configured data provider.
|
|
136
|
+
*
|
|
137
|
+
* @param polygon - The GeoJSON Feature representing the area of interest.
|
|
138
|
+
* @param zoomLevel - (Optional) The zoom level to use when retrieving the image.
|
|
139
|
+
* @param bands - (Optional) An array of band indices to select specific bands from the imagery.
|
|
140
|
+
* @param expression - (Optional) A string expression to apply to the image bands (e.g., for band math).
|
|
141
|
+
* @param requiresSquare - (default false) Whether to return a square image.
|
|
142
|
+
* @returns A Promise that resolves to a GeoRawImage corresponding to the input polygon.
|
|
143
|
+
* @throws {Error} If the data provider is not initialized.
|
|
144
|
+
*/
|
|
145
|
+
protected polygonToImage(polygon: GeoJSON.Feature, zoomLevel?: number, bands?: number[], expression?: string, requiresSquare?: boolean): Promise<GeoRawImage>;
|
|
146
|
+
protected abstract initializeModel(): Promise<void>;
|
|
147
|
+
abstract inference(params: InferenceParams): Promise<unknown>;
|
|
148
|
+
}
|
|
149
|
+
export interface SegmentationResult {
|
|
150
|
+
masks: GeoJSON.FeatureCollection;
|
|
151
|
+
geoRawImage: GeoRawImage;
|
|
152
|
+
}
|
|
153
|
+
declare class MaskGeneration extends BaseModel {
|
|
154
|
+
protected static instance: MaskGeneration | null;
|
|
155
|
+
private model;
|
|
156
|
+
private processor;
|
|
157
|
+
private cachedPolygon;
|
|
158
|
+
private cachedEmbeddings;
|
|
159
|
+
private cachedGeoRawImage;
|
|
160
|
+
private constructor();
|
|
161
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
162
|
+
instance: MaskGeneration;
|
|
163
|
+
}>;
|
|
164
|
+
protected initializeModel(): Promise<void>;
|
|
165
|
+
/**
|
|
166
|
+
* Gets or computes image embeddings for the given polygon
|
|
167
|
+
* Uses cached embeddings if polygon hasn't changed
|
|
168
|
+
*/
|
|
169
|
+
private getOrComputeEmbeddings;
|
|
170
|
+
/**
|
|
171
|
+
* Performs segmentation on a geographic area based on the provided input parameters.
|
|
172
|
+
*
|
|
173
|
+
* @param params - Inference parameters containing:
|
|
174
|
+
* - inputs: Object containing polygon and segmentation input
|
|
175
|
+
* - postProcessingParams: Optional parameters for post-processing
|
|
176
|
+
* - mapSourceParams: Optional parameters for map source configuration
|
|
177
|
+
*
|
|
178
|
+
* @returns Promise<SegmentationResult> containing:
|
|
179
|
+
* - masks: GeoJSON representation of the segmentation masks
|
|
180
|
+
* - geoRawImage: Raw image data with geographic reference
|
|
181
|
+
*
|
|
182
|
+
* @throws {Error} If data provider is not initialized
|
|
183
|
+
* @throws {Error} If model or processor is not initialized
|
|
184
|
+
* @throws {Error} If segmentation process fails
|
|
185
|
+
* @throws {Error} If input type is not supported
|
|
186
|
+
*/
|
|
187
|
+
inference(params: InferenceParams): Promise<SegmentationResult>;
|
|
188
|
+
getImageEmbeddings(params: InferenceParams): Promise<{
|
|
189
|
+
image_embeddings: any;
|
|
190
|
+
geoRawImage: GeoRawImage;
|
|
191
|
+
}>;
|
|
192
|
+
}
|
|
193
|
+
declare abstract class BaseDetectionModel extends BaseModel {
|
|
194
|
+
protected model: ort.InferenceSession | undefined;
|
|
195
|
+
protected zoom?: number;
|
|
196
|
+
protected constructor(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions);
|
|
197
|
+
protected preProcessor(image: GeoRawImage): Promise<{
|
|
198
|
+
input: ort.Tensor;
|
|
199
|
+
}>;
|
|
200
|
+
protected initializeModel(): Promise<void>;
|
|
201
|
+
protected postProcessor(outputs: any, geoRawImage: GeoRawImage): Promise<GeoJSON.FeatureCollection>;
|
|
202
|
+
inference(params: InferenceParams): Promise<ObjectDetectionResults>;
|
|
203
|
+
}
|
|
204
|
+
declare class SolarPanelDetection extends BaseDetectionModel {
|
|
205
|
+
private static instanceRef;
|
|
206
|
+
private constructor();
|
|
207
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
208
|
+
instance: SolarPanelDetection;
|
|
209
|
+
}>;
|
|
210
|
+
}
|
|
211
|
+
declare class ShipDetection extends BaseDetectionModel {
|
|
212
|
+
private static instanceRef;
|
|
213
|
+
private constructor();
|
|
214
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
215
|
+
instance: ShipDetection;
|
|
216
|
+
}>;
|
|
217
|
+
}
|
|
218
|
+
declare class CarDetection extends BaseDetectionModel {
|
|
219
|
+
private static instanceRef;
|
|
220
|
+
private constructor();
|
|
221
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
222
|
+
instance: CarDetection;
|
|
223
|
+
}>;
|
|
224
|
+
}
|
|
225
|
+
declare class BuildingDetection extends BaseDetectionModel {
|
|
226
|
+
private static instanceRef;
|
|
227
|
+
private constructor();
|
|
228
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
229
|
+
instance: BuildingDetection;
|
|
230
|
+
}>;
|
|
231
|
+
}
|
|
232
|
+
declare class WetLandSegmentation extends BaseModel {
|
|
233
|
+
protected static instance: WetLandSegmentation | null;
|
|
234
|
+
protected model: ort.InferenceSession | undefined;
|
|
235
|
+
private constructor();
|
|
236
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
237
|
+
instance: WetLandSegmentation;
|
|
238
|
+
}>;
|
|
239
|
+
protected initializeModel(): Promise<void>;
|
|
240
|
+
protected preProcessor(image: GeoRawImage): Promise<{
|
|
241
|
+
input: ort.Tensor;
|
|
242
|
+
}>;
|
|
243
|
+
inference(params: InferenceParams): Promise<ObjectDetectionResults>;
|
|
244
|
+
protected postProcessor(outputs: any, geoRawImage: GeoRawImage): Promise<GeoJSON.FeatureCollection>;
|
|
245
|
+
}
|
|
246
|
+
declare class LandCoverClassification extends BaseModel {
|
|
247
|
+
protected static instance: LandCoverClassification | null;
|
|
248
|
+
private model;
|
|
249
|
+
private classes;
|
|
250
|
+
private colors;
|
|
251
|
+
private constructor();
|
|
252
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
253
|
+
instance: LandCoverClassification;
|
|
254
|
+
}>;
|
|
255
|
+
private preProcessor;
|
|
256
|
+
protected initializeModel(): Promise<void>;
|
|
257
|
+
inference(params: InferenceParams): Promise<any>;
|
|
258
|
+
}
|
|
259
|
+
declare class ObjectDetection extends BaseModel {
|
|
260
|
+
protected static instance: ObjectDetection | null;
|
|
261
|
+
private model;
|
|
262
|
+
private processor;
|
|
263
|
+
private constructor();
|
|
264
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
265
|
+
instance: ObjectDetection;
|
|
266
|
+
}>;
|
|
267
|
+
protected initializeModel(): Promise<void>;
|
|
268
|
+
/**
|
|
269
|
+
* Performs object detection on a geographic area specified by a GeoJSON polygon.
|
|
270
|
+
*
|
|
271
|
+
* @param polygon - A GeoJSON Feature representing the geographic area to analyze
|
|
272
|
+
* @param confidence - Detection confidence threshold between 0 and 1. Detections below this threshold will be filtered out. Defaults to 0.9
|
|
273
|
+
* @returns Promise<ObjectDetectionResults> containing detected objects as GeoJSON features and the raw image used for detection
|
|
274
|
+
* @throws {Error} If data provider, model or processor are not properly initialized
|
|
275
|
+
*/
|
|
276
|
+
inference(params: InferenceParams): Promise<ObjectDetectionResults>;
|
|
277
|
+
}
|
|
278
|
+
declare class OilStorageTankDetection extends BaseModel {
|
|
279
|
+
protected static instance: OilStorageTankDetection | null;
|
|
280
|
+
protected model: ort.InferenceSession | undefined;
|
|
281
|
+
private constructor();
|
|
282
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
283
|
+
instance: OilStorageTankDetection;
|
|
284
|
+
}>;
|
|
285
|
+
protected initializeModel(): Promise<void>;
|
|
286
|
+
protected preProcessor(image: GeoRawImage): Promise<{
|
|
287
|
+
input: ort.Tensor;
|
|
288
|
+
}>;
|
|
289
|
+
inference(params: InferenceParams): Promise<ObjectDetectionResults>;
|
|
290
|
+
protected postProcessor(outputs: any, geoRawImage: GeoRawImage, CONFIDENCE_THRESHOLD?: number, NMS_THRESHOLD?: number): Promise<GeoJSON.FeatureCollection>;
|
|
291
|
+
}
|
|
292
|
+
export interface ConvertPredParams {
|
|
293
|
+
pred_bbox: number[][];
|
|
294
|
+
org_img_shape: [
|
|
295
|
+
number,
|
|
296
|
+
number
|
|
297
|
+
];
|
|
298
|
+
valid_scale: [
|
|
299
|
+
number,
|
|
300
|
+
number
|
|
301
|
+
];
|
|
302
|
+
conf_thresh: number;
|
|
303
|
+
}
|
|
304
|
+
export interface NMSOptions {
|
|
305
|
+
conf_thres?: number;
|
|
306
|
+
iou_thres?: number;
|
|
307
|
+
merge?: boolean;
|
|
308
|
+
classes?: number[];
|
|
309
|
+
multi_label?: boolean;
|
|
310
|
+
agnostic?: boolean;
|
|
311
|
+
without_iouthres?: boolean;
|
|
312
|
+
}
|
|
313
|
+
declare class OrientedObjectDetection extends BaseModel {
|
|
314
|
+
protected static instance: OrientedObjectDetection | null;
|
|
315
|
+
protected model: ort.InferenceSession | undefined;
|
|
316
|
+
protected initialized: boolean;
|
|
317
|
+
protected classes: string[];
|
|
318
|
+
protected constructor(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions);
|
|
319
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
320
|
+
instance: OrientedObjectDetection;
|
|
321
|
+
}>;
|
|
322
|
+
protected preProcessor(image: GeoRawImage): Promise<any>;
|
|
323
|
+
protected initializeModel(): Promise<void>;
|
|
324
|
+
/**
|
|
325
|
+
* Performs object detection on a given geographic polygon.
|
|
326
|
+
* @param polygon - A GeoJSON Feature representing the area for detection
|
|
327
|
+
* @param options - Optional NMS (Non-Maximum Suppression) configuration options
|
|
328
|
+
* @param {NMSOptions} [options={}] - Configuration options for NMS post-processing
|
|
329
|
+
* @returns {Promise<ObjectDetectionResults>} A promise that resolves to the detection results, including the detections array and raw image
|
|
330
|
+
* @throws {Error} If the data provider or model is not properly initialized
|
|
331
|
+
*/
|
|
332
|
+
inference(params: InferenceParams): Promise<ObjectDetectionResults>;
|
|
333
|
+
protected convertPred({ pred_bbox, org_img_shape, valid_scale, conf_thresh, }: ConvertPredParams): number[][];
|
|
334
|
+
/**
|
|
335
|
+
* Performs Rotate-Non-Maximum Suppression (RNMS) on inference results.
|
|
336
|
+
* @param prediction Array of predictions with shape (batch_size, num_boxes, [xywh, score, num_classes, num_angles]).
|
|
337
|
+
* @param conf_thres Confidence threshold.
|
|
338
|
+
* @param iou_thres IoU threshold.
|
|
339
|
+
* @param classes Array of class indices to filter by.
|
|
340
|
+
* @param without_iouthres Whether to skip IoU thresholding.
|
|
341
|
+
* @returns Array of filtered boxes after NMS.
|
|
342
|
+
*/
|
|
343
|
+
protected nonMaxSuppression4Points(prediction: number[][][], { conf_thres, iou_thres, classes, multi_label, without_iouthres, }?: NMSOptions): number[][][];
|
|
344
|
+
/**
|
|
345
|
+
* Polygonal NMS implementation.
|
|
346
|
+
* @param dets Array of polygons with shape (num_detections, [poly]).
|
|
347
|
+
* @param scores Array of confidence scores with shape (num_detections, 1).
|
|
348
|
+
* @param thresh IoU threshold.
|
|
349
|
+
* @returns Array of indices to keep after NMS.
|
|
350
|
+
*/
|
|
351
|
+
protected pyCpuNmsPolyFast(dets: number[][], scores: number[], thresh: number): number[];
|
|
352
|
+
protected postProcessor(outputs: any, geoRawImage: GeoRawImage, options?: NMSOptions): Promise<any>;
|
|
353
|
+
}
|
|
354
|
+
declare class ZeroShotObjectDetection extends BaseModel {
|
|
355
|
+
protected static instance: ZeroShotObjectDetection | null;
|
|
356
|
+
private detector;
|
|
357
|
+
rawDetections: any[];
|
|
358
|
+
protected constructor(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions);
|
|
359
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
360
|
+
instance: ZeroShotObjectDetection;
|
|
361
|
+
}>;
|
|
362
|
+
protected initializeModel(): Promise<void>;
|
|
363
|
+
/**
|
|
364
|
+
* Performs object detection on a geographic area using a zero-shot learning model
|
|
365
|
+
* @param polygon - A GeoJSON Feature representing the geographic area to analyze
|
|
366
|
+
* @param text - Label or array of labels to detect in the image
|
|
367
|
+
* @param options - Detection configuration options
|
|
368
|
+
* @param options.topk - Maximum number of detections to return (default: 4)
|
|
369
|
+
* @param options.threshold - Confidence threshold for detections (default: 0.2)
|
|
370
|
+
* @returns Promise resolving to object detection results containing GeoJSON features and raw image data
|
|
371
|
+
* @throws Error if data provider is not initialized
|
|
372
|
+
*/
|
|
373
|
+
inference(params: InferenceParams): Promise<ObjectDetectionResults>;
|
|
374
|
+
}
|
|
375
|
+
declare class BuildingFootPrintSegmentation extends BaseModel {
|
|
376
|
+
protected static instance: BuildingFootPrintSegmentation | null;
|
|
377
|
+
protected model: ort.InferenceSession | undefined;
|
|
378
|
+
private constructor();
|
|
379
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
380
|
+
instance: BuildingFootPrintSegmentation;
|
|
381
|
+
}>;
|
|
382
|
+
protected initializeModel(): Promise<void>;
|
|
383
|
+
protected preProcessor(rawImage: GeoRawImage): Promise<{
|
|
384
|
+
originalImage: any;
|
|
385
|
+
paddedImage: any;
|
|
386
|
+
patchSize: number;
|
|
387
|
+
}>;
|
|
388
|
+
inference(params: InferenceParams): Promise<ObjectDetectionResults>;
|
|
389
|
+
protected postProcessor(outputs: any, geoRawImage: GeoRawImage, CONFIDENCE_THRESHOLD?: number, minArea?: number): Promise<ObjectDetectionResults>;
|
|
390
|
+
}
|
|
391
|
+
declare class ImageFeatureExtraction extends BaseModel {
|
|
392
|
+
protected static instance: ImageFeatureExtraction | null;
|
|
393
|
+
private extractor;
|
|
394
|
+
private patchSize;
|
|
395
|
+
private constructor();
|
|
396
|
+
static getInstance(model_id: string, providerParams: ProviderParams, modelParams?: PretrainedModelOptions): Promise<{
|
|
397
|
+
instance: ImageFeatureExtraction;
|
|
398
|
+
}>;
|
|
399
|
+
protected initializeModel(): Promise<void>;
|
|
400
|
+
/**
|
|
401
|
+
* Performs image feature extraction on a geographic area specified by a GeoJSON polygon.
|
|
402
|
+
* Extracts dense feature representations using DINOv3 and computes patch-to-patch similarities.
|
|
403
|
+
*
|
|
404
|
+
* @param params - Inference parameters containing polygon and processing options
|
|
405
|
+
* @returns Promise<ImageFeatureExtractionResults> containing feature vectors, similarity matrix, and metadata
|
|
406
|
+
* @throws {Error} If data provider, model or processor are not properly initialized
|
|
407
|
+
*/
|
|
408
|
+
inference(params: InferenceParams): Promise<ImageFeatureExtractionResults>;
|
|
409
|
+
}
|
|
410
|
+
export type MapboxParams = {
|
|
411
|
+
provider: "mapbox";
|
|
412
|
+
apiKey: string;
|
|
413
|
+
style: string;
|
|
414
|
+
};
|
|
415
|
+
export type SentinelParams = {
|
|
416
|
+
provider: "sentinel";
|
|
417
|
+
apiKey: string;
|
|
418
|
+
};
|
|
419
|
+
export type GeobaseParams = {
|
|
420
|
+
provider: "geobase";
|
|
421
|
+
apikey: string;
|
|
422
|
+
cogImagery: string;
|
|
423
|
+
projectRef: string;
|
|
424
|
+
};
|
|
425
|
+
export type EsriParams = {
|
|
426
|
+
provider: "esri";
|
|
427
|
+
serviceUrl?: string;
|
|
428
|
+
serviceName?: string;
|
|
429
|
+
tileSize?: number;
|
|
430
|
+
attribution?: string;
|
|
431
|
+
};
|
|
432
|
+
export interface InferenceInputs {
|
|
433
|
+
polygon: GeoJSON.Feature;
|
|
434
|
+
classLabel?: string;
|
|
435
|
+
[key: string]: unknown;
|
|
436
|
+
}
|
|
437
|
+
export type PostProcessingParams = {
|
|
438
|
+
[key: string]: unknown;
|
|
439
|
+
};
|
|
440
|
+
export interface MapSourceParams {
|
|
441
|
+
zoomLevel?: number;
|
|
442
|
+
bands?: number[];
|
|
443
|
+
expression?: string;
|
|
444
|
+
}
|
|
445
|
+
export interface InferenceParams {
|
|
446
|
+
inputs: InferenceInputs;
|
|
447
|
+
postProcessingParams?: PostProcessingParams;
|
|
448
|
+
mapSourceParams?: MapSourceParams;
|
|
449
|
+
}
|
|
450
|
+
export type ProviderParams = MapboxParams | SentinelParams | GeobaseParams | EsriParams;
|
|
451
|
+
export type HuggingFaceModelTask = "mask-generation" | "zero-shot-object-detection" | "zero-shot-image-classification" | "object-detection" | "oriented-object-detection" | "image-feature-extraction";
|
|
452
|
+
export type GeobaseAiModelTask = "damage-assessment" | "vegetation-classification" | "land-cover-classification" | "land-use-classification" | "land-cover-change-detection" | "land-use-change-detection" | "solar-panel-detection" | "ship-detection" | "car-detection" | "wetland-segmentation" | "building-detection" | "oil-storage-tank-detection" | "building-footprint-segmentation";
|
|
453
|
+
export type ModelInstance = MaskGeneration | ZeroShotObjectDetection | ObjectDetection | OrientedObjectDetection | LandCoverClassification | SolarPanelDetection | ShipDetection | CarDetection | WetLandSegmentation | BuildingDetection | OilStorageTankDetection | BuildingFootPrintSegmentation | ImageFeatureExtraction;
|
|
454
|
+
export type ModelConfig = {
|
|
455
|
+
task: HuggingFaceModelTask | GeobaseAiModelTask;
|
|
456
|
+
library: string;
|
|
457
|
+
description: string;
|
|
458
|
+
examples?: string[];
|
|
459
|
+
geobase_ai_pipeline: (params: ProviderParams, modelId?: string, modelParams?: PretrainedModelOptions) => Promise<{
|
|
460
|
+
instance: ModelInstance;
|
|
461
|
+
}>;
|
|
462
|
+
chainableTasks?: string[];
|
|
463
|
+
ioConfig?: {
|
|
464
|
+
inputs: any;
|
|
465
|
+
outputs: any;
|
|
466
|
+
};
|
|
467
|
+
defaultModelId?: string;
|
|
468
|
+
modelParams?: PretrainedModelOptions;
|
|
469
|
+
};
|
|
470
|
+
export interface SegmentationResults {
|
|
471
|
+
detections: GeoJSON.FeatureCollection;
|
|
472
|
+
masks: GeoJSON.FeatureCollection;
|
|
473
|
+
geoRawImage: GeoRawImage;
|
|
474
|
+
rawDetections: any[];
|
|
475
|
+
}
|
|
476
|
+
export interface ObjectDetectionResults {
|
|
477
|
+
detections: GeoJSON.FeatureCollection;
|
|
478
|
+
geoRawImage: GeoRawImage;
|
|
479
|
+
}
|
|
480
|
+
export interface ImageFeatureExtractionResults {
|
|
481
|
+
features: number[][];
|
|
482
|
+
similarityMatrix: number[][];
|
|
483
|
+
patchSize: number;
|
|
484
|
+
geoRawImage: GeoRawImage;
|
|
485
|
+
metadata: {
|
|
486
|
+
numPatches: number;
|
|
487
|
+
featureDimensions: number;
|
|
488
|
+
modelId: string;
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
export interface ChainInstance {
|
|
492
|
+
inference: (inputs: InferenceParams) => Promise<ObjectDetectionResults | SegmentationResults>;
|
|
493
|
+
}
|
|
494
|
+
export interface TaskConfig {
|
|
495
|
+
task: string;
|
|
496
|
+
modelId?: string;
|
|
497
|
+
modelParams?: PretrainedModelOptions;
|
|
498
|
+
}
|
|
499
|
+
declare class Pipeline {
|
|
500
|
+
/**
|
|
501
|
+
* Builds a dependency graph from modelRegistry chainableTasks
|
|
502
|
+
*/
|
|
503
|
+
private static buildTaskGraph;
|
|
504
|
+
/**
|
|
505
|
+
* Finds all valid task chains using BFS
|
|
506
|
+
*/
|
|
507
|
+
static findValidChains(tasks: string[]): string[][];
|
|
508
|
+
/**
|
|
509
|
+
* Orders tasks in a valid chainable sequence
|
|
510
|
+
*/
|
|
511
|
+
private static orderChainTasks;
|
|
512
|
+
/**
|
|
513
|
+
* Validates and reorders tasks array in-place
|
|
514
|
+
*/
|
|
515
|
+
private static validateChainCompatibility;
|
|
516
|
+
/**
|
|
517
|
+
* Validates input for a specific task
|
|
518
|
+
*/
|
|
519
|
+
private static validateTaskInput;
|
|
520
|
+
/**
|
|
521
|
+
* Creates a pipeline for a single task or a chain of tasks
|
|
522
|
+
* @param taskOrTasks Single task or list of tasks to chain
|
|
523
|
+
* @param providerParams Provider parameters
|
|
524
|
+
* @returns A function that takes inputs and returns the output of the last task in the chain
|
|
525
|
+
*/
|
|
526
|
+
static pipeline(taskOrTasks: TaskConfig[], providerParams: ProviderParams): Promise<ModelInstance | ChainInstance>;
|
|
527
|
+
static listTasks(): string[];
|
|
528
|
+
static listModels(): ModelConfig[];
|
|
529
|
+
}
|
|
530
|
+
export declare const geoai: {
|
|
531
|
+
pipeline: typeof Pipeline.pipeline;
|
|
532
|
+
tasks: typeof Pipeline.listTasks;
|
|
533
|
+
models: typeof Pipeline.listModels;
|
|
534
|
+
validateChain: typeof Pipeline.findValidChains;
|
|
535
|
+
};
|
|
536
|
+
|
|
537
|
+
declare namespace utils {
|
|
538
|
+
export { detectionsToGeoJSON, getPolygonFromMask, maskToGeoJSON, parametersChanged, polygonsEqual, postProcessYoloOutput, refineMasks };
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
export {
|
|
542
|
+
utils,
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
export {};
|