Spaces:
Paused
Paused
File size: 2,752 Bytes
3f7dd83 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | """
This file contains tests for the API of your model. You can run these tests by installing test requirements:
```bash
pip install -r requirements-test.txt
```
"""
import pytest
import json
from label_studio_ml.utils import compare_nested_structures
from .test_common import client
label_configs = [
# test 1: one control tag with rectangle labels
"""
<View>
<Header value="Select label and click the image to start"/>
<Image name="image" value="$image" zoom="true"/>
<RectangleLabels name="rect" toName="image"
model_score_threshold="0.1" model_obb="true">
<Label value="plane" background="red"
predicted_values="plane,helicopter"/>
<Label value="vehicle" background="blue"
predicted_values="ship,storage tank,bridge,large vehicle,small vehicle"/>
</RectangleLabels>
</View>
""",
]
tasks = [
# test 1: one control tag with rectangle labels
{
"data": {
"image": "https://s3.amazonaws.com/htx-pub/datasets/mmdetection-ml-test/001bebecea382500.jpg"
}
},
]
expected = [
# test 1: one control tag with rectangle labels
[
{
"model_version": "yolo",
"result": [
{
"from_name": "rect",
"score": 0.32253125309944153,
"to_name": "image",
"type": "rectanglelabels",
"value": {
"height": 3.3118023546502084,
"original_height": 576,
"original_width": 768,
"rectanglelabels": ["vehicle"],
"rotation": -89.43998820538127,
"width": 2.2955212735479535,
"x": 1.9985803710085965,
"y": 10.487648558804944,
},
}
],
"score": 0.32253125309944153,
}
]
]
@pytest.mark.parametrize(
"label_config, task, expect", zip(label_configs, tasks, expected)
)
def test_rectanglelabels_obb_predict(client, label_config, task, expect):
data = {"schema": label_config, "project": "42"}
response = client.post(
"/setup", data=json.dumps(data), content_type="application/json"
)
assert response.status_code == 200, "Error while setup: " + str(response.content)
data = {"tasks": [task], "label_config": label_config}
response = client.post(
"/predict", data=json.dumps(data), content_type="application/json"
)
assert response.status_code == 200, "Error while predict"
data = response.json
compare_nested_structures(data["results"], expect)
|