Parse Options[] list of ``key:value`` strings into a dict. Supports type inference for common cases (bool, int, float). Unknown or mixed-case values are returned as strings. Used by LoadModel to extract backend-specific options passed via ``ModelOptions.Options`` in ``backend.proto
(options_list)
| 8 | |
| 9 | |
| 10 | def parse_options(options_list): |
| 11 | """Parse Options[] list of ``key:value`` strings into a dict. |
| 12 | |
| 13 | Supports type inference for common cases (bool, int, float). Unknown or |
| 14 | mixed-case values are returned as strings. |
| 15 | |
| 16 | Used by LoadModel to extract backend-specific options passed via |
| 17 | ``ModelOptions.Options`` in ``backend.proto``. |
| 18 | """ |
| 19 | opts = {} |
| 20 | for opt in options_list: |
| 21 | if ":" not in opt: |
| 22 | continue |
| 23 | key, value = opt.split(":", 1) |
| 24 | key = key.strip() |
| 25 | value = value.strip() |
| 26 | # Try type conversion |
| 27 | if value.lower() in ("true", "false"): |
| 28 | opts[key] = value.lower() == "true" |
| 29 | else: |
| 30 | try: |
| 31 | opts[key] = int(value) |
| 32 | except ValueError: |
| 33 | try: |
| 34 | opts[key] = float(value) |
| 35 | except ValueError: |
| 36 | opts[key] = value |
| 37 | return opts |
| 38 | |
| 39 | |
| 40 | def messages_to_dicts(proto_messages): |
no outgoing calls