校验上线包.ps1 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. # 宝可梦上线包自检 (card_seg_v0904)
  2. # 用法: D:\顾工交接\wzj\宝可梦\上线\校验上线包.ps1
  3. $ErrorActionPreference = 'Stop'
  4. $Root = Split-Path -Parent $MyInvocation.MyCommand.Path
  5. Set-Location $Root
  6. Write-Host ""
  7. Write-Host "=== 宝可梦上线包自检 · card_seg_v0904 ===" -ForegroundColor Cyan
  8. Write-Host "包路径: $Root"
  9. Write-Host ""
  10. # ---------- 1. MD5 校验 ----------
  11. Write-Host "[1/3] MD5 校验 (对照 MD5SUMS.txt, 基准=249 生产端)" -ForegroundColor Yellow
  12. $sumFile = Join-Path $Root 'MD5SUMS.txt'
  13. if (-not (Test-Path $sumFile)) { Write-Host " X 找不到 MD5SUMS.txt" -ForegroundColor Red; exit 1 }
  14. $ok = 0; $bad = 0; $missing = 0
  15. foreach ($line in (Get-Content -LiteralPath $sumFile -Encoding UTF8)) {
  16. if ($line -notmatch '\S') { continue }
  17. $parts = $line -split '\s+', 2
  18. $want = $parts[0].Trim().ToLower()
  19. $rel = $parts[1].Trim() -replace '/', '\'
  20. $path = Join-Path $Root $rel
  21. if (-not (Test-Path $path)) {
  22. Write-Host (" X 缺失 {0}" -f $rel) -ForegroundColor Red
  23. $missing++; continue
  24. }
  25. $got = (Get-FileHash -Path $path -Algorithm MD5).Hash.ToLower()
  26. $mb = [math]::Round((Get-Item $path).Length / 1MB, 1)
  27. if ($got -eq $want) {
  28. Write-Host (" OK {0,8} MB {1}" -f $mb, $rel) -ForegroundColor Green
  29. $ok++
  30. } else {
  31. Write-Host (" X 不一致 {0}" -f $rel) -ForegroundColor Red
  32. Write-Host (" 期望 {0}" -f $want)
  33. Write-Host (" 实际 {0}" -f $got)
  34. $bad++
  35. }
  36. }
  37. Write-Host (" -> 一致 {0} / 不一致 {1} / 缺失 {2}" -f $ok, $bad, $missing)
  38. Write-Host ""
  39. # ---------- 2. 关键结构 ----------
  40. Write-Host "[2/3] 关键文件与目录" -ForegroundColor Yellow
  41. $must = @(
  42. 'README_上线清单.md',
  43. 'README_操作方法.md',
  44. 'code\build_dual_gallery_v0904.py',
  45. 'code\serve_recognition_api.py',
  46. 'code\serve_card_match_v2.py',
  47. 'code\modules\attribute_detector.py',
  48. 'code\build_dual_gallery_v0904.py',
  49. 'data\gallery_v0904\gallery_dual_meta.json',
  50. 'data\train_meta_v0904.json',
  51. 'code\serve_card_match.py',
  52. 'code\serve_lang_judge.py',
  53. 'code\config.py',
  54. 'code\scripts\cascade_match.py',
  55. 'code\modules\feature_extractor_dual.py',
  56. 'docs\宝可梦卡牌识别服务文档接口.md',
  57. 'offline_cache\huggingface_hub\models--facebook--dinov2-large',
  58. 'offline_cache\paddlex_official_models\PP-OCRv6_medium_rec'
  59. )
  60. $structBad = 0
  61. foreach ($m in $must) {
  62. if (Test-Path (Join-Path $Root $m)) {
  63. Write-Host (" OK {0}" -f $m) -ForegroundColor Green
  64. } else {
  65. Write-Host (" X {0}" -f $m) -ForegroundColor Red
  66. $structBad++
  67. }
  68. }
  69. Write-Host ""
  70. # ---------- 3. 图库形状 ----------
  71. Write-Host "[3/3] 图库特征形状 (npy 头部, 应为 91116 x 1024)" -ForegroundColor Yellow
  72. foreach ($n in @('gallery_v0904/gallery_upper_features.npy', 'gallery_v0904/gallery_lower_features.npy')) {
  73. $p = Join-Path $Root "data\$n"
  74. if (-not (Test-Path $p)) { Write-Host (" X 缺失 {0}" -f $n) -ForegroundColor Red; continue }
  75. $fs = [System.IO.File]::OpenRead($p)
  76. $buf = New-Object byte[] 200
  77. [void]$fs.Read($buf, 0, 200)
  78. $fs.Close()
  79. $head = [System.Text.Encoding]::ASCII.GetString($buf)
  80. if ($head -match "'shape':\s*\(([0-9]+),\s*([0-9]+)\)") {
  81. $rows = $Matches[1]; $cols = $Matches[2]
  82. if ($rows -eq '91116' -and $cols -eq '1024') {
  83. Write-Host (" OK {0} shape=({1}, {2})" -f $n, $rows, $cols) -ForegroundColor Green
  84. } else {
  85. Write-Host (" X {0} shape=({1}, {2}) <- 期望 (91116, 1024), 疑似混版!" -f $n, $rows, $cols) -ForegroundColor Red
  86. $structBad++
  87. }
  88. } else {
  89. Write-Host (" ? {0} 解析不出 shape" -f $n) -ForegroundColor DarkYellow
  90. }
  91. }
  92. Write-Host ""
  93. # ---------- 汇总 ----------
  94. if ($bad -eq 0 -and $missing -eq 0 -and $structBad -eq 0) {
  95. Write-Host "===== 全部通过, 上线包完好 =====" -ForegroundColor Green
  96. Write-Host "下一步: 按 README_上线清单.md 第六节落位, 第七节启动;" -ForegroundColor Gray
  97. Write-Host " /health 的 gallery_size 必须是 91116, 且要再打一个真实请求才算验过。" -ForegroundColor Gray
  98. } else {
  99. Write-Host "===== 有问题, 见上方红色行 =====" -ForegroundColor Red
  100. exit 1
  101. }