Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
343 views
in Technique[技术] by (71.8m points)

python - DEPRECATION WARNING: How to remove "WARNING:calling BaseResourceVariable.__init__ with constraint is deprecated..."

I'm getting this warning and can't figure out how to remove it.

This is the full warning,

WARNING:tensorflow:From C:Usersgeneranaconda3envsfreqlibsite-packagesensorflow_corepythonops
esource_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-packagesensorflow_corepythonops
n_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

Here is the code.

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.")

My tensorflow is 2.4.0 and I tried putting tf.where in place of np.where but that just made my code stop working. The first warning Im not sure what it even means. I saw online that these error are harmless to the code, but their difficult to code with, so if there is a way to get rid of them it would be greatly appreciated.

question from:https://stackoverflow.com/questions/65892650/deprecation-warning-how-to-remove-warningcalling-baseresourcevariable-init

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

It is generally not a good idea to ignore warnings but it seems like maintainers of tensorflow are using them a bit more than community likes (check the number of dislikes on this contributor's comment - https://github.com/tensorflow/tensorflow/issues/27023#issuecomment-475684266)

To disable them it seems like this might work:

When using tensorflow 2.X, you can use:

import tensorflow as tf
tf.logging.set_verbosity(tf.logging.ERROR)

And when using tensorflow 1.X:

import tensorflow as tf
tf.compat.v1.logging.set_verbosity(tf.compat.v1.logging.ERROR)

Taken from https://github.com/tensorflow/tensorflow/issues/27023#issuecomment-589673539


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...