forked from johnolafenwa/DeepStack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark.py
74 lines (62 loc) · 2.14 KB
/
benchmark.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Script to time how long it takes deepstack to process a set of images.
The purpose is to allow comparison of speed on different hosts.
We also count the total number of predictions as a quality check.
Example run: python3 benchmark.py --images_folder /Users/my/images
"""
import argparse
import time
from pathlib import Path
import requests
# deepstack credentials
DEFAULT_IP_ADDRESS = "localhost"
DEFAULT_PORT = 5000
DEFAULT_API_KEY = ""
DEFAULT_IMAGES_FOLDER = "."
def main():
parser = argparse.ArgumentParser(description="Perform benchmarking of Deepstack")
parser.add_argument(
"--ip",
default=DEFAULT_IP_ADDRESS,
type=str,
help="Deepstack IP",
)
parser.add_argument(
"--port",
default=DEFAULT_PORT,
type=int,
help="Deepstack port",
)
parser.add_argument(
"--api_key", default=DEFAULT_API_KEY, type=str, help="Deepstack API key"
)
parser.add_argument(
"--images_folder",
default=DEFAULT_IMAGES_FOLDER,
type=str,
help="The folder of jpg images",
)
args = parser.parse_args()
images = list(Path(args.images_folder).rglob("*.jpg"))
print(f"Processing {len(images)} images in folder {args.images_folder}")
total_predictions = 0 # keep predictions
start_time = time.time()
for i, img_path in enumerate(images):
with open(img_path, "rb") as image_bytes:
response = requests.post(
f"http:https://{args.ip}:{args.port}/v1/vision/detection",
files={"image": image_bytes},
data={"api_key": args.api_key},
)
predictions = response.json()["predictions"]
total_predictions = total_predictions + len(predictions)
print(
f"Processed image number {i} : {str(img_path)}, {len(predictions)} predictions"
)
end_time = time.time()
duration = end_time - start_time
print(
f"Processing completes in {round(duration, 5)} seconds, total of {total_predictions} predictions"
)
if __name__ == "__main__":
main()