Spaces:
Running
Running
Download detection/ml_utils.py from cvachet/object_detection_lambda: direct link, hf CLI and curl.
- Browser
- Download file 429 Bytes
-
https://huggingface.co/spaces/cvachet/object_detection_lambda/resolve/c8fa85e07a8b10094e2b4a4eaf42339f236ce65f/detection/ml_utils.py
- Command line
-
hf download hf://spaces/cvachet/object_detection_lambda@c8fa85e07a8b10094e2b4a4eaf42339f236ce65f/detection/ml_utils.py
-
curl -L -o ml_utils.py https://huggingface.co/spaces/cvachet/object_detection_lambda/resolve/c8fa85e07a8b10094e2b4a4eaf42339f236ce65f/detection/ml_utils.py
429 Bytes
| import torch | |
| import json | |
| def convert_tensor_dict_to_json(tensor_dict): | |
| """Convert a dictionary of tensors to a JSON-serializable dictionary.""" | |
| json_dict = {key: value.detach().cpu().numpy().tolist() if isinstance(value, torch.Tensor) else value | |
| for key, value in tensor_dict.items()} | |
| # Convert to JSON string | |
| # json_str = json.dumps(json_dict) | |
| # print(json_str) | |
| return json_dict | |