forked from wasserth/TotalSegmentator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_server.py
55 lines (45 loc) · 1.57 KB
/
test_server.py
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
import sys
import os
import requests
import time
from pathlib import Path
"""
Steps to test the server:
1. Create api_key file:
touch store/api_keys.txt
echo jakob:abc123 >> store/api_keys.txt
2. Start server by running `python server.py`.
3. Then in another shell run `python test_server.py`.
"""
# Url needs to have a trailing slash!
# url_base = 'http://localhost:5000/'
url_base = f"http://{sys.argv[1]}/" # read from command line
api_key = sys.argv[2]
print("------------- get_server_status ------------------")
r = requests.post(url_base + "get_server_status",
json={"api_key": api_key})
if r.ok:
print(f"status: {r.json()['status']}")
else:
print(f"status code: {r.status_code}")
print(f"message: {r.json()['message']}")
print("------------- predict_image ------------------")
st = time.time()
test_data_dir = Path("/home/jakob/Downloads/nnunet_test")
filename = test_data_dir / "ct_3mm.nii.gz" # 50s
# filename = test_data_dir / "ct_15mm.nii.gz" # 100s
# filename = test_data_dir / "ct_0000.nii.gz" # 400s
r = requests.post(url_base + "predict_image",
files={'data_binary': open(filename, 'rb')},
data={"api_key": api_key, "statistics": 1})
if r.ok:
seg = r.content # segmentation as bytes object
with open(test_data_dir / 'seg.zip', 'wb') as f:
f.write(seg)
print("Successfully received segmentation")
else:
print(f"status code: {r.status_code}")
print(f"message: {r.json()['message']}")
print(f"took: {time.time() - st:.2f}s")
# without preview:
# 3mm (145x145x274: 5.7M): 28s