config.py 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. from pathlib import Path
  2. from typing import Dict, List
  3. from enum import Enum
  4. # 定义一个模型的配置结构
  5. class CardModelConfig:
  6. pth_path: str
  7. class_dict: dict
  8. img_size: dict
  9. confidence: float
  10. input_channels: int
  11. class Settings:
  12. API_Inference_prefix: str = "/api/card_inference"
  13. API_Score_prefix: str = "/api/card_score"
  14. BASE_PATH = Path(__file__).parent.parent.parent.absolute()
  15. TEMP_WORK_DIR = BASE_PATH / "_temp_work"
  16. SCORE_CONFIG_PATH = BASE_PATH / "app/core/scoring_config.json"
  17. # 图片像素与真实图片缩放比例
  18. PIXEL_RESOLUTION = 24.54
  19. CORNER_SIZE_MM = 3.0
  20. # 使用一个字典来管理所有卡片检测模型
  21. # key (如 'outer_box') 将成为 API 路径中的 {inference_type}
  22. CARD_MODELS_CONFIG: Dict[str, CardModelConfig] = {
  23. "outer_box": {
  24. "pth_path": "Model/outer_box.pth",
  25. "class_dict": {1: 'outer_box'},
  26. "img_size": {'width': 1280, 'height': 1280},
  27. "confidence": 0.5,
  28. "input_channels": 3,
  29. },
  30. "pokemon_front_inner_box": {
  31. "pth_path": "Model/pokemon_front_inner_box.pth",
  32. "class_dict": {1: 'inner_box'},
  33. "img_size": {'width': 1280, 'height': 1280},
  34. "confidence": 0.5,
  35. "input_channels": 3,
  36. },
  37. "pokemon_back_inner_box": {
  38. "pth_path": "Model/pokemon_back_inner_box.pth",
  39. "class_dict": {1: 'inner_box'},
  40. "img_size": {'width': 1280, 'height': 1280},
  41. "confidence": 0.5,
  42. "input_channels": 3,
  43. },
  44. "pokemon_back_corner_defect": {
  45. "pth_path": "Model/pokemon_back_corner_defect.pth",
  46. "class_dict": {
  47. 1: 'wear', 2: 'wear_and_impact', 3: 'impact',
  48. 4: 'damaged', 5: 'wear_and_stain',
  49. },
  50. "img_size": {'width': 512, 'height': 512},
  51. "confidence": 0.5,
  52. "input_channels": 3,
  53. },
  54. "pokemon_back_face_defect": {
  55. "pth_path": "Model/pokemon_back_face_defect.pth",
  56. "class_dict": {"1": "wear", "2": "scratch", "3": "stain",
  57. "4": "scuff", "5": "impact", "6": "damaged",
  58. "7": "wear_and_impact"},
  59. "img_size": {'width': 512, 'height': 512},
  60. "confidence": 0.5,
  61. "input_channels": 3,
  62. },
  63. "pokemon_front_face_reflect_defect": {
  64. "pth_path": "Model/pokemon_front_face_reflect_defect.pth",
  65. "class_dict": {"1": "scratch", "2": "stain", "3": "wear",
  66. "4": "impact", "5": "stain_and_scratch"},
  67. "img_size": {'width': 512, 'height': 512},
  68. "confidence": 0.5,
  69. "input_channels": 3,
  70. },
  71. "pokemon_front_corner_reflect_defect": {
  72. "pth_path": "Model/pokemon_front_corner_reflect_defect.pth",
  73. "class_dict": {"1": "impact", "2": "wear_and_impact", "3": "wear"},
  74. "img_size": {'width': 512, 'height': 512},
  75. "confidence": 0.5,
  76. "input_channels": 3,
  77. },
  78. "pokemon_front_corner_no_reflect_defect": {
  79. "pth_path": "Model/pokemon_front_corner_no_reflect_defect.pth",
  80. "class_dict": {"1": "wear", "2": "wear_and_impact", "3": "impact",
  81. "4": "damaged", "5": "stain"},
  82. "img_size": {'width': 512, 'height': 512},
  83. "confidence": 0.5,
  84. "input_channels": 3,
  85. },
  86. "pokemon_front_face_no_reflect_defect": {
  87. "pth_path": "Model/pokemon_front_face_no_reflect_defect.pth",
  88. "class_dict": {"1": "wear", "2": "scratch", "3": "damaged",
  89. "4": "stain", "5": "impact", "6": "pit"},
  90. "img_size": {'width': 512, 'height': 512},
  91. "confidence": 0.5,
  92. "input_channels": 3,
  93. },
  94. }
  95. # 包含, 环形光居中计算, 环形光正反边角缺陷, 同轴光正反表面缺陷
  96. # 里面存储需要用到的模型类型
  97. DEFECT_TYPE: Dict[str, dict] = {
  98. "pokemon_front_card_center": {
  99. "inner_box": "pokemon_front_inner_box",
  100. "outer_box": "outer_box",
  101. },
  102. "pokemon_back_card_center": {
  103. "inner_box": "pokemon_back_inner_box",
  104. "outer_box": "outer_box",
  105. },
  106. "pokemon_back_face_defect": {
  107. 'model_type': "pokemon_back_face_defect"
  108. },
  109. "pokemon_back_corner_defect": {
  110. 'model_type': "pokemon_back_corner_defect"
  111. },
  112. "pokemon_front_corner_reflect_defect": {
  113. "model_type": "pokemon_front_corner_reflect_defect"
  114. },
  115. "pokemon_front_corner_no_reflect_defect": {
  116. "model_type": "pokemon_front_corner_no_reflect_defect",
  117. },
  118. "pokemon_front_face_no_reflect_defect": {
  119. "model_type": "pokemon_front_face_no_reflect_defect",
  120. }
  121. }
  122. SCORE_TYPE: List[str] = ["front_corner_edge", "front_face",
  123. "back_corner_edge", "back_face"]
  124. settings = Settings()
  125. print(settings.BASE_PATH)
  126. # DefectType = Enum("InferenceType", {name: name for name in settings.DEFECT_TYPE})
  127. # print()