部署时更改 GPU 数量

Change number of GPUs when deploy

我在 2-GPU 机器上有一个微调的 Inception v3。 现在,我正尝试 运行 在另一台具有 1 个 GPU 的机器上训练模型,但出现如下错误:

Cannot assign a device to node 'tower_1/gradients/tower_1/conv0/BatchNorm/moments/sufficient_statistics/Sub_grad/BroadcastGradientArgs': Could not satisfy explicit device specification '/device:GPU:1' because no devices matching that specification are registered in this process; available devices: /job:localhost/replica:0/task:0/cpu:0, /job:localhost/replica:0/task:0/gpu:0

似乎该模型需要一个 2-GPU 环境,就像它训练的环境一样。我可以转换此模型,使其仅使用 1 个 GPU 吗?

我改变了两个东西,它奏效了。

  1. 在会话中打开 allow_soft_placement 选项:

    config = tf.ConfigProto(allow_soft_placement=True)
    sess = tf.Session(config=config)
    
  2. 将模型文件名从 model.ckpt-50000.data-00000-of-00001 重命名为 model.ckpt-50000