unittest in tensorflow, python session_test.py, got a exception - tensorflow

I'm trying to run session_test.py from https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/client/session_test.py, So in my anaconda, tensorflow virtual env, I went to the corresponding directory in tensorflow like ../master/tensorflow/python/client/.. and run
python session_test.py
I got exception info like this:
Traceback (most recent call last):
File "session_test.py", line 32, in
from tensorflow.core.protobuf import cluster_pb2
ImportError: cannot import name 'cluster_pb2'
What package I should install or related documents that I could read about it. Is there anyone trying to do the same thing, run those unit test coming along with each module in tensorflow repo?
Please help me, thanks!

That line was added just a couple of weeks ago (see commit), and relates to a new feature being implemented in TensorFlow. Unless you have compiled and installed a very bleeding-edge version of TensorFlow you won't be able to run it. Instead, try to run the script corresponding to the version of TensorFlow that you have installed (for example, this is for version 1.1.0, the latest stable release at the time of writing).

Related

file_utils module import failing in colab

I am trying to run BertForSequenceClassification from within Google Colab. My notebook needs to import BertForSequenceClassification from modeling_readmission, but modeling_readmission.py itself contains an important statement that is failing.
from file_utils import cached_path
Other imports like torch work. I tried running
!pip install file_utils
in the previous cell, and it claims to be successfully installed, but the import fails. Another post suggests restarting the module. Did that, no help.
Ironically, you can pip install and do the import from the same cell, and you will get a "successful" installed (or " requirement satisfied") message followed by the error.
Requirement already satisfied: file_utils in /usr/local/lib/python3.7/dist-packages (0.0.1)
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-4-cd0910142da0> in <module>()
1 get_ipython().system('pip install file_utils')
----> 2 import file_utils
I did note that the successful import statement claims that file_utils is installed at
/usr/local/lib/python3.7/dist-packages (0.0.1),
and if you do an !ls on that folder you will indeed see a directory entitled 'file.utils-0.0.1.dist-info, inside of which are INSTALLER, LICENSE, METADATA, RECORD, REQUESTED top_level_txt, WHEEL. I should add that, as recommended in other stackoverflow posts, I also tried appending system paths using:
sys.path.append('./')
sys.path.append('/content/drive/My Drive/CAMLBERT/') #location of modeling_readmission.py
sys.path.append('/usr/local/lib/python3.7/dist-packages') # alleged location of file_utils
Despite looking through several similar stackoverflow posts on colab install failures, I'm totally at a loss. How do I get my Colab to recognize that file_utils has been installed? And how do I get this notebook, which needs to import from modeling_readmission, to run without needing a restart after file_utils is installed?
I'm not sure this is a great answer, but it is a workaround. I simply copied the contents of file_utils.py into a folder and placed them in the main directory of my project. Things ran fine after that.

Run Python, Anaconda, Pandas, Numpy offline on a Server getting dependency error

After installing Anaconda on a Virtual Machine I run a script which is working on my local machine but not on my Virtual Machine.
I'm getting the error Message:
C:\Users\...\python>"C:\ProgramData\Anaconda3\python.exe" "C:\Users\...\reporting.py"
C:\ProgramData\Anaconda3\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "C:\Users\...\reporting.py", line 1, in <module>
import pandas as pd
File "C:\ProgramData\Anaconda3\lib\site-packages\pandas\__init__.py", line 16, in <module>
raise ImportError(
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.8 from "C:\ProgramData\Anaconda3\python.exe"
* The NumPy version is: "1.18.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: DLL load failed while importing _multiarray_umath: The specified module could not be found.
The VM has no Internet. Is there any way to install all the required libs and frameworks?
You can package your script and used libraries using something like Pyinstaller. When you use an virtualenv keep in mind that all the packages that you use during pyinstaller execution are stored and may lead to an huge .exe

Error in Power BI while importing pandas library in python scrip

Below are the mentioned error while importing pandas library in Power BI in python script.
Details: "ADO.NET: Python script error.
C:\USERS\YADAVP\ANACONDA3\lib\site-packages\numpy\__init__.py:140: UserWarning: mkl-service package failed to import, therefore Intel(R) MKL initialization ensuring its correct out-of-the box operation under condition when Gnu OpenMP had already been loaded by Python process is not assured. Please install mkl-service package, see http://github.com/IntelPython/mkl-service
from . import _distributor_init
Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 2, in <module>
import os, pandas, matplotlib
File "C:\USERS\YADAVP\ANACONDA3\lib\site-packages\pandas\__init__.py", line 17, in <module>
"Unable to import required dependencies:\n" + "\n".join(missing_dependencies)
ImportError: Unable to import required dependencies:
numpy:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy c-extensions failed.
- Try uninstalling and reinstalling numpy.
- If you have already done that, then:
1. Check that you expected to use Python3.7 from "C:\USERS\YADAVP\ANACONDA3\python.exe",
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy version "1.18.1" you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
- how you installed Python
- how you installed numpy
- your operating system
- whether or not you have multiple versions of Python installed
- if you built from source, your compiler versions and ideally a build log
- If you're working with a numpy git repository, try `git clean -xdf`
(removes all files not under version control) and rebuild numpy.
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: DLL load failed: The specified module could not be found.
What is the resolution to sort this kind of error in Power BI?
Forget Anaconda and use WinPython.
I tried Anaconda for days with all the workarounds available in StackOverflow and other forums, and they took me nowhere.
Then I tried WinPython, and it worked immediately. Of course, you will need to change the PowerBI options accordingly.
To install WinPython: https://github.com/winpython/winpython
To change the detected Python home directory: https://learn.microsoft.com/en-us/power-bi/connect-data/desktop-python-scripts#enable-python-scripting
If you consider my answer, you won't need to downgrade Python, PBI, or anything else.
I had the same error. Unfortunately, PowerBI wont work with Jupyter Notebook Python.
So you have to install a "normal" Python: https://www.python.org/downloads/
And configure the Python you want to use in PowerBI and install your needed Python libraries via pip
Edit: Please use Python 3.8 because 3.9 doesnt support NumPy for now

Anaconda install of Tensorflow missing 'audio_ops' from contrib framework

I'm trying to follow along the Audio Recognition Network tutorial.
I've created an Anaconda environment with python 3.6 and followed the install instruction accordingly for installing the GPU whl.
I can run the 'hello world' TF example.
When I go to run 'train.py' in the Audio Recognition Network tutorial/example, I get:
Traceback (most recent call last):
File "train.py", line 79, in <module>
import input_data
File "/home/philglau/speech_commands/input_data.py", line 35, in <module>
from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio
ImportError: cannot import name 'audio_ops'
The code in the tutorial that fails is:
from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio
I then backed up that chain until I could import some part of it:
import tensorflow.contrib.framework as test ==> works
import tensorflow.contrib.framework.python as test --> fail:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorflow.contrib.framework' has no attribute 'python'
Not sure where I'm going wrong on my install.
Details:
Ubuntu 16.04
Anaconda env with python 3.6
Followed the 'anaconda' instruction on the TF install page. (GPU version)
I also tried using a python 2.7 env for anaconda but got the same results.
It looks like they're releasing the audio_ops modules in version 1.4 (https://github.com/tensorflow/tensorflow/issues/11339#issuecomment-327879009).
Until v1.4 is released, an easy way around this is to install the nightly tensorflow build
pip install tf-nightly
or with the docker image linked in the issue comment.
The short answer:
The framework is missing the "audio_ops.py" and the example wont work until the file is released. Or you code the wrappers.
More on this:
If you go to the: tensorflow.contrib.framework.python.ops local folder you can find other *_ops.py files but not the "audio_ops.py".
If you get it from the Master at: https://github.com/tensorflow/tensorflow/tree/master/tensorflow/contrib/framework/python/ops
You will find the file is almost empty and with import labels wrong: "audio_ops" vs "gen_audio_ops".
With almost empty I mean that: decode_wav, encode_wav, audio_spectrogram , mfcc are not implemented/wrapped.
So, no working example and no fun.
We need to check again when "audio_ops.py" is released.
Here:
https://github.com/tensorflow/tensorflow/issues/11339
You can find a Developer saying: "we don't actually want to make them public / supported yet. I'm sorry this decision wasn't better documented"

ImportError: No module named inception

Im using imagenet train script (https://github.com/tensorflow/models/blob/master/inception/inception/imagenet_train.py) to train my own image data set to classify in tensorflow (in Oracle VM Virtual box) and im getting an error as below
shri#shri-VirtualBox:~/Desktop/Test/inception_test/models/inception/inception$ python imagenet_train.py
Traceback (most recent call last):
File "imagenet_train.py", line 25, in
from inception import inception_train
ImportError: No module named inception
Could someone please help understand the problem and how do i fix it?
Regards,
Shri
This sounds like a Python module search path issue. The import statements in the particular script imagenet_train.py and other scripts in that directory assume that they can find the other scripts in a submodule called inception, but when you run the script from the same directory, Python can't find that submodule.
The easiest way to fix this is to change to the parent directory (cd ~/Desktop/Test/inception_test/models/inception) and run the script as follows:
$ python inception/inception_train.py