欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

解决model.predict()慢

时间:2023-05-16

以我跑过的模型为例:

原始model.predict

clock1 = time.time()Y_pred = model.predict(X_test)print('model.predict(X_test) time is',time.time() - clock1, 's')

输出:

model.predict(X_test) time is 880.3435561656952 s

解决方法1

clock2 = time.time()Y_pred = = model(X_test, training=False)Y_pred = = np.array(Y_pred )print('model(X_test, training=False) time is',time.time() - clock2, 's')

输出:

model(X_test, training=False) time is 0.2510557174682617 s

解决方法2

clock3= time.time()Pre = model.predict(x=tf.data.Dataset.from_tensors(X_test))print('model.predict(x=tf.data.Dataset.from_tensors(X_test)) time is', time.time() - clock3, 's')

输出:

model.predict(x=tf.data.Dataset.from_tensors(X_test)) time is 0.26605892181396484 s

参考:https://blog.csdn.net/qq_41726670/article/details/117771138

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。