How can I fix this error with tensorflow warning? - tensorflow

When the programme has been started in the console outputting:
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.base has been moved to tensorflow.python.trackable.base. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.checkpoint_management has been moved to tensorflow.python.checkpoint.checkpoint_management. The old module will be deleted in version 2.9.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.resource has been moved to tensorflow.python.trackable.resource. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.util has been moved to tensorflow.python.checkpoint.checkpoint. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.base_delegate has been moved to tensorflow.python.trackable.base_delegate. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.graph_view has been moved to tensorflow.python.checkpoint.graph_view. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.tracking.python_state has been moved to tensorflow.python.trackable.python_state. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.saving.functional_saver has been moved to tensorflow.python.checkpoint.functional_saver. The old module will be deleted in version 2.11.
WARNING:tensorflow:Please fix your imports. Module tensorflow.python.training.saving.checkpoint_options has been moved to tensorflow.python.checkpoint.checkpoint_options. The old module will be deleted in version 2.11.
How to fix this?
update
there

To reduce the amount of warnings given by tensorflow all you need to do is define how much you want to avoid changing your os.environ variable here is a sample. 1 will make sure nothing is printed
import os.
import tensorflow as tf.
os.environ['TF_CPP_MIN_LOG_LEVEL'] = '1'

Can you try setting the log level before you import tensorflow?
import os
os.environ['TF_CPP_MIN_LOG_LEVEL'] = "2"
import tensorflow as tf

The logging occurs in this function:
def getter(name):
if getter not in _PRINTED_WARNING and _PRINT_DEPRECATION_WARNINGS:
_PRINTED_WARNING[getter] = True
logging.warning(
'Please fix your imports. Module %s has been moved to %s. The old '
'module will be deleted in version %s.', deprecated_name,
new_module.__name__, deletion_version)
return getattr(new_module, name)
return getter
In various modules, you'll find:
deprecation.deprecate_moved_module(
__name__, <MODULE_NAME>, "<VERSION_NUMBER>")
One example from the snippet provided is tensorflow.python.training.saving.checkpoint_options:
from tensorflow.python.checkpoint import checkpoint_options
from tensorflow.python.util import deprecation
__getattr__ = deprecation.deprecate_moved_module(
__name__, checkpoint_options, "2.11")
which indicates importing from that module is being deprecated in 2.11 (although it will still technically work until then).
Based on the snippet provided, it does not appear you're directly importing these modules, but an external dependency or a different module may be. If fixing the imports is not possible, in the same deprecations module, there is a context manager called silence, which changes the global variable _PRINT_DEPRECATION_WARNINGS to False within the context block and will therefore prevent the warning logs from surfacing. The use would be something like:
from tensorflow.python.util import deprecation
with deprecation.silence():
<INSERT_CODE_HERE>
Alternatively, if you don't want to put a large code block within a context manager, you could just set the variable _PRINT_DEPRECATION_WARNINGS directly at the top of your module:
from tensorflow.python.util import deprecation
deprecation._PRINT_DEPRECATION_WARNINGS = False
<INSERT_CODE_HERE>
Note that setting the environment variable TF_CPP_MIN_LOG_LEVEL to 1-3 for reduced logging does not apply for deprecation warnings, as discussed in this thread.

Related

plotnine is broken with matplotlib==3.6

I am getting the following error with plotnine==0.9 and matplotlib==3.6.
File "D:\Python\Python310\lib\site-packages\plotnine\stats\stat_density_2d.py", line 3, in <module>
import matplotlib._contour as _contour
ModuleNotFoundError: No module named 'matplotlib._contour'
If I downgrade matplotlib==3.5, the problem goes away.
It's discussed here and it's already fixed here Note that it's already merged to main.
It was due to a internal matplotlib call that is no longer supported and has been replaced.
So I guess you could choose between:
downgrade to mlp 3.5.3
install plotnine#main
till the next plotnine release.
Carlos's answer is correct. However if anybody else, like me, is uncertain of how to install plotnine#main, you can implement the fix rather easily:
Find the site_packages folder you python script uses. It usually is a subdirectory of the python version you are using, which can located reliably by trying to reinstall matplotlib or any other package you know you have access to, and checking the logs in the console. ex using python -m pip install matplotlib.
Go down into the site_packages/plotnine/stats directory and open up the stats_density_2d.py file in your editor of choice.
Apply & save the modifications made in the fix. Alternatively, overwrite the file with the one from the github.
ModuleNotFoundError: No module named 'matplotlib._contour'
Issues with matplotlib 3.6.1 and
plotnine 0.9.0
K.I.S.S.
in terminal:
pip show matplotlib #enables you to check version
pip install matplotlib==3.5 #revert and problem is resolved for now.
no more:
ModuleNotFoundError: No module named 'matplotlib._contour'
resolves issue for now that will stop progress...

want to upload a file to s3 using apache airflow [ DAG ] file

i want to make a DAG file (apache airflow) for uploading a rar file to s3 bucket any one tried.? plz suggest ,
and i tried these things on my DAG file but there is showing some error
from airflow.operators import SimpleHttpOperator, HttpSensor, , EmailOperator, S3KeySensor
The error is
/usr/local/lib/python3.6/dist-packages/airflow/utils/helpers.py:439: DeprecationWarning: Importing 'SimpleHttpOperator' directly from 'airflow.operators' has been deprecated. Please import from 'airflow.operators.[operator_module]' instead. Support for direct imports will be dropped entirely in Airflow 2.0.
DeprecationWarning)
/usr/local/lib/python3.6/dist-packages/airflow/utils/helpers.py:439: DeprecationWarning: Importing 'HttpSensor' directly from 'airflow.operators' has been deprecated. Please import from 'airflow.operators.[operator_module]' instead. Support for direct imports will be dropped entirely in Airflow 2.0.
DeprecationWarning)
/usr/local/lib/python3.6/dist-packages/airflow/utils/helpers.py:439: DeprecationWarning: Importing 'EmailOperator' directly from 'airflow.operators' has been deprecated. Please import from 'airflow.operators.[operator_module]' instead. Support for direct imports will be dropped entirely in Airflow 2.0.
how to solve this issue.?
This is simply a warning, not an error. A DeprecationWarning usually hints that something you're doing will work now, but may break in future versions. If your task is failing, ignore these messages and look for a proper error.
Code for operators have always been located under airflow.operators.[operator_module], but it was also made available under airflow.operators directly for convenience. For example, SimpleHttpOperator is defined in https://github.com/apache/airflow/blob/1.10.9/airflow/operators/http_operator.py, so importing it from airflow.operators.http_operator will definitely work. However, importing it from airflow.operators will also work due to the code that currently exists in https://github.com/apache/airflow/blob/1.10.9/airflow/operators/init.py#L97-L99, at least for now in your current version of Airflow. Basically, you can address these warnings by updating your imports to the following:
from airflow.operators.http_operator import SimpleHttpOperator
from airflow.operators.email_operator import EmailOperator
from airflow.sensors.http_sensor import HttpSensor
from airflow.sensors.s3_key_sensor import S3KeySensor
Just heads up, currently only on the master branch, not yet in any released version, some of the third party operators and sensors have also been moved again. For example, S3KeySensor will be found under providers.amazon.aws.sensors.s3_key.py. As expected, importing from the "old" path will get you a similar deprecation message, https://github.com/apache/airflow/blob/97a429f9d0cf740c5698060ad55f11e93cb57b55/airflow/sensors/s3_key_sensor.py#L25-L28.

No module named lstm_predictor

When I am trying to import the following module,
>>> from lstm_predictor import lstm_model
The error says no module named lstm_predictor.
How can I solve the problem?
It seems like you are utilizing the lstm_predictor package present in https://github.com/tgjeon/TensorFlow-Tutorials-for-Time-Series.
Since this is not a standard module, make sure you have cloned this project and you have the lstm_predictor.py file in the same folder as your python terminal.

Import org.apache.commons.io.FileUtils; not possible in latest apache poi.Instead import org.apache.tools.ant.util.FileUtils; is coming

In the latest Apache poi download(poi-3.15-beta2), while taking screenshot, I need to use FileUtils.copyFile. In its previous version, the imported package was import org.apache.commons.io.FileUtils;. In the latest download, this package is not coming, and it is giving error in my existing executable code. Now I tried to remove the previous import and it gave import org.apache.tools.ant.util.FileUtils;
Code:
FileUtils.copyFile(
scrFile,
new File(location+"LR_"+strDate+"_scr1.png")
);
Gives the error:
Cannot make a static reference to the non-static method
`copyFile(File, File)` from the type `FileUtils`
Apache POI never bundled or required Apache Commons IO, which contains the FileUtils class and so it seems some other project dragged in this code previously, but does not any longer. See http://poi.apache.org/overview.html#components for the list of third-party projects that Apache POI uses.
You should simply add a recent commons-io dependency to your project depending on which type of buildsystem you use, e.g. a normal dependency in Gradle/Maven or the actual jar-file if you have a buildsystem without full dependency-support.
Use the code below:
FileUtils.getFileUtils().copyFile(sourceFile, new File(directory + filename));
And import file should be:
import org.apache.tools.ant.util.FileUtils;

OMP warning when numpy 1.8.0 is packaged with py2exe

import numpy
When I packaged above one line script as a single executable window application using py2exe, I get following warnings upon launch.
OMP: Warning #178: Function GetModuleHandleEx failed:
OMP: System error #126: The specified module could not be found.
This warning happen only when I build as single executable (i.e., only when bundle_files=1). Here's my setup.py for this.
from distutils.core import setup
import py2exe
setup(
options = {'py2exe': {'bundle_files': 1}},
windows=['testnumpy.py'],
zipfile = None,
)
This problem started with numpy 1.8.0. When I revert back to 1.6.2, the warnings don't show up.
Usually a single executable packaged by py2exe will catch warnings and traceback and save them into a log file. But somehow these warnings are not captured and the app creates a console window to show warning. I want to suppress this additional console window to show up.
How can I fix this warning problem?
What I tried (nothing worked):
I tried this redirecting sys.stderr.
I searched github numpy source for openMP assuming the OMP stands for it as mentioned here. But, nothing useful came out.
I have copied libiomp5md.dll to the same folder as setup.py.
I tried filterwarnings:
I tried sys.excepthook.
As I wrote in the comment, installing numpy 1.8.1rc1 from sourceforge did fix the issue, although I don't really know the differences...
I had this issue with numpy 1.13.1+mkl and scipy 1.19.1. Reverting to numpy 1.8.1rc1 is not an acceptable solution.
I tracked this issue to the scipy.integrate subpackage. The warning message pops up when this package is imported. It seems that perhaps libraries that use MKL don't like being invoked from library.zip, which is where py2exe places packages when using bundle option 2.
The solution is to exclude scipy and numpy in the py2exe setup script and copy their entire package folders into the distribution directory and add that directory to the system path at the top of the main python script.