Why am I getting Tensorflow Serving module import error? - python

I am trying to use TensorFlow Serving. I installed TensorFlow serving with these instructions.
When I attempted use this line in my python code
from tensorflow_serving.session_bundle import exporter
I got this problem
>>> from tensorflow_serving.session_bundle import exporter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named tensorflow_serving.session_bundle
Why am I getting this problem? Am I missing something to build TensorFlow to include this module?
P.S.: Hello World TensorFlow application is working fine in my setup.
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))

After spending countless hours, I managed to find the solution.
When I changed the line
from tensorflow_serving.session_bundle import exporter
to
from tensorflow.contrib.session_bundle import exporter
It seems TF developers decided to change their session_bundle package location in the source tree.

Related

No module named 'keras.backend.tensorflow_backend'

I am trying to learn from a python script on semantic search that uses sentence transformer-BERT, While compiling this python script (semantic_search.py) file I encountered the following error:
Traceback (most recent call last):
File "semantic_search.py", line 6, in <module>
import keras.backend.tensorflow_backend as tb
ModuleNotFoundError: No module named 'keras'
Kindly suggest possible source of error and corrections.
This is a problem with versions of keras and tensorflow. It sounds like this tutorial was written before keras became a part of tensorflow. For more info on why this happened and what version you should use, see this article.
Probably what you'd need is to change any imports in the script that start with keras to tensorflow.keras, if you have tensorflow version 2.0 and above. So for that line specifically, you probably want:
import tensorflow.keras.backend as tb

ImportError: cannot import name convert_all_kernels_in_model

I am trying to use ImageAI’s model training to train an AI model.
This is the code:
from imageai.Prediction.Custom import ModelTraining
model_trainer = ModelTraining()
model_trainer.setModelTypeAsResNet()
model_trainer.setDataDirectory("idenprof")
model_trainer.trainModel(num_objects=2, num_experiments=3, enhance_data=True,
batch_size=32, show_network_summary=True)
This is the error I get when running:
Traceback (most recent call last):
File ".../FirstTraining.py", line 1, in <module>
from imageai.Prediction.Custom import ModelTraining
File ".../lib/python2.7/site-packages/imageai/Prediction/Custom/__init__.py", line 4, in <module>
from ..DenseNet.densenet import DenseNetImageNet121
File ".../PycharmProjects/bonez/venv/lib/python2.7/site-packages/imageai/Prediction/DenseNet/densenet.py", line 21, in <module>
from tensorflow.python.keras.utils import convert_all_kernels_in_model
ImportError: cannot import name convert_all_kernels_in_model
I have searched all over but I could not find the same issue or a way to solve the problem. I have the following dependencies installed: Tensorflow, OpenCV, Keras, and ImageAI.
Update: It turns out ImageAI does not support Tensorflow 2 yet. This issue does not happen with following tensorflow version: pip install tensorflow==1.15.2
I had the same issue and resolved it by replacing all tensorflow.python.keras imports with tensorflow.keras in ImageAI library. After this, from imageai.Prediction.Custom import ModelTraining import works fine.
If you want to follow, there is an open issue for problem in ImageAI: https://github.com/OlafenwaMoses/ImageAI/issues/494

How to install or make working keras_retinanet.utils.gpu module?

I am trying to train M-RCNN using Keras and RetinaNet as in the Keras founder's example. I installed retinanet package but this module isn't found. May be it is related to that my TF doesn't use GPU? How to check that?
from keras_retinanet.utils.gpu import setup_gpu
Traceback (most recent call last):
File "<ipython-input-2-1f3ae263a7c6>", line 1, in <module>
from keras_retinanet.utils.gpu import setup_gpu
ModuleNotFoundError: No module named 'keras_retinanet.utils.gpu'
You probably need to install some submodules. The beginning of this code may help you https://www.kaggle.com/labintsevai/keras-retinanet-submission

Paymentwall-Python 1.0.7 Import Error

Following the official Paymentwall documentation testing the API, I tried the code below to import the library (exactly the same code as in the doc example):
from paymentwall import *
Paymentwall.set_api_type(Paymentwall.API_GOODS)
......
But it throws the following import error:
Traceback (most recent call last):
File "/Users/username/project/app/paymentwall.py", line 1, in <module>
from paymentwall import *
File "/Users/username/project/app/paymentwall.py", line 4, in <module>
Paymentwall.set_api_type(Paymentwall.API_GOODS)
NameError: name 'Paymentwall' is not defined
I have paymentwall-python 1.0.7 and Python 3.5.4 in the same conda virtual environment.
Any ideas? They tech support is incredibly slow.
This seems to work:
>>> from paymentwall.base import *
>>> Paymentwall.set_api_type(Paymentwall.API_GOODS)
perhaps the project's structure has changed, but the docs haven't been kept up to date.

Python missing modules with Theano

i have installed theano a deep neural network library and am trying to run some examples, but it looks like the script cant find some of the modules. i tried setting path
export PYTHONPATH=/Library/Python/2.7/site-packages/theano
sys.path.append('/Library/Python/2.7/site-packages/theano')
but both are not working. I get this error. I see that the modules are properly installed in subdirectory of theano /Library/Python/2.7/site-packages/theano/tensor/.. but somehow python cant seem to find the modules
Please can someone help. I am using a mac.
$python theano_mnist.py
Traceback (most recent call last):
File "theano_mnist.py", line 45, in <module>
import theano
File "/Users/prabhubalakrishnan/Desktop/theano.py", line 6, in <module>
from theano.tensor.nnet import conv
ImportError: No module named tensor.nnet
There is an issue on Theano repository. As fast solution I have:
Opened the file "miniconda3/envs/YOUR_CONDA_ENV_NAME/lib/python3.4/site-packages/theano/tensor/signal/downsample.py"
change the import import pool in from . import pool
and it works!

Categories