【问题标题】:Is it possible to train model on GPU,then predict on CPU是否可以在 GPU 上训练模型,然后在 CPU 上进行预测
【发布时间】:2019-08-11 05:13:03
【问题描述】:

我想使用 GPU 设备训练我的自定义模型。 我想知道客户可以通过 CPU 使用它吗?

【问题讨论】:

标签: tensorflow deep-learning gpu cpu


【解决方案1】:

是的,您在 GPU 上进行繁重的训练,保存权重,然后,您的 CPU 将只为预测执行矩阵乘法。

TensorflowKeras 中,您可以训练您的模型并保存神经网络权重:

张量流:

# ON GPU
with tf.Session() as sess:
  sess.run(init)
  save_path = saver.save(sess, "/tmp/saved_model.ckpt")

# ON CPU
with tf.Session() as sess:
    saver.restore(sess, "/tmp/saved_model.ckpt")

Keras:

model.save_weights('your_model_weights.h5')
model.load_weights('your_model_weights.h5')

使用sklearn 算法,您可以通过这种方式保存权重:

model=XGBClassifier(max_depth=100, learning_rate=0.7, n_estimators=10, objective='binary:logistic',booster='gbtree',n_jobs=16,eval_metric="error",eval_set=eval_set, verbose=True)
clf=model.fit(x_train,y_train)
from sklearn.externals import joblib
joblib.dump(clf, '/path/your_model.joblib')

model = joblib.load('/path/your_model.joblib')
model.predict(X_train)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多