I built up a model with 500 captcha images with tensorflow. It works fine on my macbook M1 at a good speed. But when I deployed it to cloud Ubuntu server with 4 cores. it became very slow. Esp. it takes long time when it starts up.
I am using tb-nightly==2.13.0a20230328 version.
Can I run the process all the time so the process receives the input file and return without loading delay?
The result says it took 3.6 sec to solve only 1 captcha image when it's just 1 sec on local macbook. what a bummer!!
Is there any way to improve performance? Please advice.
My code and result is as follows:
Code:
start = time.time()
math.factorial(100000)
data_dir = './gray/'
res = []
# Iterate directory
for path in os.listdir(data_dir):
# check if current path is a file
if os.path.isfile(os.path.join(data_dir, path)):
res.append(path)
img_width = 150
img_height = 50
max_length = 6
characters = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd','e','f','g','h','i','j','k', 'l', 'm', 'n', 'o', 'p', 'q', 'r','s','t', 'u', 'v', 'w', 'x', 'y', 'z' }
weights_path = "./model/weights.h5"
AM = cc.ApplyModel(weights_path, img_width, img_height, max_length, characters)
for i in range(len(res)):
pred = AM.predict(data_dir + res[i])
print(res[i] + '=' + pred)
end = time.time()
print(f"{end - start:.5f} sec"
Result:
(.venv) ubutu@server:~/captcha$ python predict.py
2023-03-29 10:07:24.919058: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2023-03-29 10:07:24.982799: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2023-03-29 10:07:24.983566: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-03-29 10:07:26.063683: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
['gray.png']
1/1 [==============================] - 2s 2s/step
gray.png=pkm7ga
3.64084 sec