弃用警告:如何删除"WARNING:calling BaseResourceVariable.__init__ with constraint is deprecated..."



我收到这个警告,不知道如何删除它。

这是完整的警告,

WARNING:tensorflow:From C:Usersgeneranaconda3envsfreqlibsite-packagestensorflow_corepythonopsresource_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:Usersgeneranaconda3envsfreqlibsite-packagestensorflow_corepythonopsnn_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。这里代替了np。但这只是让我的代码停止工作。第一个警告我甚至不确定它是什么意思。我在网上看到这些错误对代码是无害的,但它们很难编码,所以如果有办法摆脱它们,我将不胜感激。

忽略警告通常不是一个好主意,但看起来tensorflow的维护者使用它们的次数比社区喜欢的要多(查看这个贡献者的评论中不喜欢的数量- https://github.com/tensorflow/tensorflow/issues/27023#issuecomment-475684266)

要禁用它们,似乎可以这样做:

使用tensorflow时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

相关内容

  • 没有找到相关文章

最新更新