弃用警告:如何删除“警告:不推荐使用约束调用 BaseResourceVariable.__init__...”

时间:2021-01-25 21:25:05

标签: python tensorflow conda

我收到此警告,但不知道如何删除它。

这是完整的警告,

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

1 个答案:

答案 0 :(得分:1)

忽略警告通常不是一个好主意,但似乎 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