常见错误排查 ✅
- 设备不匹配:检查
tf.config.list_physical_devices()
是否包含预期的GPU/TPU - 数据类型问题:使用
tf.debugging.check_numerics()
验证张量数值合法性 - 模型收敛缓慢:通过TensorBoard可视化损失曲线
/Community/Technology_Tutorials/Python/Tutorial/TensorFlow_TensorBoard
调试工具推荐 🔍
- TensorBoard 📊
- 实时监控训练指标
- 可视化计算图结构
- print调试 📜
- 关键节点添加
tf.print()
输出 - 使用
logging
模块记录调试信息
- 关键节点添加
- 断言检查 ⚠️
tf.debugging.assert_allclose()
验证数值精度tf.debugging.assert_shapes()
确认张量形状
实战技巧 💡
- 在
tf.function
装饰器中启用experimental_run_tf_function=False
禁用自动图形 - 使用
tf.debugging.set_log_device_placement(True)
定位设备分配问题 - 通过
tf.summary.create_file_writer()
自定义日志记录格式