解决model.predict()慢

以我跑过的模型为例:

原始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

你可能感兴趣的:(Python,tensorflow,python,人工智能)