Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/waikato-datamining/fast-opex
Simpler and faster implementation of the OPEX JSON file format for object detection predictions.
https://github.com/waikato-datamining/fast-opex
exchange-format json object-detection
Last synced: about 2 months ago
JSON representation
Simpler and faster implementation of the OPEX JSON file format for object detection predictions.
- Host: GitHub
- URL: https://github.com/waikato-datamining/fast-opex
- Owner: waikato-datamining
- License: mit
- Created: 2024-06-13T22:09:33.000Z (7 months ago)
- Default Branch: main
- Last Pushed: 2024-08-22T04:35:32.000Z (4 months ago)
- Last Synced: 2024-11-04T05:05:59.493Z (about 2 months ago)
- Topics: exchange-format, json, object-detection
- Language: Python
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.rst
- License: LICENSE
Awesome Lists containing this project
README
# fast-opex
Simpler and faster implementation of the OPEX JSON file format for object detection predictions.Uses [orjson](https://github.com/ijl/orjson) if present (no pretty-printing available) for further speed-ups,
otherwise the standard json library.This library is written in Python. For a Java port, please see
[opex4j](https://github.com/waikato-datamining/opex4j).## Installation
You can install the library via `pip` (or `pip3`):
```commandline
pip install fast-opex
```## JSON
```json
{
"timestamp": "%Y%m%d_%H%M%S.%f",
"id": "str",
"objects": [
{
"score": 1.0,
"label": "person",
"bbox": {
"top": 100,
"left": 100,
"bottom": 150,
"right": 120
},
"polygon": {
"points": [
[100, 100],
[150, 100],
[150, 120],
[100, 120]
]
}
},
{
"score": 0.95,
"label": "house",
"bbox": {
"top": 100,
"left": 100,
"bottom": 200,
"right": 200
},
"polygon": {
"points": [
[100, 100],
[200, 100],
[200, 200],
[100, 200]
]
},
"meta": {
"price": "500k"
}
}
],
"meta": {
"key1": "value1",
"key2": "value2"
}
}
```**Notes:**
The following keys are optional:
* timestamp
* meta
* score## Reading/Writing
To read a prediction:
```python
from opex import ObjectPredictions# From a string
predictions = ObjectPredictions.from_json_string("{...}")# From a named file
predictions = ObjectPredictions.load_json_from_file("predictions.json")# From an open stream
with open("predictions.json", "r") as stream:
predictions = ObjectPredictions.read_json_from_stream(stream)
```To write a prediction:
```python
from opex import ObjectPredictionspredictions: ObjectPredictions = ...
# Serialise the object to a JSON-formatted string
print(predictions.to_json_string())
print(predictions.to_json_string(indent=2))# Write the object to a file
predictions.save_json_to_file("predictions.json", indent=2)# Write to an open stream
with open("predictions.json", "w") as stream:
predictions.write_json_to_stream(stream, indent=2)
```