config.py 6.2 KB

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