implement num_steps
Browse files- api_test.py +16 -15
api_test.py
CHANGED
@@ -6,6 +6,7 @@ import torch
|
|
6 |
|
7 |
from api_helper import preprocess_image, encode_numpy_array
|
8 |
clip_image_size = 224
|
|
|
9 |
|
10 |
client = Client("http://127.0.0.1:7860/")
|
11 |
|
@@ -34,23 +35,23 @@ def test_image_as_payload(payload):
|
|
34 |
|
35 |
# performance test for text
|
36 |
start = time.time()
|
37 |
-
for i in range(
|
38 |
test_text()
|
39 |
end = time.time()
|
40 |
-
|
41 |
-
print("Average time for text: ",
|
42 |
-
print("Average time for text: ",
|
43 |
-
print("Number of predictions per second for text: ", 1 /
|
44 |
|
45 |
# performance test for image
|
46 |
start = time.time()
|
47 |
-
for i in range(
|
48 |
test_image()
|
49 |
end = time.time()
|
50 |
-
|
51 |
-
print("Average time for image: ",
|
52 |
-
print("Average time for image: ",
|
53 |
-
print("Number of predictions per second for image: ", 1 /
|
54 |
|
55 |
|
56 |
|
@@ -72,11 +73,11 @@ payload = encode_numpy_array(input_image)
|
|
72 |
|
73 |
# performance test for image as payload
|
74 |
start = time.time()
|
75 |
-
for i in range(
|
76 |
test_image_as_payload(payload)
|
77 |
end = time.time()
|
78 |
-
|
79 |
-
print("Average time for image as payload: ",
|
80 |
-
print("Average time for image as payload: ",
|
81 |
-
print("Number of predictions per second for image as payload: ", 1 /
|
82 |
|
|
|
6 |
|
7 |
from api_helper import preprocess_image, encode_numpy_array
|
8 |
clip_image_size = 224
|
9 |
+
num_steps = 1000
|
10 |
|
11 |
client = Client("http://127.0.0.1:7860/")
|
12 |
|
|
|
35 |
|
36 |
# performance test for text
|
37 |
start = time.time()
|
38 |
+
for i in range(num_steps):
|
39 |
test_text()
|
40 |
end = time.time()
|
41 |
+
average_time_seconds = (end - start) / num_steps
|
42 |
+
print("Average time for text: ", average_time_seconds, "s")
|
43 |
+
print("Average time for text: ", average_time_seconds * 1000, "ms")
|
44 |
+
print("Number of predictions per second for text: ", 1 / average_time_seconds)
|
45 |
|
46 |
# performance test for image
|
47 |
start = time.time()
|
48 |
+
for i in range(num_steps):
|
49 |
test_image()
|
50 |
end = time.time()
|
51 |
+
average_time_seconds = (end - start) / num_steps
|
52 |
+
print("Average time for image: ", average_time_seconds, "s")
|
53 |
+
print("Average time for image: ", average_time_seconds * 1000, "ms")
|
54 |
+
print("Number of predictions per second for image: ", 1 / average_time_seconds)
|
55 |
|
56 |
|
57 |
|
|
|
73 |
|
74 |
# performance test for image as payload
|
75 |
start = time.time()
|
76 |
+
for i in range(num_steps):
|
77 |
test_image_as_payload(payload)
|
78 |
end = time.time()
|
79 |
+
average_time_seconds = (end - start) / num_steps
|
80 |
+
print("Average time for image as payload: ", average_time_seconds, "s")
|
81 |
+
print("Average time for image as payload: ", average_time_seconds * 1000, "ms")
|
82 |
+
print("Number of predictions per second for image as payload: ", 1 / average_time_seconds)
|
83 |
|