WARNING:tensorflow:6 out of the last 6 calls to <function Model.make_predict_function.<locals>.predict_function at 0x0000022972E28048> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.

时间: 2024-04-17 11:28:57 浏览: 18
这是一个警告信息,提示在过去的6次调用中,函数被重复追踪。这可能是因为在循环中重复创建了@tf.function,传递了不同形状的张量,或者传递了Python对象而不是张量。对于情况(1),请将@tf.function定义在循环外部。对于情况(2),@tf.function有一个实验性的experimental_relax_shapes=True选项,可以放宽参数形状以避免不必要的重追踪。对于情况(3),请参考链接中的文档了解更多细节。
相关问题

WARNING:tensorflow:6 out of the last 6 calls to <function Model.make_predict_function.<locals>.predict_function at 0x000001B6B7A85EE0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing

这个警告通常是由于在循环中定义 `@tf.function` 导致的。当你在循环中定义 `@tf.function` 时,每次迭代都会重新追踪该函数,这会导致重复的追踪,降低了性能。为了避免这个问题,你可以将 `@tf.function` 定义在循环外面,以便只追踪一次。 如果你确信循环内的计算图和循环外的计算图是相同的,你可以通过将 `experimental_relax_shapes=True` 传递给 `@tf.function` 来避免不必要的追踪。这个选项告诉 TensorFlow 在输入形状稍有不同的情况下仍然使用之前追踪的计算图。 下面是一个示例代码,演示了如何在循环中使用 `@tf.function` 并避免追踪警告: ``` import tensorflow as tf @tf.function(experimental_relax_shapes=True) def my_func(x): # 这里定义你的计算图 return x for i in range(10): x = tf.ones((2, 2)) y = my_func(x) ``` 在这个例子中,`my_func` 是一个使用 `@tf.function` 定义的函数,它将输入 `x` 作为参数并返回 `x`。`for` 循环中多次调用 `my_func`,但由于使用了 `experimental_relax_shapes=True`,所以不会出现追踪警告。

这段代码def slide2(y): l = y.shape[0] y = tf.reshape(y, [1, -1, 1]) input = keras.Input(shape=(l, 1)) output = Conv1D(filters=1, kernel_size=3, padding='causal', activation='linear', trainable=False, use_bias=False)(input) output = tf.stop_gradient(output) # 将 output 视为常数 model = keras.Model(inputs=input, outputs=output) weights_list = model.get_weights() weights = np.ones(3) / 3 weights_list[0] = weights.reshape((3, 1, 1)) model.set_weights(weights_list) result = model.predict(y) result = tf.reshape(result, [-1, 1]) return result用在了循环内部,出现了WARNING:tensorflow:6 out of the last 6 calls to <function Model.make_predict_function.<locals>.predict_function at 0x000001B6B7A85EE0> triggered tf.function retracing.警告

这个警告通常是由于在循环中定义 `keras.Model.predict` 函数时触发的,原因是每次调用 `predict` 函数时都需要重新追踪计算图,这会导致性能下降。为了避免这个问题,你可以尝试将 `keras.Model.predict` 函数的定义放到循环外面。 具体而言,你可以先定义一个空的模型,然后在循环内部多次调用 `model` 的 `__call__` 方法,这样就可以避免重复追踪计算图。下面是修改后的代码示例: ``` def slide2(y): l = y.shape[0] y = tf.reshape(y, [1, -1, 1]) input = keras.Input(shape=(l, 1)) output = Conv1D(filters=1, kernel_size=3, padding='causal', activation='linear', trainable=False, use_bias=False)(input) output = tf.stop_gradient(output) # 将 output 视为常数 model = keras.Model(inputs=input, outputs=output) weights_list = model.get_weights() weights = np.ones(3) / 3 weights_list[0] = weights.reshape((3, 1, 1)) model.set_weights(weights_list) # 在循环外定义 result result = np.zeros((y.shape[1], 1)) for i in range(y.shape[1]): x = y[:, :i+1, :] y_pred = model(x) result[i, :] = y_pred[-1, 0] return result ``` 在这个例子中,我们在循环外定义了 `result`,并在循环内部多次调用了 `model` 的 `__call__` 方法,最终得到了和原始代码相同的结果。这样就避免了重复追踪计算图的问题,也就不会再出现 `tf.function retracing` 的警告了。

相关推荐

2023-06-09 09:46:11.022252: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1900] Ignoring visible gpu device (device: 0, name: GeForce GT 610, pci bus id: 0000:01:00.0, compute capability: 2.1) with Cuda compute capability 2.1. The minimum required Cuda capability is 3.5. 2023-06-09 09:46:11.022646: I tensorflow/core/platform/cpu_feature_guard.cc:151] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: AVX AVX2 To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. WARNING:tensorflow:5 out of the last 9 calls to <function Model.make_test_function.<locals>.test_function at 0x0000017BB39D0670> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details. WARNING:tensorflow:6 out of the last 11 calls to <function Model.make_test_function.<locals>.test_function at 0x0000017BB3AE83A0> triggered tf.function retracing. Tracing is expensive and the excessive number of tracings could be due to (1) creating @tf.function repeatedly in a loop, (2) passing tensors with different shapes, (3) passing Python objects instead of tensors. For (1), please define your @tf.function outside of the loop. For (2), @tf.function has experimental_relax_shapes=True option that relaxes argument shapes that can avoid unnecessary retracing. For (3), please refer to https://www.tensorflow.org/guide/function#controlling_retracing and https://www.tensorflow.org/api_docs/python/tf/function for more details.

最新推荐

recommend-type

pre_o_1csdn63m9a1bs0e1rr51niuu33e.a

pre_o_1csdn63m9a1bs0e1rr51niuu33e.a
recommend-type

matlab建立计算力学课程的笔记和文件.zip

matlab建立计算力学课程的笔记和文件.zip
recommend-type

FT-Prog-v3.12.38.643-FTD USB 工作模式设定及eprom读写

FT_Prog_v3.12.38.643--FTD USB 工作模式设定及eprom读写
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

SPDK_NVMF_DISCOVERY_NQN是什么 有什么作用

SPDK_NVMF_DISCOVERY_NQN 是 SPDK (Storage Performance Development Kit) 中用于查询 NVMf (Non-Volatile Memory express over Fabrics) 存储设备名称的协议。NVMf 是一种基于网络的存储协议,可用于连接远程非易失性内存存储器。 SPDK_NVMF_DISCOVERY_NQN 的作用是让存储应用程序能够通过 SPDK 查询 NVMf 存储设备的名称,以便能够访问这些存储设备。通过查询 NVMf 存储设备名称,存储应用程序可以获取必要的信息,例如存储设备的IP地址、端口号、名称等,以便能
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。
recommend-type

"互动学习:行动中的多样性与论文攻读经历"

多样性她- 事实上SCI NCES你的时间表ECOLEDO C Tora SC和NCESPOUR l’Ingén学习互动,互动学习以行动为中心的强化学习学会互动,互动学习,以行动为中心的强化学习计算机科学博士论文于2021年9月28日在Villeneuve d'Asq公开支持马修·瑟林评审团主席法布里斯·勒菲弗尔阿维尼翁大学教授论文指导奥利维尔·皮耶昆谷歌研究教授:智囊团论文联合主任菲利普·普雷教授,大学。里尔/CRISTAL/因里亚报告员奥利维耶·西格德索邦大学报告员卢多维奇·德诺耶教授,Facebook /索邦大学审查员越南圣迈IMT Atlantic高级讲师邀请弗洛里安·斯特鲁布博士,Deepmind对于那些及时看到自己错误的人...3谢谢你首先,我要感谢我的两位博士生导师Olivier和Philippe。奥利维尔,"站在巨人的肩膀上"这句话对你来说完全有意义了。从科学上讲,你知道在这篇论文的(许多)错误中,你是我可以依
recommend-type

实现实时监控告警系统:Kafka与Grafana整合

![实现实时监控告警系统:Kafka与Grafana整合](https://imgconvert.csdnimg.cn/aHR0cHM6Ly9tbWJpei5xcGljLmNuL21tYml6X2pwZy9BVldpY3ladXVDbEZpY1pLWmw2bUVaWXFUcEdLT1VDdkxRSmQxZXB5R1lxaWNlUjA2c0hFek5Qc3FyRktudFF1VDMxQVl3QTRXV2lhSWFRMEFRc0I1cW1ZOGcvNjQw?x-oss-process=image/format,png) # 1.1 Kafka集群架构 Kafka集群由多个称为代理的服务器组成,这