python-3.x - 无法转换类型的对象到张量。每副本
问题描述
我在具有 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.
解决方案
推荐阅读
- android - HILT 是否支持注入泛型类型?
- gcc - make 的 -j 参数必须与核心数完全相同吗?
- elixir - 如何处理 Elixir 中的尝试和救援错误
- jenkins - 用于报告工具的阶段帖子部分中的 Jenkins 管道环境变量
- c# - 如何使用 Parallel.ForEach 从 excel 文件中读取单元格数据
- android - 从 ByteArray 播放音频
- asp.net-core - Audit.NET 将 2 个不同的上下文审计到 2 个不同的数据库
- ios - 在 swinject 环境下卡住情节提要控制
- flutter - 如何正确显示拍摄的照片?
- flutter - 我在相机预览中收到“NoSuchMethodError”,这是因为我没有将 dart 文件加载到物理设备中吗?