config.py 3.4 KB

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