Fix gin config loading + source filter, docs updates
- config_loader: add base_gin_files() to exclude dataset-specific pipeline_*.gin variants from default `python -m src.main` load (pipeline_uav_visloc.gin was overriding pipeline.gin) - main.py: use base_gin_files() in the --gin override branch too - pipeline.gin: source None (both DB + query) — was 'query', which silently dropped all DB satellite crops from discovery - README/CLAUDE/docs: sync source default, tensor format spec Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
46
README.md
46
README.md
@@ -44,7 +44,9 @@ python -m pytest src/tests/ -v
|
||||
│ │ ├── models.gin # Model IDs, weights_dir
|
||||
│ │ ├── hardware.gin # GPU profile, batch_size (None=auto), FP16
|
||||
│ │ ├── segmentation.gin # 11 промптов, threshold=0.15
|
||||
│ │ └── input.gin # image_size (256)
|
||||
│ │ ├── input.gin # image_size (256)
|
||||
│ │ └── pipeline_*.gin # Датасет-специфичные оверрайды (напр. pipeline_uav_visloc.gin);
|
||||
│ │ # НЕ подгружаются `python -m src.main` — только своими скриптами
|
||||
│ └── weights/ # Веса моделей (не в git, >50MB)
|
||||
│ ├── models--depth-anything--DA3-LARGE-1.1/
|
||||
│ ├── sam3.1/sam3.1_multiplex.pt
|
||||
@@ -106,7 +108,7 @@ PipelineConfig.save_safetensors = True # True = .safetensors (для обу
|
||||
PipelineConfig.cleanup_npy = False # True = удалить .npy после консолидации
|
||||
PipelineConfig.resume = True # Пропускать уже обработанные
|
||||
PipelineConfig.subset = None # None=все, 'Rot', 'Country', 'Terrain'
|
||||
PipelineConfig.source = 'db' # 'db' = спутник, 'query' = БПЛА, None = оба
|
||||
PipelineConfig.source = None # None = оба (по умолчанию), 'db' = спутник, 'query' = БПЛА
|
||||
```
|
||||
|
||||
### segmentation.gin (unified 17 классов)
|
||||
@@ -194,14 +196,16 @@ World-UAV-aug/
|
||||
|
||||
### SafeTensors (рекомендуемый формат для обучения)
|
||||
|
||||
Один `.safetensors` файл на изображение, содержит все модальности:
|
||||
Один `.safetensors` файл на изображение, содержит все модальности как **dense spatial maps [1, H, W]** — финальные predictions моделей, не промежуточные feature maps. Подробная спецификация: [docs/tensor_format_spec.md](docs/tensor_format_spec.md).
|
||||
|
||||
| Ключ | Dtype | Shape | Описание |
|
||||
|:---|:---|:---|:---|
|
||||
| `depth` | float16 | [1, H, W] | Dense depth map, непрерывная [0, 1], per-frame normalized |
|
||||
| `edge` | float16 | [1, H, W] | Dense edge map (Sobel magnitude), [0, 1] |
|
||||
| `chm` | float16 | [1, H, W] | Dense canopy height map, [0, 1], per-frame normalized |
|
||||
| `segm` | uint8 | [1, H, W] | Dense class ID map, значения [0, 16] (17 unified классов) |
|
||||
| Ключ | Dtype | Shape | Описание | Модель |
|
||||
|:---|:---|:---|:---|:---|
|
||||
| `depth` | float16 | [1, H, W] | Relative depth, [0, 1], per-frame min-max normalized | DA3-LARGE-1.1 (DinoV2-ViTL) |
|
||||
| `edge` | float16 | [1, H, W] | Sobel magnitude из depth, [0, 1], per-frame max normalized | Sobel (CPU) |
|
||||
| `chm` | float16 | [1, H, W] | Relative canopy height, [0, 1], per-frame min-max normalized | DINOv3-ViTL16 CHMv2 |
|
||||
| `segm` | uint8 | [1, H, W] | Dense class ID map (argmax), значения [0, 16] (17 классов) | SegEarth-OV3 (ViTDet-32L) |
|
||||
|
||||
**Что НЕ сохраняется:** backbone features (ViT tokens), soft probabilities/logits сегментации, абсолютные значения глубины/высоты в метрах, text embeddings промптов, направление градиента (только magnitude).
|
||||
|
||||
Преимущества SafeTensors:
|
||||
- **Zero-copy mmap** -- тензор читается прямо с диска без копирования в RAM (~0.1ms)
|
||||
@@ -242,7 +246,7 @@ World-UAV-aug/
|
||||
|
||||
## Использование для обучения
|
||||
|
||||
Все модальности хранятся как **dense tensor maps** — прямые тензоры, не RGB-рендеры. Это ключевое решение (см. [dialog_fusion_modalities](docs/segmentation_class_analysis.md)): тензоры сохраняют полную информацию без потерь при квантовании/colormapping и не являются OOD-входом для DINOv3.
|
||||
Все модальности хранятся как **dense spatial maps [1, H, W]** — финальные predictions моделей, не RGB-рендеры и не промежуточные feature maps. Тензоры сохраняют полную информацию без потерь при квантовании/colormapping и не являются OOD-входом для DINOv3. Полная спецификация форматов: [docs/tensor_format_spec.md](docs/tensor_format_spec.md).
|
||||
|
||||
### SafeTensors (рекомендуемый способ)
|
||||
|
||||
@@ -254,33 +258,37 @@ import torch.nn.functional as F
|
||||
data = load_file("World-UAV-aug/safetensors/Rot/.../crop_12_4.safetensors")
|
||||
|
||||
# Все модальности — dense spatial maps, готовые для injection в backbone
|
||||
depth = data["depth"] # [1, H, W] float16, непрерывная глубина [0, 1]
|
||||
edge = data["edge"] # [1, H, W] float16, Sobel magnitude [0, 1]
|
||||
chm = data["chm"] # [1, H, W] float16, canopy height [0, 1]
|
||||
segm = data["segm"] # [1, H, W] uint8, dense class ID map [0, 16]
|
||||
depth = data["depth"] # [1, H, W] float16, relative depth [0, 1], per-frame min-max
|
||||
edge = data["edge"] # [1, H, W] float16, Sobel magnitude [0, 1], per-frame max
|
||||
chm = data["chm"] # [1, H, W] float16, relative canopy height [0, 1], per-frame min-max
|
||||
segm = data["segm"] # [1, H, W] uint8, class IDs (argmax) [0, 16], no normalization
|
||||
```
|
||||
|
||||
### Подача в Teacher NADEZHDA
|
||||
|
||||
Каждая модальность подаётся в свой lightweight aux-encoder, затем через FiLM/Conv1x1 injection в DINOv3 patch tokens:
|
||||
Каждая модальность подаётся в свой lightweight aux-encoder, затем через FiLM injection в DINOv3 patch tokens:
|
||||
|
||||
```python
|
||||
# Depth / Edge / CHM → [B, 1, H, W] float → Conv aux-encoder → FiLM injection
|
||||
# Прямые тензоры, НЕ RGB-рендеры (turbo colormap = потеря 70% информации + OOD)
|
||||
# Все три уже в [0, 1] — рекомендуемый FiLM init: gamma=1, beta=0 (identity)
|
||||
aux_depth = depth_encoder(depth.float()) # [1, H, W] → [C, H, W]
|
||||
aux_edge = edge_encoder(edge.float())
|
||||
aux_chm = chm_encoder(chm.float())
|
||||
|
||||
# Segmentation → dense class ID map → per-class embedding → spatial feature map
|
||||
# Вариант 1: one-hot → Conv
|
||||
# Segmentation → dense class ID map → embedding → spatial feature map
|
||||
# Вариант 1: one-hot → Conv (deterministic init, explicit)
|
||||
segm_onehot = F.one_hot(segm.long().squeeze(0), num_classes=17) # [H, W, 17]
|
||||
segm_features = seg_conv(segm_onehot.permute(2, 0, 1).float()) # [17, H, W] → [C, H, W]
|
||||
|
||||
# Вариант 2: learned per-class embedding (SegAuxEncoder)
|
||||
# Вариант 2: learned per-class embedding (компактнее)
|
||||
# seg_emb = nn.Embedding(17, 32)
|
||||
# segm_features = seg_emb(segm.long().squeeze(0)).permute(2, 0, 1) # [H, W] → [32, H, W]
|
||||
```
|
||||
|
||||
### Нормирование входных тензоров
|
||||
|
||||
Depth, edge, chm уже per-frame normalized в [0, 1]. Для FiLM init `gamma=1, beta=0` (identity) — безопасный старт. При необходимости dataset-level статистики — пройти по subset (1K-5K изображений) для running mean/std. Segmentation (uint8 class IDs) требует embedding перед FiLM — нельзя подавать как continuous input.
|
||||
|
||||
### Почему тензоры, а не RGB-рендеры
|
||||
|
||||
| Формат | Пример depth | Потеря информации | Для DINOv3 |
|
||||
|
||||
Reference in New Issue
Block a user