更新守护进程
This commit is contained in:
parent
37ce5c746f
commit
7f3036a003
@ -74,6 +74,7 @@ class ImagePreprocessor:
|
|||||||
f"噪声点 {stats['noise_points']} 个"
|
f"噪声点 {stats['noise_points']} 个"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# TODO 过滤算法还需要更新
|
||||||
def filter_points(self) -> pd.DataFrame:
|
def filter_points(self) -> pd.DataFrame:
|
||||||
"""过滤GPS点"""
|
"""过滤GPS点"""
|
||||||
if not self.config.enable_filter:
|
if not self.config.enable_filter:
|
||||||
@ -217,7 +218,7 @@ class ImagePreprocessor:
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# 创建配置
|
# 创建配置
|
||||||
config = PreprocessConfig(
|
config = PreprocessConfig(
|
||||||
image_dir=r"E:\datasets\UAV\283\project\images",
|
image_dir=r"E:\datasets\UAV\502",
|
||||||
output_dir=r"E:\studio2\ODM_pro\test",
|
output_dir=r"E:\studio2\ODM_pro\test",
|
||||||
|
|
||||||
cluster_eps=0.01,
|
cluster_eps=0.01,
|
||||||
@ -238,7 +239,7 @@ if __name__ == "__main__":
|
|||||||
enable_visualization=True,
|
enable_visualization=True,
|
||||||
enable_copy_images=True,
|
enable_copy_images=True,
|
||||||
|
|
||||||
mode="快拼模式",
|
mode="sadf模式",
|
||||||
)
|
)
|
||||||
|
|
||||||
# 创建处理器并执行
|
# 创建处理器并执行
|
||||||
|
@ -36,10 +36,11 @@ i
|
|||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
grid_dir = os.path.join(self.output_dir, f'grid_{grid_idx + 1}')
|
grid_dir = os.path.join(self.output_dir, f'grid_{grid_idx + 1}')
|
||||||
|
grid_dir = grid_dir[0].lower() + grid_dir[1:].replace('\\', '/')
|
||||||
if self.mode == "快拼模式":
|
if self.mode == "快拼模式":
|
||||||
command = f"docker run -ti --rm -v {grid_dir}:/datasets opendronemap/odm --project-path /datasets project --feature-quality lowest --force-gps --use-3dmesh --fast-orthophoto --skip-3dmodel"
|
command = f"docker run -ti --rm -v {grid_dir}:/datasets opendronemap/odm --project-path /datasets project --feature-quality lowest --force-gps --fast-orthophoto --skip-3dmodel"
|
||||||
else:
|
else:
|
||||||
command = f"docker run -ti --rm -v {grid_dir}:/datasets opendronemap/odm --project-path /datasets project --feature-quality lowest --force-gps --use-3dmesh"
|
command = f"docker run -ti --rm -v {grid_dir}:/datasets opendronemap/odm --project-path /datasets project --feature-quality lowest --force-gps"
|
||||||
|
|
||||||
self.logger.info(f"开始执行命令: {command}")
|
self.logger.info(f"开始执行命令: {command}")
|
||||||
success, error_msg = self.monitor.run_odm_with_monitor(
|
success, error_msg = self.monitor.run_odm_with_monitor(
|
||||||
|
@ -5,10 +5,11 @@ import logging
|
|||||||
import subprocess
|
import subprocess
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
|
|
||||||
class ODMProcessMonitor:
|
class ODMProcessMonitor:
|
||||||
"""ODM进程监控器"""
|
"""ODM进程监控器"""
|
||||||
|
|
||||||
def __init__(self, max_retries: int = 3, check_interval: int = 300, mode: str = "快拼模式"):
|
def __init__(self, max_retries: int = 3, check_interval: int = 10, mode: str = "快拼模式"):
|
||||||
"""
|
"""
|
||||||
初始化监控器
|
初始化监控器
|
||||||
|
|
||||||
@ -22,22 +23,28 @@ class ODMProcessMonitor:
|
|||||||
self.logger = logging.getLogger('UAV_Preprocess.ODMMonitor')
|
self.logger = logging.getLogger('UAV_Preprocess.ODMMonitor')
|
||||||
self.mode = mode
|
self.mode = mode
|
||||||
|
|
||||||
def _is_process_running(self, pid: int) -> bool:
|
def _check_docker_container(self, process_name: str = "opendronemap/odm") -> bool:
|
||||||
"""检查进程是否在运行"""
|
"""检查是否有指定的Docker容器在运行"""
|
||||||
try:
|
try:
|
||||||
process = psutil.Process(pid)
|
result = subprocess.run(
|
||||||
return process.is_running()
|
["docker", "ps", "--filter",
|
||||||
except psutil.NoSuchProcess:
|
f"ancestor={process_name}", "--format", "{{.ID}}"],
|
||||||
|
capture_output=True,
|
||||||
|
text=True
|
||||||
|
)
|
||||||
|
return bool(result.stdout.strip())
|
||||||
|
except Exception as e:
|
||||||
|
self.logger.error(f"检查Docker容器状态时发生错误: {str(e)}")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def _check_success(self, grid_dir: str) -> bool:
|
def _check_success(self, grid_dir: str) -> bool:
|
||||||
"""检查ODM是否执行成功"""
|
"""检查ODM是否执行成功"""
|
||||||
# ODM成功完成时会生成这些文件夹
|
|
||||||
if self.mode == "快拼模式":
|
if self.mode == "快拼模式":
|
||||||
success_markers = ['odm_orthophoto', 'odm_georeferencing']
|
success_markers = ['odm_orthophoto', 'odm_georeferencing']
|
||||||
else:
|
else:
|
||||||
success_markers = ['odm_orthophoto', 'odm_georeferencing', 'odm_texturing']
|
success_markers = ['odm_orthophoto',
|
||||||
return all(os.path.exists(os.path.join(grid_dir, marker)) for marker in success_markers)
|
'odm_georeferencing', 'odm_texturing']
|
||||||
|
return all(os.path.exists(os.path.join(grid_dir, 'project', marker)) for marker in success_markers)
|
||||||
|
|
||||||
def run_odm_with_monitor(self, command: str, grid_dir: str, grid_idx: int) -> Tuple[bool, str]:
|
def run_odm_with_monitor(self, command: str, grid_dir: str, grid_idx: int) -> Tuple[bool, str]:
|
||||||
"""
|
"""
|
||||||
@ -66,25 +73,32 @@ class ODMProcessMonitor:
|
|||||||
text=True
|
text=True
|
||||||
)
|
)
|
||||||
|
|
||||||
pid = process.pid
|
self.logger.info("ODM进程已启动,开始监控Docker容器")
|
||||||
self.logger.info(f"ODM进程启动,PID: {pid}")
|
|
||||||
|
|
||||||
# 监控进程
|
# 等待进程启动
|
||||||
|
time.sleep(10)
|
||||||
|
|
||||||
|
# 监控Docker容器
|
||||||
while True:
|
while True:
|
||||||
if not self._is_process_running(pid):
|
if not self._check_docker_container():
|
||||||
# 进程结束,检查是否成功
|
# Docker容器已结束,获取进程输出
|
||||||
stdout, stderr = process.communicate()
|
stdout, stderr = process.communicate()
|
||||||
|
|
||||||
|
time.sleep(10)
|
||||||
# 保存日志
|
# 保存日志
|
||||||
log_file = os.path.join(grid_dir, f'odm_attempt_{attempt + 1}.log')
|
log_file = os.path.join(
|
||||||
|
grid_dir, f'odm_attempt_{attempt + 1}.log')
|
||||||
with open(log_file, 'w', encoding='utf-8') as f:
|
with open(log_file, 'w', encoding='utf-8') as f:
|
||||||
f.write(f"=== 标准输出 ===\n{stdout}\n\n=== 错误输出 ===\n{stderr}")
|
f.write(
|
||||||
|
f"=== 标准输出 ===\n{stdout}\n\n=== 错误输出 ===\n{stderr}")
|
||||||
|
|
||||||
|
# 检查是否成功完成
|
||||||
if self._check_success(grid_dir):
|
if self._check_success(grid_dir):
|
||||||
self.logger.info(f"网格 {grid_idx + 1} ODM处理成功")
|
self.logger.info(f"网格 {grid_idx + 1} ODM处理成功")
|
||||||
return True, ""
|
return True, ""
|
||||||
else:
|
else:
|
||||||
self.logger.warning(f"网格 {grid_idx + 1} 第 {attempt + 1} 次尝试失败")
|
self.logger.warning(
|
||||||
|
f"网格 {grid_idx + 1} 第 {attempt + 1} 次尝试失败")
|
||||||
break
|
break
|
||||||
|
|
||||||
time.sleep(self.check_interval)
|
time.sleep(self.check_interval)
|
||||||
|
Loading…
Reference in New Issue
Block a user