验证模型配置参数 Args: ocr: 是否启用OCR功能 det: 是否启用目标检测功能 old: 是否使用旧版OCR模型 beta: 是否使用beta版OCR模型 use_gpu: 是否使用GPU device_id: GPU设备ID Returns: bool: 配置是否有效 Raises: DDDDOCRError: 当配置无效时
(ocr: bool = True, det: bool = False, old: bool = False,
beta: bool = False, use_gpu: bool = False, device_id: int = 0)
| 32 | |
| 33 | |
| 34 | def validate_model_config(ocr: bool = True, det: bool = False, old: bool = False, |
| 35 | beta: bool = False, use_gpu: bool = False, device_id: int = 0) -> bool: |
| 36 | """ |
| 37 | 验证模型配置参数 |
| 38 | |
| 39 | Args: |
| 40 | ocr: 是否启用OCR功能 |
| 41 | det: 是否启用目标检测功能 |
| 42 | old: 是否使用旧版OCR模型 |
| 43 | beta: 是否使用beta版OCR模型 |
| 44 | use_gpu: 是否使用GPU |
| 45 | device_id: GPU设备ID |
| 46 | |
| 47 | Returns: |
| 48 | bool: 配置是否有效 |
| 49 | |
| 50 | Raises: |
| 51 | DDDDOCRError: 当配置无效时 |
| 52 | """ |
| 53 | # 检查基本参数类型 |
| 54 | if not isinstance(ocr, bool): |
| 55 | raise DDDDOCRError("ocr参数必须为布尔值") |
| 56 | if not isinstance(det, bool): |
| 57 | raise DDDDOCRError("det参数必须为布尔值") |
| 58 | if not isinstance(old, bool): |
| 59 | raise DDDDOCRError("old参数必须为布尔值") |
| 60 | if not isinstance(beta, bool): |
| 61 | raise DDDDOCRError("beta参数必须为布尔值") |
| 62 | if not isinstance(use_gpu, bool): |
| 63 | raise DDDDOCRError("use_gpu参数必须为布尔值") |
| 64 | if not isinstance(device_id, int) or device_id < 0: |
| 65 | raise DDDDOCRError("device_id参数必须为非负整数") |
| 66 | |
| 67 | # 检查功能组合的有效性 |
| 68 | if not ocr and not det: |
| 69 | # 允许两者都为False,这种情况下只能使用滑块功能 |
| 70 | pass |
| 71 | |
| 72 | # 检查模型版本冲突 |
| 73 | if old and beta: |
| 74 | raise DDDDOCRError("old和beta参数不能同时为True") |
| 75 | |
| 76 | # 检查GPU配置 |
| 77 | if use_gpu and device_id < 0: |
| 78 | raise DDDDOCRError("使用GPU时device_id必须为非负整数") |
| 79 | |
| 80 | return True |
| 81 | |
| 82 | |
| 83 | def validate_color_filter_params(colors: List[str] = None, |
no test coverage detected
searching dependent graphs…