如何解决使用Keras和远程TesorFlow训练模型
由于我找不到任何有用的信息,所以我想寻求您的帮助。
我想在服务器上启动TensorFlow(2.1.0),并使用客户端上的keras在其上训练模型。
要启动TensorFlow服务器,我在远程计算机上使用了tf.distribute.Server类:
import tensorflow as tf
cluster_spec = tf.train.ClusterSpec({
"worker": [
"remotehost:2222"
],"ps": [
"remotehost:2221"
]
})
ps = tf.distribute.Server(cluster_spec,job_name="ps",task_index=0)
worker = tf.distribute.Server(cluster_spec,job_name="worker",task_index=0)
ps.join()
worker.join()
使用experimental_connect_to_host方法,客户端可以成功连接到服务器:
tf.config.experimental_connect_to_host(remote_host='remotehost:2222',job_name='worker')
但是,我不确定如何告诉keras使用此服务器。因此,在创建和训练模型之前,我只是打电话给experimental_connect_to_host
。建立了连接,但培训仍在本地进行:
2020-09-25 17:42:25.776262: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
2020-09-25 17:42:25.809998: I tensorflow/core/common_runtime/process_util.cc:147] Creating new thread pool with default inter op setting: 2. Tune using inter_op_parallelism_threads for best performance.
2020-09-25 17:42:25.875051: I tensorflow/core/distributed_runtime/rpc/grpc_channel.cc:300] Initialize GrpcChannelCache for job worker -> {0 -> remotehost:2222}
2020-09-25 17:42:25.889637: I tensorflow/core/distributed_runtime/rpc/grpc_channel.cc:300] Initialize GrpcChannelCache for job localhost -> {0 -> localhost:59320}
2020-09-25 17:42:28.325110: I tensorflow/core/distributed_runtime/rpc/grpc_channel.cc:300] Initialize GrpcChannelCache for job worker -> {0 -> remotehost:2222}
2020-09-25 17:42:28.368530: I tensorflow/core/distributed_runtime/rpc/grpc_channel.cc:300] Initialize GrpcChannelCache for job localhost -> {0 -> localhost:59320}
2020-09-25 17:42:28.427439: I tensorflow/core/distributed_runtime/rpc/grpc_server_lib.cc:390] Started server with target: grpc://localhost:59320
Train on 539 samples,validate on 29 samples
Epoch 1/300
539/539 - 2s - loss: 0.4477 - accuracy: 0.8534 - val_loss: 0.4668 - val_accuracy: 0.8276
...
有人知道是否以及如何使用Keras和TensorFlow在远程设备上进行训练吗?
谢谢。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。