config.py 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. API_ImageData_prefix: str = "/api/image_data"
  15. BASE_PATH = Path(__file__).parent.parent.parent.absolute()
  16. TEMP_WORK_DIR = BASE_PATH / "_temp_work"
  17. DATA_DIR = BASE_PATH / "Data"
  18. SCORE_CONFIG_PATH = BASE_PATH / "app/core/scoring_config.json"
  19. # 图片像素与真实图片缩放比例
  20. PIXEL_RESOLUTION = 24.54
  21. CORNER_SIZE_MM = 3.0
  22. # --- 数据库配置 ---
  23. DB_NAME = 'card_score_database'
  24. DB_TABLE_NAME = 'image_records'
  25. DATABASE_CONFIG: Dict[str, str] = {
  26. 'user': 'root',
  27. 'password': '123456',
  28. 'host': '127.0.0.1',
  29. }
  30. # 连接到指定数据库的配置
  31. DATABASE_CONFIG_WITH_DB: Dict[str, str] = {
  32. **DATABASE_CONFIG,
  33. 'database': DB_NAME
  34. }
  35. # 使用一个字典来管理所有卡片检测模型
  36. # key (如 'outer_box') 将成为 API 路径中的 {inference_type}
  37. '''
  38. face: "1": "wear", "2": "scratch", "3": "stain",
  39. "4": "scuff", "5": "impact", "6": "damaged",
  40. "7": "wear_and_impact"
  41. "8": "stain", "9": "pit"
  42. corner: "1": "wear", "2": "wear_and_impact", "3": "damaged",
  43. "4": "impact", "5": "wear_and_stain"
  44. '''
  45. CARD_MODELS_CONFIG: Dict[str, CardModelConfig] = {
  46. "outer_box": {
  47. "pth_path": "Model/outer_box.pth",
  48. "class_dict": {1: 'outer_box'},
  49. "img_size": {'width': 1280, 'height': 1280},
  50. "confidence": 0.5,
  51. "input_channels": 3,
  52. },
  53. "pokemon_front_inner_box": {
  54. "pth_path": "Model/pokemon_front_inner_box.pth",
  55. "class_dict": {1: 'inner_box'},
  56. "img_size": {'width': 1280, 'height': 1280},
  57. "confidence": 0.5,
  58. "input_channels": 3,
  59. },
  60. "pokemon_back_inner_box": {
  61. "pth_path": "Model/pokemon_back_inner_box.pth",
  62. "class_dict": {1: 'inner_box'},
  63. "img_size": {'width': 1280, 'height': 1280},
  64. "confidence": 0.5,
  65. "input_channels": 3,
  66. },
  67. "pokemon_back_corner_defect": {
  68. "pth_path": "Model/pokemon_back_corner_defect.pth",
  69. "class_dict": {"1": "wear", "2": "wear_and_impact", "3": "damaged",
  70. "4": "impact", "5": "wear_and_stain"},
  71. "img_size": {'width': 512, 'height': 512},
  72. "confidence": 0.5,
  73. "input_channels": 3,
  74. },
  75. "pokemon_back_face_defect": {
  76. "pth_path": "Model/pokemon_back_face_defect.pth",
  77. "class_dict": {"1": "wear", "2": "scratch", "3": "stain",
  78. "4": "scuff", "5": "impact", "6": "damaged",
  79. "7": "wear_and_impact"},
  80. "img_size": {'width': 512, 'height': 512},
  81. "confidence": 0.5,
  82. "input_channels": 3,
  83. },
  84. "pokemon_front_face_reflect_defect": {
  85. "pth_path": "Model/pokemon_front_face_reflect_defect.pth",
  86. "class_dict": {"1": "scratch", "2": "stain", "3": "wear",
  87. "4": "impact", "5": "stain_and_scratch"},
  88. "img_size": {'width': 512, 'height': 512},
  89. "confidence": 0.5,
  90. "input_channels": 3,
  91. },
  92. "pokemon_front_corner_reflect_defect": {
  93. "pth_path": "Model/pokemon_front_corner_reflect_defect.pth",
  94. "class_dict": {"1": "impact", "2": "wear_and_impact", "3": "wear"},
  95. "img_size": {'width': 512, 'height': 512},
  96. "confidence": 0.5,
  97. "input_channels": 3,
  98. },
  99. "pokemon_front_corner_no_reflect_defect": {
  100. "pth_path": "Model/pokemon_front_corner_no_reflect_defect.pth",
  101. "class_dict": {"1": "wear", "2": "wear_and_impact", "3": "impact",
  102. "4": "damaged", "5": "stain"},
  103. "img_size": {'width': 512, 'height': 512},
  104. "confidence": 0.5,
  105. "input_channels": 3,
  106. },
  107. "pokemon_front_face_no_reflect_defect": {
  108. "pth_path": "Model/pokemon_front_face_no_reflect_defect.pth",
  109. "class_dict": {"1": "wear", "2": "scratch", "3": "damaged",
  110. "4": "stain", "5": "impact", "6": "pit"},
  111. "img_size": {'width': 512, 'height': 512},
  112. "confidence": 0.5,
  113. "input_channels": 3,
  114. },
  115. }
  116. # 包含, 环形光居中计算, 环形光正反边角缺陷, 同轴光正反表面缺陷
  117. # 里面存储需要用到的模型类型
  118. DEFECT_TYPE: Dict[str, dict] = {
  119. "pokemon_front_card_center": {
  120. "inner_box": "pokemon_front_inner_box",
  121. "outer_box": "outer_box",
  122. },
  123. "pokemon_back_card_center": {
  124. "inner_box": "pokemon_back_inner_box",
  125. "outer_box": "outer_box",
  126. },
  127. "pokemon_back_face_defect": {
  128. 'model_type': "pokemon_back_face_defect"
  129. },
  130. "pokemon_back_corner_defect": {
  131. 'model_type': "pokemon_back_corner_defect"
  132. },
  133. "pokemon_front_corner_reflect_defect": {
  134. "model_type": "pokemon_front_corner_reflect_defect"
  135. },
  136. "pokemon_front_face_reflect_defect": {
  137. "model_type": "pokemon_front_face_reflect_defect"
  138. },
  139. "pokemon_front_corner_no_reflect_defect": {
  140. "model_type": "pokemon_front_corner_no_reflect_defect",
  141. },
  142. "pokemon_front_face_no_reflect_defect": {
  143. "model_type": "pokemon_front_face_no_reflect_defect",
  144. }
  145. }
  146. SCORE_TYPE: List[str] = ["front_corner_edge", "front_face",
  147. "back_corner_edge", "back_face"]
  148. settings = Settings()
  149. print(f"项目根目录: {settings.BASE_PATH}")
  150. print(f"数据存储目录: {settings.DATA_DIR}")
  151. # DefectType = Enum("InferenceType", {name: name for name in settings.DEFECT_TYPE})
  152. # print()