到张量。每副本,python-3.x,tensorflow,multi-gpu"/>

首页 > 解决方案 > 无法转换类型的对象到张量。每副本

问题描述

我在具有 4 个 GPU 的 EC2 实例上训练 TensorFlow 代码并收到此错误。我的训练和测试策略就像下面的代码。有什么想法或建议吗?

提前致谢!

mirrored_strategy = tf.distribute.MirroredStrategy()
test_ds = test_ds.repeat(repeat_size).shuffle(1000).batch(global_batch_size).prefetch(buffer_size=tf.data.experimental.AUTOTUNE) 
dist_dataset_test = mirrored_strategy.experimental_distribute_dataset(test_ds)
TypeError: Failed to convert object of type <class 'tensorflow.python.distribute.values.PerReplica'> to Tensor. Contents: PerReplica:{
  0: Tensor("cond_4/Identity:0", shape=(None, 12, 64), dtype=float32, device=/job:localhost/replica:0/task:0/device:GPU:0),
  1: Tensor("cond_5/Identity:0", shape=(None, 12, 64), dtype=float32, device=/job:localhost/replica:0/task:0/device:GPU:1),
  2: Tensor("cond_6/Identity:0", shape=(None, 12, 64), dtype=float32, device=/job:localhost/replica:0/task:0/device:GPU:2),
  3: Tensor("cond_7/Identity:0", shape=(None, 12, 64), dtype=float32, device=/job:localhost/replica:0/task:0/device:GPU:3)
}. Consider casting elements to a supported type.

标签: python-3.xtensorflowmulti-gpu

解决方案


推荐阅读