如何解决弃用警告:如何删除“警告:不推荐使用约束调用 BaseResourceVariable.__init__...”
我收到此警告,但不知道如何删除它。
这是完整的警告,
WARNING:tensorflow:From C:\Users\gener\anaconda3\envs\freq\lib\site-packages\tensorflow_core\python\ops\resource_variable_ops.py:1630: calling BaseResourceVariable.__init__ (from tensorflow.python.ops.resource_variable_ops) with constraint is deprecated and will be removed in a future version.
Instructions for updating:
If using Keras pass *_constraint arguments to layers.
2021-01-25 16:10:27.289896: I tensorflow/core/platform/cpu_feature_guard.cc:142] Your cpu supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
WARNING:tensorflow:From C:\Users\gener\anaconda3\envs\freq\lib\site-packages\tensorflow_core\python\ops\nn_impl.py:183: where (from tensorflow.python.ops.array_ops) is deprecated and will be removed in a future version.
Instructions for updating:
Use tf.where in 2.0,which has the same broadcast rule as np.where
这是代码。
import tensorflow
import crepe
from scipy.io import wavfile
import csv
import numpy as np
def get_freq(filename):
outputDict = {}
sr,audio = wavfile.read(filename)
time,frequency,confidence,activation = crepe.predict(audio,sr,viterbi=True,step_size = 10)
for stamp in time:
index = np.where(time == stamp)[0][0]
outputDict[stamp] = frequency[index]
with open("../csv/output.csv","w",newline="") as file:
writer = csv.writer(file)
writer.writerow(["time","freq"])
for stamp in outputDict:
writer.writerow([stamp,outputDict[stamp]])
print("Done get_freq.")
我的 tensorflow 是 2.4.0,我尝试用 tf.where 代替 np.where 但这只是让我的代码停止工作。第一个警告我不确定它是什么意思。我在网上看到这些错误对代码无害,但它们很难编码,所以如果有办法摆脱它们,将不胜感激。
解决方法
忽略警告通常不是一个好主意,但似乎 tensorflow 的维护者使用它们的次数比社区喜欢的要多一些(查看此贡献者评论中的不喜欢次数 - https://github.com/tensorflow/tensorflow/issues/27023#issuecomment-475684266)
要禁用它们,这似乎可行:
使用tensorflow 2.X时,可以使用:
import tensorflow as tf
tf.logging.set_verbosity(tf.logging.ERROR)
当使用 tensorflow 1.X 时:
import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)
取自https://github.com/tensorflow/tensorflow/issues/27023#issuecomment-589673539
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。