I want to optimize my neural network (Resnet101 from Google) for inference with TensorRT (ver. 5.1). I've been looking for blogs and tutorials how to do it and found some stuff like here and a few other. All of them have one common thing:
trt_graph = trt.create_inference_graph(
getNetwork(network_file_name),
outputs,
max_batch_size=batch_size,
max_workspace_size_bytes=workspace_size,
precision_mode=”INT8")
But the problem is that my version of TensorRT does not have such function. I get an output as below.
Python 3.6.6 |Anaconda custom (64-bit)
>>> import tensorrt as trt
>>> trt.__version__
5.1.2.2
>>> trt.create_inference_graph()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'tensorrt' has no attribute 'create_inference_graph'
Does anyone know if that function was replaced with other in version 5.1 of TensorRT? How to run it?
Some installations of tensorflow already have tensorrt by default. Try with;
import tensorflow.contrib.tensorrt as trt
This is also another location from where you can import tensorrt
from tensorflow.python.compiler.tensorrt import trt_convert as trt
As #Uziel suggested Tensorrt should be used with:
import tensorflow.contrib.tensorrt as trt
Unfortunately in my case that import caused a following error:
tensorflow.python.framework.errors_impl.NotFoundError: libnvinfer.so.4: cannot open shared object file: No such file or directory
There was a problem with my installation of TensorRT. After reinstalling everything it works now.
Related
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
I am trying to run a code using keras. The program uses from keras.backend.tensorflow_backend import set_session and i am getting an underhanded Exception thats says No module named 'keras.backend.tensorflow_backend'; 'keras.backend' is not a package with the following error code File "c:/Users/phili/Desktop/python-projects/test.py", line 15, in <module> from keras.backend.tensorflow_backend import set_session ModuleNotFoundError: No module named 'keras.backend.tensorflow_backend'; 'keras.backend' is not a package
I am using python 3.7 Keras 2.4.3 and tensorflow 2.2.0, is there any solution to the problem i can provide the whole code if needed
Thanks in advance
I guess you are importing it incorrectly.
The command to import set_session, for Tensorflow 2.3 (latest version) is shown below.
from tensorflow.compat.v1.keras.backend import set_session
Please find this Colab for working code.
Please refer this Tensorflow Documentation for more information.
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
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.
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!