Spaces:
Sleeping
Sleeping
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/a5ac89c3aad0ca7f80da8a5dfe3ef8649f3bdf18/detection/ml_utils.py
- Command line
-
hf download hf://spaces/cvachet/object_detection_lambda@a5ac89c3aad0ca7f80da8a5dfe3ef8649f3bdf18/detection/ml_utils.py
-
curl -L -o ml_utils.py https://huggingface.co/spaces/cvachet/object_detection_lambda/resolve/a5ac89c3aad0ca7f80da8a5dfe3ef8649f3bdf18/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 | |