Supprimer le code mort (imports inutilisés, variable _xp, conseil GPU inatteignable)
This commit is contained in:
@ -5,8 +5,6 @@ Handles argument parsing, logging configuration, and entry point.
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import os
|
||||
import shutil
|
||||
import signal
|
||||
import sys
|
||||
|
||||
|
||||
@ -457,7 +457,7 @@ def classify_ground(laz_file, temp_dir, method='auto', force=False, ign_classes=
|
||||
Returns:
|
||||
Path to classified ground LAS file, or None on failure.
|
||||
"""
|
||||
import laspy # noqa: ensure available
|
||||
import laspy
|
||||
|
||||
# Auto-detect method if requested
|
||||
if method == 'auto':
|
||||
|
||||
@ -80,7 +80,6 @@ except Exception:
|
||||
# ---------------------------------------------------------------------------
|
||||
# Lazy CuPy initialization — tries each GPU until one works
|
||||
# ---------------------------------------------------------------------------
|
||||
_xp = np
|
||||
_cp = None
|
||||
_cp_ndimage = None
|
||||
_cupy_ndarray = None # type ref qui survit à disable_gpu() pour que to_cpu() récupère les tableaux orphelins
|
||||
@ -154,7 +153,7 @@ def _init_gpu():
|
||||
import CuPy directly (no subprocess test needed)
|
||||
3. Otherwise: test each GPU in a subprocess, pick the first that works
|
||||
"""
|
||||
global _xp, _cp, _cp_ndimage, _cupy_ndarray, _gpu_initialized, HAS_GPU, _best_gpu_id, _gpu_name, _gpu_mem_gb
|
||||
global _cp, _cp_ndimage, _cupy_ndarray, _gpu_initialized, HAS_GPU, _best_gpu_id, _gpu_name, _gpu_mem_gb
|
||||
if _gpu_initialized:
|
||||
return
|
||||
_gpu_initialized = True
|
||||
@ -165,7 +164,6 @@ def _init_gpu():
|
||||
candidates = _filter_candidates(_runtime_candidates())
|
||||
if not candidates:
|
||||
logger.info("Pas de GPU utilisable — mode CPU uniquement")
|
||||
_xp = np
|
||||
_cp = None
|
||||
_cp_ndimage = None
|
||||
HAS_GPU = False
|
||||
@ -191,14 +189,12 @@ def _init_gpu():
|
||||
_gpu_name = name
|
||||
_gpu_mem_gb = mem_mi // 1024
|
||||
HAS_GPU = True
|
||||
_xp = _real_cupy
|
||||
_cp = _real_cupy
|
||||
_cp_ndimage = _real_cupy_ndimage
|
||||
_cupy_ndarray = _real_cupy.ndarray
|
||||
return
|
||||
except Exception as e:
|
||||
logger.warning(f"GPU indisponible (CUDA_VISIBLE_DEVICES={cuda_visible}): {e}")
|
||||
_xp = np
|
||||
_cp = None
|
||||
_cp_ndimage = None
|
||||
HAS_GPU = False
|
||||
@ -230,7 +226,6 @@ def _init_gpu():
|
||||
|
||||
if _working_gpu is None:
|
||||
logger.info("Pas de GPU utilisable — mode CPU uniquement")
|
||||
_xp = np
|
||||
_cp = None
|
||||
_cp_ndimage = None
|
||||
HAS_GPU = False
|
||||
@ -248,7 +243,6 @@ def _init_gpu():
|
||||
_gpu_name = name
|
||||
_gpu_mem_gb = mem_mi // 1024
|
||||
HAS_GPU = True
|
||||
_xp = _real_cupy
|
||||
_cp = _real_cupy
|
||||
_cp_ndimage = _real_cupy_ndimage
|
||||
_cupy_ndarray = _real_cupy.ndarray
|
||||
@ -444,13 +438,12 @@ def disable_gpu():
|
||||
Libère le memory pool GPU avant de nuller les références (anti-fuite VRAM).
|
||||
Garde _cupy_ndarray vivant pour que to_cpu() récupère les tableaux orphelins.
|
||||
"""
|
||||
global HAS_GPU, _xp, _cp, _cp_ndimage
|
||||
global HAS_GPU, _cp, _cp_ndimage
|
||||
if not HAS_GPU:
|
||||
return
|
||||
logger.warning("GPU désactivé — passage en mode CPU pour la suite du processus")
|
||||
gpu_cleanup()
|
||||
HAS_GPU = False
|
||||
_xp = np
|
||||
_cp = None
|
||||
_cp_ndimage = None
|
||||
|
||||
|
||||
@ -7,7 +7,6 @@ GeoTIFF overlays matching the LiDAR DTM extent.
|
||||
import logging
|
||||
import math
|
||||
import time
|
||||
from pathlib import Path
|
||||
|
||||
import numpy as np
|
||||
import rasterio
|
||||
|
||||
@ -243,7 +243,6 @@ class LidarArchaeoPipeline:
|
||||
needs_generation[name] = not expected_webp.exists()
|
||||
|
||||
to_generate = [n for n, needed in needs_generation.items() if needed]
|
||||
ign_only = all(name in ('ortho', 'topo') for name in to_generate)
|
||||
needs_shared = any(name not in ('ortho', 'topo') for name in to_generate)
|
||||
|
||||
if not to_generate:
|
||||
@ -574,8 +573,6 @@ class LidarArchaeoPipeline:
|
||||
logger.info(f"Traitement parallèle avec {self.workers} workers sur {n_gpus} GPUs...")
|
||||
else:
|
||||
logger.info(f"Traitement parallèle avec {self.workers} workers...")
|
||||
if n_gpus > 1 and self.workers == 1:
|
||||
logger.info(f"Conseil: utilisez -w {n_gpus} pour exploiter tous les GPUs")
|
||||
logger.info(f"Fichiers: {len(files)}")
|
||||
|
||||
with ProcessPoolExecutor(max_workers=self.workers) as executor:
|
||||
@ -624,6 +621,10 @@ class LidarArchaeoPipeline:
|
||||
return
|
||||
else:
|
||||
total = len(files)
|
||||
if self.workers == 1 and len(files) > 1:
|
||||
n_gpus = num_gpus() or 1
|
||||
if n_gpus > 1:
|
||||
logger.info(f"Conseil : utilisez -w {n_gpus} pour exploiter tous les GPUs")
|
||||
for idx, laz_file in enumerate(files, 1):
|
||||
logger.info(f"--- Fichier {idx}/{total} ---")
|
||||
try:
|
||||
|
||||
@ -28,16 +28,9 @@ import matplotlib
|
||||
matplotlib.use('Agg')
|
||||
import matplotlib.pyplot as plt
|
||||
from matplotlib import rcParams
|
||||
from matplotlib.patches import Polygon as MplPolygon, Rectangle as RectPatch, FancyBboxPatch
|
||||
from matplotlib.colors import ListedColormap
|
||||
from matplotlib.patches import Polygon as MplPolygon, Rectangle as RectPatch
|
||||
from matplotlib.ticker import ScalarFormatter
|
||||
|
||||
try:
|
||||
from cmcrameri import cm as cmc
|
||||
HAS_CMCRAmeri = True
|
||||
except ImportError:
|
||||
HAS_CMCRAmeri = False
|
||||
|
||||
rcParams['figure.dpi'] = 150
|
||||
rcParams['savefig.dpi'] = 300
|
||||
rcParams['font.size'] = 10
|
||||
@ -284,8 +277,6 @@ def _download_location_map(min_x, max_x, min_y, max_y):
|
||||
Tuple (image_array, bounds_dict) where bounds_dict has keys
|
||||
'min_x', 'max_x', 'min_y', 'max_y' in Lambert 93, or None on failure.
|
||||
"""
|
||||
import hashlib
|
||||
|
||||
# Cache key based on rounded coordinates (1km grid)
|
||||
cache_key = (round(min_x, -3), round(max_x, -3), round(min_y, -3), round(max_y, -3))
|
||||
if cache_key in _location_map_cache:
|
||||
|
||||
@ -16,7 +16,6 @@ fastapi>=0.110
|
||||
uvicorn>=0.29
|
||||
pydantic>=2.6
|
||||
pyproj>=3.6
|
||||
cmcrameri>=1.8
|
||||
|
||||
# Tests (./run.sh --test)
|
||||
pytest>=7.4
|
||||
|
||||
Reference in New Issue
Block a user