Reputation: 57
I'm trying to install tensorflow, to do so I use the following:
conda install -c conda-forge/label/cf201901 tensorflow
However when I import tensorflow the following error raises up: ModuleNotFoundError: No module named 'tensorflow.python.tools'
. I took a look at other questions here but the solutions didn't work for me. Can you help?
I'm using python 3.7.1 and conda 4.12.0
Upvotes: 0
Views: 2109
Reputation: 766
I found these generics errors they posted in the tutorials saved_model and their recommendation is exactly use of these functions tf.compat.v1.saved_model.utils.build_tensor_info or tf.compat.v1.saved_model.build_tensor_info. build_tensor_info
It is about the version target, provides the methods used, and the target versions. Using compatibilities matrixes or compile from Github.
Requirements:
1. Ubuntu 20.04.03
2. Anaconda 3-2022.05-Linux-x86_64
1. sudo apt-get install pip
2. pip install see
3. bash Anaconda 3-2022.05-Linux-x86_64
4. sudo /root/anaconda3/bin/conda install -c conda-forge/label/cf201901 tensorflow
[ Generics Errors from the target function ]:
WARNING:tensorflow:From /tmpfs/src/tf_docs_env/lib/python3.7/site-packages/tensorflow/python/tools/saved_model_cli.py:451: load (from tensorflow.python.saved_model.loader_impl) is deprecated and will be removed in a future version.
Instructions for updating:
This function will only be available through the v1 compatibility library as tf.compat.v1.saved_model.loader.load or tf.compat.v1.saved_model.load. There will be a new function for importing SavedModels in Tensorflow 2.0.
INFO:tensorflow:Saver not created because there are no variables in the graph to restore
INFO:tensorflow:The specified SavedModel has no variables; no checkpoints were restored.
Result for output key output:
12.0
[ Recommendation ]:
This function will only be available through the v1 compatibility library as
tf.compat.v1.saved_model.utils.build_tensor_info
or
tf.compat.v1.saved_model.build_tensor_info
[ Sample ]:
import os
from os.path import exists
import tensorflow as tf
import tensorflow.compat.v1 as tf1
tf.compat.v1.disable_eager_execution()
outputs = [ ]
def remove_dir(path):
try:
shutil.rmtree(path)
except:
pass
def add_two(input):
return input + 2
with tf.Graph().as_default() as g:
with tf1.Session() as sess:
input = tf1.placeholder(tf.float32, shape=[])
output = add_two(input)
print("add two output: ", sess.run(output, {input: 3.}))
# Save with SavedModelBuilder
builder = tf1.saved_model.Builder('saved-model-builder')
sig_def = tf1.saved_model.predict_signature_def(
inputs={'input': input},
outputs={'output': output})
builder.add_meta_graph_and_variables(
sess, tags=["serve"], signature_def_map={
tf.saved_model.DEFAULT_SERVING_SIGNATURE_DEF_KEY: sig_def
})
builder.save()
# Save with build_tensor_info
build_tensor_info = tf.compat.v1.saved_model.build_tensor_info( tf.constant( outputs, dtype=tf.int32 ) )
print( build_tensor_info )
Upvotes: 0
Reputation:
By default Tensorflow will be installed on GPU.
To install on CPU run this command pip install tensorflow-cpu
If that doesn't work try pip install tensorflow
If you are using anaconda environment, you can try conda install tensorflow
I hope this will help you.
Upvotes: 1