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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
//! OxiGDAL ML - Machine Learning for Geospatial Data
//!
//! This crate provides machine learning capabilities for the OxiGDAL ecosystem,
//! enabling geospatial ML workflows with ONNX Runtime integration.
//!
//! # Features
//!
//! - **ONNX Runtime Integration**: Pure Rust interface to ONNX Runtime for model inference
//! - **Image Segmentation**: Semantic, instance, and panoptic segmentation
//! - **Image Classification**: Scene classification, land cover classification, multi-label
//! - **Object Detection**: Bounding box detection with NMS and georeferencing
//! - **Preprocessing**: Normalization, tiling, padding, and augmentation
//! - **Postprocessing**: Tile merging, thresholding, polygon conversion, GeoJSON export
//!
//! # Optional Features
//!
//! - `gpu` - Enable CUDA and TensorRT GPU acceleration
//! - `directml` - Enable DirectML support (Windows)
//! - `coreml` - Enable CoreML support (macOS/iOS)
//!
//! # Example: Image Segmentation
//!
//! ```ignore
//! use oxigdal_ml::*;
//! use oxigdal_ml::models::OnnxModel;
//! use oxigdal_ml::inference::{InferenceEngine, InferenceConfig};
//! use oxigdal_ml::segmentation::probability_to_mask;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Load ONNX model
//! let model = OnnxModel::from_file("segmentation.onnx")?;
//!
//! // Create inference engine
//! let config = InferenceConfig::default();
//! let engine = InferenceEngine::new(model, config);
//!
//! // Load input raster (not shown)
//! # use oxigdal_core::buffer::RasterBuffer;
//! # use oxigdal_core::types::RasterDataType;
//! # let input = RasterBuffer::zeros(256, 256, RasterDataType::Float32);
//!
//! // Run inference
//! let predictions = engine.predict(&input)?;
//!
//! // Convert to segmentation mask
//! let mask = probability_to_mask(&predictions, 2, 0.5)?;
//! # Ok(())
//! # }
//! ```
//!
//! # Example: Object Detection
//!
//! ```ignore
//! use oxigdal_ml::*;
//! use oxigdal_ml::detection::{non_maximum_suppression, NmsConfig};
//! use oxigdal_ml::postprocessing::export_detections_geojson;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Assume we have detections from a model
//! # let detections = vec![];
//!
//! // Apply NMS to filter overlapping detections
//! let config = NmsConfig::default();
//! let filtered = non_maximum_suppression(&detections, &config)?;
//!
//! // Export to GeoJSON
//! # let geo_detections = vec![];
//! # export_detections_geojson(&geo_detections, "detections.geojson")?;
//! # Ok(())
//! # }
//! ```
//!
//! # Example: Batch Processing with Progress Tracking
//!
//! ```ignore
//! use oxigdal_ml::*;
//! use oxigdal_ml::batch::{BatchConfig, BatchProcessor};
//! use oxigdal_ml::models::OnnxModel;
//! # use oxigdal_core::buffer::RasterBuffer;
//! # use oxigdal_core::types::RasterDataType;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Load model
//! let model = OnnxModel::from_file("model.onnx")?;
//!
//! // Auto-tune batch size based on available memory
//! let sample_size = 3 * 256 * 256 * 4; // 3 channels, 256x256, float32
//! let batch_size = BatchConfig::auto_tune_batch_size(sample_size, 0.5);
//!
//! // Create batch processor
//! let config = BatchConfig::builder()
//! .max_batch_size(batch_size)
//! .parallel_batches(4)
//! .build();
//!
//! let processor = BatchProcessor::new(model, config);
//!
//! // Process large batch with progress bar
//! # let inputs: Vec<RasterBuffer> = vec![];
//! let results = processor.infer_batch_with_progress(inputs, true)?;
//! # Ok(())
//! # }
//! ```
//!
//! # Example: Model Optimization Pipeline
//!
//! ```ignore
//! use oxigdal_ml::*;
//! use oxigdal_ml::optimization::{OptimizationPipeline, OptimizationProfile};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create optimization pipeline for edge deployment
//! let pipeline = OptimizationPipeline::from_profile(OptimizationProfile::Size);
//!
//! // Optimize model (applies quantization + pruning)
//! let stats = pipeline.optimize("model.onnx", "model_optimized.onnx")?;
//!
//! println!("Size reduction: {:.1}%", stats.size_reduction_percent());
//! println!("Speedup: {:.2}x", stats.speedup);
//! println!("Accuracy delta: {:.2}%", stats.accuracy_delta);
//! # Ok(())
//! # }
//! ```
//!
//! # Example: Model Zoo - Download Pretrained Models
//!
//! ```ignore
//! use oxigdal_ml::*;
//! use oxigdal_ml::zoo::ModelZoo;
//! use oxigdal_ml::models::OnnxModel;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create model zoo
//! let mut zoo = ModelZoo::new()?;
//!
//! // List available models
//! let models = zoo.list_models();
//! for model in models {
//! println!("{}: {} - {:.1}% accuracy",
//! model.name, model.description,
//! model.accuracy.unwrap_or(0.0));
//! }
//!
//! // Download a model (with progress bar and checksum verification)
//! let model_path = zoo.get_model("unet_buildings")?;
//!
//! // Load and use the model
//! let model = OnnxModel::from_file(model_path)?;
//! # Ok(())
//! # }
//! ```
//!
//! # Example: Transfer Learning
//!
//! ```no_run
//! use oxigdal_ml::*;
//! # #[cfg(feature = "temporal")]
//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
//! // This example requires oxigdal-ml-foundation
//! // Load pretrained feature extractor
//! use oxigdal_ml_foundation::transfer::FeatureExtractor;
//!
//! // Extract features from pretrained model
//! let extractor = FeatureExtractor::from_pretrained("resnet50")?;
//!
//! // Use features for custom classification task
//! // (Training loop implementation would go here)
//! # Ok(())
//! # }
//! ```
//!
//! # Example: GPU Acceleration
//!
//! ```ignore
//! use oxigdal_ml::*;
//! use oxigdal_ml::gpu::{GpuBackend, GpuConfig};
//! use oxigdal_ml::inference::{InferenceEngine, InferenceConfig};
//! use oxigdal_ml::models::OnnxModel;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Detect available GPU backends
//! let backends = GpuBackend::detect_all();
//! for backend in &backends {
//! println!("Available: {:?}", backend);
//! }
//!
//! // Configure GPU acceleration
//! let gpu_config = GpuConfig::builder()
//! .preferred_backend(GpuBackend::Cuda)
//! .device_id(0)
//! .build();
//!
//! // Create inference engine with GPU support
//! let model = OnnxModel::from_file("model.onnx")?;
//! let mut inference_config = InferenceConfig::default();
//! inference_config.gpu_config = Some(gpu_config);
//!
//! let engine = InferenceEngine::new(model, inference_config);
//! # Ok(())
//! # }
//! ```
//!
//! # Example: Model Monitoring
//!
//! ```ignore
//! use oxigdal_ml::*;
//! use oxigdal_ml::monitoring::{ModelMonitor, MonitoringConfig};
//! use oxigdal_ml::models::OnnxModel;
//! # use oxigdal_core::buffer::RasterBuffer;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! let model = OnnxModel::from_file("model.onnx")?;
//!
//! // Create monitor with custom config
//! let config = MonitoringConfig::builder()
//! .track_latency(true)
//! .track_memory(true)
//! .alert_threshold_ms(100.0)
//! .build();
//!
//! let mut monitor = ModelMonitor::new(model, config);
//!
//! // Run inference with monitoring
//! # let input = RasterBuffer::zeros(256, 256, oxigdal_core::types::RasterDataType::Float32);
//! let result = monitor.predict(&input)?;
//!
//! // Check metrics
//! let metrics = monitor.metrics();
//! println!("Avg latency: {:.2}ms", metrics.avg_latency_ms());
//! println!("Memory usage: {:.1}MB", metrics.peak_memory_mb);
//! # Ok(())
//! # }
//! ```
//!
//! # SciRS2 Integration Status
//!
//! This crate is being migrated to use the Pure Rust SciRS2 ecosystem following
//! COOLJAPAN policy. Current status:
//!
//! - **Random Number Generation**: Completed - using `scirs2-core::random` for RNG
//! - **Statistical Distributions**: Completed - using `NormalDistribution` for Gaussian noise
//! - **Data Augmentation**: Completed - integrated SciRS2-Core RNG
//! - **Linear Algebra**: Partial - `ndarray` still used in some modules, migration ongoing
//! - **Neural Network Training**: In Progress - `oxigdal-ml-foundation` implements custom
//! Pure Rust backend with SciRS2 integration
//!
//! ## Usage Example with SciRS2
//!
//! ```no_run
//! use oxigdal_ml::augmentation::{add_gaussian_noise, random_crop};
//! # use oxigdal_core::buffer::RasterBuffer;
//! # use oxigdal_core::types::RasterDataType;
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Create a raster buffer
//! let input = RasterBuffer::zeros(512, 512, RasterDataType::Float32);
//!
//! // Add Gaussian noise using SciRS2-Core
//! let noisy = add_gaussian_noise(&input, 0.01)?;
//!
//! // Random crop using SciRS2-Core RNG
//! let cropped = random_crop(&input, 256, 256)?;
//! # Ok(())
//! # }
//! ```
//!
//! For more information about SciRS2 integration, see the SCIRS2 POLICY in the
//! workspace documentation.
// Pedantic disabled to reduce noise - default clippy::all is sufficient
// #![warn(clippy::pedantic)]
// Allow unused imports in feature-gated modules
// Allow dead code for ML model structures
// Allow collapsible match for ML result handling
// Allow expect() for model loading invariants
// Allow for loop with idx for tensor operations
// Allow manual div_ceil for batch calculations
// Allow field assignment outside initializer for ML configs
// Allow unexpected cfg for temporarily disabled features
// Re-export commonly used items
pub use AugmentationConfig;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ModelZoo;
/// Crate version
pub const VERSION: &str = env!;
/// Crate name
pub const NAME: &str = env!;