config.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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_prefix: str = "/api/card_inference"
  13. BASE_PATH = Path(__file__).parent.parent.parent.absolute()
  14. TEMP_WORK_DIR = BASE_PATH / "_temp_work"
  15. # 图片像素与真实图片缩放比例
  16. PIXEL_RESOLUTION = 24.54
  17. CORNER_SIZE_MM = 3.0
  18. # 使用一个字典来管理所有卡片检测模型
  19. # key (如 'outer_box') 将成为 API 路径中的 {inference_type}
  20. CARD_MODELS_CONFIG: Dict[str, CardModelConfig] = {
  21. "pokemon_outer_box": {
  22. "pth_path": "Model/pokemon_outer_box.pth",
  23. "class_dict": {1: 'outer_box'},
  24. "img_size": {'width': 1280, 'height': 1280},
  25. "confidence": 0.5,
  26. "input_channels": 3,
  27. },
  28. "pokemon_inner_box": {
  29. "pth_path": "Model/pokemon_inner_box.pth",
  30. "class_dict": {1: 'inner_box'},
  31. "img_size": {'width': 1280, 'height': 1280},
  32. "confidence": 0.5,
  33. "input_channels": 3,
  34. },
  35. "pokemon_back_corner_defect": {
  36. "pth_path": "Model/pokemon_back_corner_defect.pth",
  37. "class_dict": {
  38. 1: 'wear', 2: 'wear_and_impact', 3: 'impact',
  39. 4: 'damaged', 5: 'wear_and_stain',
  40. },
  41. "img_size": {'width': 512, 'height': 512},
  42. "confidence": 0.5,
  43. "input_channels": 3,
  44. },
  45. "pokemon_front_corner_reflect_defect": {
  46. "pth_path": "Model/pokemon_front_corner_reflect_defect.pth",
  47. "class_dict": {"1": "impact", "2": "wear_and_impact", "3": "wear"},
  48. "img_size": {'width': 512, 'height': 512},
  49. "confidence": 0.5,
  50. "input_channels": 3,
  51. },
  52. "pokemon_front_corner_no_reflect_defect": {
  53. "pth_path": "Model/pokemon_front_corner_no_reflect_defect.pth",
  54. "class_dict": {"1": "wear", "2": "wear_and_impact", "3": "impact", "4": "damaged"},
  55. "img_size": {'width': 512, 'height': 512},
  56. "confidence": 0.5,
  57. "input_channels": 3,
  58. },
  59. "pokemon_front_face_no_reflect_defect": {
  60. "pth_path": "Model/pokemon_front_face_no_reflect_defect.pth",
  61. "class_dict": {"1": "scratch", "2": "pit", "3": "stain"},
  62. "img_size": {'width': 512, 'height': 512},
  63. "confidence": 0.5,
  64. "input_channels": 3,
  65. },
  66. }
  67. # 包含, 环形光居中计算, 环形光正反边角缺陷, 同轴光正反表面缺陷
  68. # 里面存储需要用到的模型类型
  69. DEFECT_TYPE: Dict[str, CardModelConfig] = {
  70. "pokemon_card_center": {
  71. "inner_box": "pokemon_inner_box",
  72. "outer_box": "pokemon_outer_box",
  73. },
  74. "pokemon_back_corner_defect": {
  75. 'model_type': "pokemon_back_corner_defect"
  76. },
  77. "pokemon_front_corner_reflect_defect": {
  78. "model_type": "pokemon_front_corner_reflect_defect"
  79. },
  80. "pokemon_front_corner_no_reflect_defect": {
  81. "model_type": "pokemon_front_corner_no_reflect_defect",
  82. },
  83. "pokemon_front_face_no_reflect_defect": {
  84. "model_type": "pokemon_front_face_no_reflect_defect",
  85. }
  86. }
  87. settings = Settings()
  88. print(settings.BASE_PATH)
  89. # DefectType = Enum("InferenceType", {name: name for name in settings.DEFECT_TYPE})
  90. # print()