config.py 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. # 使用一个字典来管理所有卡片检测模型
  22. # key (如 'outer_box') 将成为 API 路径中的 {inference_type}
  23. '''
  24. face: "1": "wear", "2": "scratch", "3": "stain",
  25. "4": "scuff", "5": "impact", "6": "damaged",
  26. "7": "wear_and_impact"
  27. "8": "stain", "9": "pit"
  28. corner: "1": "wear", "2": "wear_and_impact", "3": "damaged",
  29. "4": "impact", "5": "wear_and_stain"
  30. '''
  31. CARD_MODELS_CONFIG: Dict[str, CardModelConfig] = {
  32. "outer_box": {
  33. "pth_path": "Model/outer_box.pth",
  34. "class_dict": {1: 'outer_box'},
  35. "img_size": {'width': 1280, 'height': 1280},
  36. "confidence": 0.5,
  37. "input_channels": 3,
  38. },
  39. "pokemon_front_inner_box": {
  40. "pth_path": "Model/pokemon_front_inner_box.pth",
  41. "class_dict": {1: 'inner_box'},
  42. "img_size": {'width': 1280, 'height': 1280},
  43. "confidence": 0.5,
  44. "input_channels": 3,
  45. },
  46. "pokemon_back_inner_box": {
  47. "pth_path": "Model/pokemon_back_inner_box.pth",
  48. "class_dict": {1: 'inner_box'},
  49. "img_size": {'width': 1280, 'height': 1280},
  50. "confidence": 0.5,
  51. "input_channels": 3,
  52. },
  53. "pokemon_back_corner_defect": {
  54. "pth_path": "Model/pokemon_back_corner_defect.pth",
  55. "class_dict": {"1": "wear", "2": "wear_and_impact", "3": "damaged",
  56. "4": "impact", "5": "wear_and_stain"},
  57. "img_size": {'width': 512, 'height': 512},
  58. "confidence": 0.5,
  59. "input_channels": 3,
  60. },
  61. "pokemon_back_face_defect": {
  62. "pth_path": "Model/pokemon_back_face_defect.pth",
  63. "class_dict": {"1": "wear", "2": "scratch", "3": "stain",
  64. "4": "scuff", "5": "impact", "6": "damaged",
  65. "7": "wear_and_impact"},
  66. "img_size": {'width': 512, 'height': 512},
  67. "confidence": 0.5,
  68. "input_channels": 3,
  69. },
  70. "pokemon_front_face_reflect_defect": {
  71. "pth_path": "Model/pokemon_front_face_reflect_defect.pth",
  72. "class_dict": {"1": "stain", "2": "scratch", "3": "impact", "4": "wear"},
  73. "img_size": {'width': 512, 'height': 512},
  74. "confidence": 0.5,
  75. "input_channels": 3,
  76. },
  77. "pokemon_front_corner_reflect_defect": {
  78. "pth_path": "Model/pokemon_front_corner_reflect_defect.pth",
  79. "class_dict": {"1": "impact", "2": "wear_and_impact", "3": "wear"},
  80. "img_size": {'width': 512, 'height': 512},
  81. "confidence": 0.5,
  82. "input_channels": 3,
  83. },
  84. "pokemon_front_corner_no_reflect_defect": {
  85. "pth_path": "Model/pokemon_front_corner_no_reflect_defect.pth",
  86. "class_dict": {"1": "wear", "2": "wear_and_impact", "3": "impact",
  87. "4": "damaged", "5": "stain"},
  88. "img_size": {'width': 512, 'height': 512},
  89. "confidence": 0.5,
  90. "input_channels": 3,
  91. },
  92. "pokemon_front_face_no_reflect_defect": {
  93. "pth_path": "Model/pokemon_front_face_no_reflect_defect.pth",
  94. "class_dict": {"1": "scratch", "2": "wear", "3": "stain", "4": "damaged",
  95. "5": "impact", "6": "wear_and_impact",
  96. "7": "chip", "8": "protrudent", "9": "wear_and_stain"},
  97. "img_size": {'width': 512, 'height': 512},
  98. "confidence": 0.5,
  99. "input_channels": 3,
  100. },
  101. }
  102. # 包含, 环形光居中计算, 环形光正反边角缺陷, 同轴光正反表面缺陷
  103. # 里面存储需要用到的模型类型
  104. DEFECT_TYPE: Dict[str, dict] = {
  105. "pokemon_front_card_center": {
  106. "inner_box": "pokemon_front_inner_box",
  107. "outer_box": "outer_box",
  108. },
  109. "pokemon_back_card_center": {
  110. "inner_box": "pokemon_back_inner_box",
  111. "outer_box": "outer_box",
  112. },
  113. "pokemon_back_face_defect": {
  114. 'model_type': "pokemon_back_face_defect"
  115. },
  116. "pokemon_back_corner_defect": {
  117. 'model_type': "pokemon_back_corner_defect"
  118. },
  119. "pokemon_front_corner_reflect_defect": {
  120. "model_type": "pokemon_front_corner_reflect_defect"
  121. },
  122. "pokemon_front_face_reflect_defect": {
  123. "model_type": "pokemon_front_face_reflect_defect"
  124. },
  125. "pokemon_front_corner_no_reflect_defect": {
  126. "model_type": "pokemon_front_corner_no_reflect_defect",
  127. },
  128. "pokemon_front_face_no_reflect_defect": {
  129. "model_type": "pokemon_front_face_no_reflect_defect",
  130. }
  131. }
  132. SCORE_TYPE: List[str] = ["front_corner_edge", "front_face",
  133. "back_corner_edge", "back_face"]
  134. settings = Settings()
  135. print(f"项目根目录: {settings.BASE_PATH}")
  136. # DefectType = Enum("InferenceType", {name: name for name in settings.DEFECT_TYPE})
  137. # print()