forked from microsoft/SceneLandmarkLocalization
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocker-run.bat
More file actions
305 lines (275 loc) · 8.67 KB
/
docker-run.bat
File metadata and controls
305 lines (275 loc) · 8.67 KB
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
@echo off
REM 场景地标检测项目 Docker 运行脚本 (Windows版本)
REM 使用方法: docker-run.bat [命令] [参数]
setlocal enabledelayedexpansion
REM 设置颜色代码
set "RED=[91m"
set "GREEN=[92m"
set "YELLOW=[93m"
set "BLUE=[94m"
set "NC=[0m"
REM 打印带颜色的消息
:print_info
echo %BLUE%[INFO]%NC% %~1
goto :eof
:print_success
echo %GREEN%[SUCCESS]%NC% %~1
goto :eof
:print_warning
echo %YELLOW%[WARNING]%NC% %~1
goto :eof
:print_error
echo %RED%[ERROR]%NC% %~1
goto :eof
REM 检查Docker是否安装
:check_docker
docker --version >nul 2>&1
if errorlevel 1 (
call :print_error "Docker 未安装,请先安装 Docker Desktop"
exit /b 1
)
docker-compose --version >nul 2>&1
if errorlevel 1 (
call :print_error "Docker Compose 未安装,请先安装 Docker Compose"
exit /b 1
)
goto :eof
REM 构建基础镜像
:build_base
call :print_info "构建基础镜像..."
docker-compose build --no-cache base_build
if errorlevel 1 (
call :print_error "基础镜像构建失败"
exit /b 1
)
call :print_success "基础镜像构建完成"
goto :eof
REM 构建训练镜像
:build_image
call :print_info "构建训练镜像..."
docker-compose build --no-cache scene-landmark-detection
if errorlevel 1 (
call :print_error "训练镜像构建失败"
exit /b 1
)
call :print_success "训练镜像构建完成"
goto :eof
REM 构建API镜像
:build_api_image
call :print_info "构建API镜像..."
docker-compose build --no-cache api
if errorlevel 1 (
call :print_error "API镜像构建失败"
exit /b 1
)
call :print_success "API镜像构建完成"
goto :eof
REM 构建所有镜像
:build_all
call :print_info "构建所有镜像..."
docker-compose build --no-cache
if errorlevel 1 (
call :print_error "镜像构建失败"
exit /b 1
)
call :print_info "构建API镜像..."
docker-compose build --no-cache api
if errorlevel 1 (
call :print_error "API镜像构建失败"
exit /b 1
)
call :print_success "所有镜像构建完成"
goto :eof
REM 运行交互式容器
:run_interactive
call :print_info "启动交互式容器..."
docker-compose run --rm scene-landmark-detection bash
goto :eof
REM 运行自定义命令
:run_custom
call :print_info "运行自定义命令: %*"
docker-compose run --rm scene-landmark-detection python /app/src/main.py %*
goto :eof
REM 运行API服务(生产环境)
:run_api
call :print_info "启动API服务(生产环境)..."
docker-compose --profile api up api
goto :eof
REM 运行API服务(生产环境,后台)
:run_api_daemon
call :print_info "启动API服务(生产环境,后台模式)..."
docker-compose --profile api up -d api
call :print_success "API服务已在后台启动"
call :print_info "等待服务启动..."
timeout /t 15 /nobreak >nul
call :print_info "API服务信息:"
call :print_info " - Nginx端口: http://localhost:8081"
call :print_info " - Flask端口: http://localhost:8080"
call :print_info " - 健康检查: GET http://localhost:8081/nginx-health"
call :print_info " - API文档:"
call :print_info " - 健康检查: GET http://localhost:8081/health"
call :print_info " - 获取场景: GET http://localhost:8081/scenes"
call :print_info " - 场景信息: GET http://localhost:8081/scene/^<scene_name^>/info"
call :print_info " - 室内定位: POST http://localhost:8081/localize"
goto :eof
REM 停止API服务
:stop_api
call :print_info "停止API服务..."
docker-compose --profile api down
call :print_success "API服务已停止"
goto :eof
REM 检查API状态
:check_api_status
call :print_info "检查API服务状态..."
docker ps | findstr "scene-landmark-api" >nul
if not errorlevel 1 (
call :print_success "API服务正在运行"
call :print_info "尝试访问健康检查接口..."
curl -s http://localhost:8081/nginx-health >nul 2>&1
if not errorlevel 1 (
call :print_success "Nginx服务响应正常"
curl -s http://localhost:8081/health >nul 2>&1
if not errorlevel 1 (
call :print_success "API服务响应正常"
curl -s http://localhost:8081/health | python3 -m json.tool
) else (
call :print_warning "API服务无响应"
)
) else (
call :print_warning "Nginx服务无响应"
)
) else (
call :print_warning "API服务未运行"
)
goto :eof
REM 查看API日志
:view_api_logs
call :print_info "查看API服务日志..."
docker ps | findstr "scene-landmark-api" >nul
if not errorlevel 1 (
docker logs scene-landmark-api
) else (
call :print_warning "API服务未运行"
)
goto :eof
REM 运行快速测试
:run_quick_test
call :print_info "运行快速测试..."
call :print_warning "注意:此命令需要先运行训练生成模型文件,或者使用 custom 命令指定预训练模型路径"
call :print_info "建议先运行: %0 quick_train"
call :print_info "或者使用: %0 custom --action test --pretrained_model /path/to/model.ckpt ..."
docker-compose run --rm scene-landmark-detection python /app/src/main.py ^
--action test ^
--dataset_folder /app/data/indoor6 ^
--output_folder /app/data/outputs ^
--scene_id scene6 ^
--landmark_config landmarks/landmarks-100v9 ^
--visibility_config landmarks/visibility-100v9_depth_normal ^
--landmark_indices 0 ^
--landmark_indices 100 ^
--pretrained_model /app/data/outputs/model-best_median.ckpt ^
--training_batch_size 4
goto :eof
REM 运行快速训练
:run_quick_train
call :print_info "运行快速训练..."
docker-compose run --rm scene-landmark-detection python /app/src/main.py ^
--action train ^
--dataset_folder /app/data/indoor6 ^
--output_folder /app/data/outputs ^
--scene_id scene6 ^
--landmark_config landmarks/landmarks-100v9 ^
--visibility_config landmarks/visibility-100v9_depth_normal ^
--landmark_indices 0 ^
--landmark_indices 100 ^
--num_epochs 10 ^
--training_batch_size 4
goto :eof
REM 显示帮助信息
:show_help
echo 场景地标检测项目 Docker 运行脚本 ^(Windows版本^)
echo.
echo 使用方法:
echo %0 [命令] [参数]
echo.
echo 镜像构建:
echo build_base 构建基础镜像
echo build 构建训练镜像
echo build_api 构建API镜像
echo build_all 构建所有镜像(包括API镜像)
echo.
echo 训练和测试:
echo quick_train 运行快速训练(100个地标,10轮)
echo quick_test 运行快速测试(100个地标)
echo.
echo API服务:
echo api 启动API服务(生产环境)
echo api_daemon 启动API服务(生产环境,后台模式)
echo stop_api 停止API服务
echo api_status 检查API服务状态
echo api_logs 查看API服务日志
echo.
echo 开发环境:
echo interactive 启动交互式容器
echo custom ^<命令^> 运行自定义命令
echo.
echo 维护:
echo help 显示此帮助信息
echo.
echo 示例:
echo %0 build_all
echo %0 quick_train
echo %0 quick_test
echo %0 api_daemon # 启动API服务
echo %0 api_status # 检查API状态
echo %0 api_logs # 查看API日志
echo %0 custom --action test --dataset_folder /app/data/indoor6 --scene_id scene6
echo %0 interactive
echo.
echo API接口:
echo - 健康检查: GET http://localhost:8081/health
echo - 获取场景: GET http://localhost:8081/scenes
echo - 场景信息: GET http://localhost:8081/scene/^<scene_name^>/info
echo - 室内定位: POST http://localhost:8081/localize
echo.
echo 数据集路径: /app/data/indoor6
echo 可用场景: scene1, scene2a, scene3, scene4a, scene5, scene6
echo 可用地标配置: landmarks-100v9, landmarks-300v9, landmarks-500v9, landmarks-1000v9
echo.
echo Docker Compose Profiles:
echo - api: API生产环境
echo.
echo 多阶段构建:
echo - base_build: 基础镜像(PyTorch + 依赖)
echo - main: 训练镜像(基础镜像 + 训练工具)
echo - api: API镜像(基础镜像 + API服务)
goto :eof
REM 主函数
:main
call :check_docker
if errorlevel 1 exit /b 1
if "%1"=="" goto :show_help
if "%1"=="build_base" goto :build_base
if "%1"=="build" goto :build_image
if "%1"=="build_api" goto :build_api_image
if "%1"=="build_all" goto :build_all
if "%1"=="quick_train" goto :run_quick_train
if "%1"=="quick_test" goto :run_quick_test
if "%1"=="interactive" goto :run_interactive
if "%1"=="custom" (
shift
goto :run_custom
)
if "%1"=="api" goto :run_api
if "%1"=="api_daemon" goto :run_api_daemon
if "%1"=="stop_api" goto :stop_api
if "%1"=="api_status" goto :check_api_status
if "%1"=="api_logs" goto :view_api_logs
if "%1"=="help" goto :show_help
if "%1"=="-h" goto :show_help
if "%1"=="--help" goto :show_help
call :print_error "未知命令: %1"
call :show_help
exit /b 1
REM 运行主函数
call :main %*