Skip to main content

oxigdal_ml_foundation/
lib.rs

1//! # OxiGDAL ML Foundation
2//!
3//! Deep learning training infrastructure and model architectures for geospatial machine learning.
4//!
5//! This crate provides:
6//! - Training infrastructure (loops, optimizers, schedulers, losses)
7//! - Transfer learning and fine-tuning capabilities
8//! - Model architectures (UNet, ResNet, custom layers)
9//! - Data augmentation pipelines for geospatial imagery
10//! - Evaluation metrics and monitoring
11//!
12//! ## Features
13//!
14//! - `std` (default): Standard library support
15//! - `pytorch`: PyTorch backend for training (requires libtorch)
16//! - `onnx`: ONNX export support for trained models
17//! - `cuda`: GPU acceleration (requires CUDA)
18//!
19//! ## Architecture
20//!
21//! The crate is organized into several modules:
22//!
23//! - [`training`]: Training loops, optimizers, schedulers, and losses
24//! - [`transfer`]: Transfer learning and fine-tuning
25//! - [`models`]: Neural network architectures
26//! - [`augmentation`]: Data augmentation pipelines
27//! - [`data`]: Data pipeline with dataset loaders and batching
28//! - [`metrics`]: Evaluation metrics
29//!
30//! ## COOLJAPAN Compliance
31//!
32//! - Pure Rust implementation (PyTorch bindings are feature-gated)
33//! - No unwrap() calls in production code
34//! - All files under 2000 lines
35//! - Uses workspace dependencies
36//! - Uses SciRS2-Core for numerical operations (Pure Rust Policy)
37//!
38//! ## Example
39//!
40//! ```rust,no_run
41//! use oxigdal_ml_foundation::{
42//!     training::TrainingConfig,
43//!     training::training_loop::Trainer,
44//!     models::unet::UNet,
45//!     metrics::Metrics,
46//! };
47//!
48//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
49//! // Create a UNet model for segmentation (in_channels=3, num_classes=10, depth=4)
50//! let model = UNet::new(3, 10, 4)?;
51//!
52//! // Configure training
53//! let config = TrainingConfig {
54//!     learning_rate: 0.001,
55//!     batch_size: 16,
56//!     num_epochs: 100,
57//!     ..Default::default()
58//! };
59//!
60//! // Train the model (requires PyTorch feature)
61//! // let trainer = Trainer::new(model, config)?;
62//! // let trained_model = trainer.train(train_data, val_data)?;
63//! # Ok(())
64//! # }
65//! ```
66
67#![cfg_attr(not(feature = "std"), no_std)]
68#![warn(missing_docs)]
69#![warn(clippy::unwrap_used)]
70#![warn(clippy::panic)]
71
72#[cfg(not(feature = "std"))]
73extern crate alloc;
74
75// Re-export key types
76pub use error::{Error, Result};
77
78// Core modules
79pub mod error;
80pub mod metrics;
81
82// Backend abstraction for ML operations
83#[cfg(feature = "ml")]
84pub mod backend;
85
86// Main functionality modules
87pub mod augmentation;
88pub mod data;
89pub mod models;
90pub mod training;
91pub mod transfer;
92
93/// Library version
94pub const VERSION: &str = env!("CARGO_PKG_VERSION");
95
96/// Library name
97pub const NAME: &str = env!("CARGO_PKG_NAME");
98
99/// Checks if PyTorch backend is available
100pub fn has_pytorch_backend() -> bool {
101    cfg!(feature = "ml")
102}
103
104/// Checks if GPU support is available
105pub fn has_gpu_support() -> bool {
106    cfg!(feature = "gpu")
107}
108
109/// Checks if ONNX export is available
110pub fn has_onnx_export() -> bool {
111    cfg!(feature = "onnx")
112}
113
114#[cfg(test)]
115mod tests {
116    use super::*;
117
118    #[test]
119    fn test_version() {
120        assert!(!VERSION.is_empty());
121        assert_eq!(NAME, "oxigdal-ml-foundation");
122    }
123
124    #[test]
125    fn test_feature_detection() {
126        // These should return false in default test configuration
127        // (unless features are explicitly enabled)
128        let _ = has_pytorch_backend();
129        let _ = has_gpu_support();
130        let _ = has_onnx_export();
131    }
132}