-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_imagga.py
More file actions
64 lines (45 loc) · 1.83 KB
/
Copy pathtest_api_imagga.py
File metadata and controls
64 lines (45 loc) · 1.83 KB
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
import time
import fiftyone.zoo as foz
from apis.imagga import Imagga
N_SAMPLES = 10
imagenet_dataset = foz.load_zoo_dataset("imagenet-sample")
api_key = 'YOUR_API_KEY'
api_secret = 'YOUR_API_SECRET'
if __name__ == '__main__':
image_paths = []
imagga_client = Imagga(api_key, api_secret, concurrency=2)
for sample in imagenet_dataset:
image_paths.append(str(sample['filepath']))
print('Running Imagga API')
one_query = []
for i in range(N_SAMPLES):
start = time.time()
imagga_client.predict(image_paths[0])
end = time.time()
one_query.append(end - start)
avg_one_query = sum(one_query) / len(one_query) * 1000
print('Imagga API (1): {:.2f} ms'.format(avg_one_query))
two_query = []
for i in range(N_SAMPLES):
start = time.time()
imagga_client.predictX(image_paths[:2])
end = time.time()
two_query.append(end - start)
avg_five_query = sum(two_query) / len(two_query) * 1000
print('Imagga API (2): {:.2f} ms, x{:.2f} faster'.format(avg_five_query, avg_one_query * 2 / avg_five_query))
ten_query = []
for i in range(N_SAMPLES):
start = time.time()
imagga_client.predictX(image_paths[:10])
end = time.time()
ten_query.append(end - start)
avg_ten_query = sum(ten_query) / len(ten_query) * 1000
print('Imagga API (10): {:.2f} ms, x{:.2f} faster'.format(avg_ten_query, avg_one_query * 10 / avg_ten_query))
twenty_query = []
for i in range(N_SAMPLES):
start = time.time()
imagga_client.predictX(image_paths[:20])
end = time.time()
twenty_query.append(end - start)
avg_twenty_query = sum(twenty_query) / len(twenty_query) * 1000
print('Imagga API (20): {:.2f} ms, x{:.2f} faster'.format(avg_twenty_query, avg_one_query * 20 / avg_twenty_query))