I have a tensor x of shape (4,64,5,5). How can I print (or just visualize) the content of a specific dimension?
What I'm trying to do is
with tf.Session() as sess: print(x[0,:,:,:].eval())
but I got the following error:
FailedPreconditionError: Error while reading resource variable dense_2/kernel from Container: localhost. This could mean that the variable was uninitialized. Not found: Container localhost does not exist. (Could not find resource: localhost/dense_2/kernel)
I'm using Tensorflow
1.14
I tried the same in colab in Tensorflow version 1.14 using tf.ones(shape=(4,64,5,5)). It is working fine. Here's the code:
! pip install tensorflow==1.14
import tensorflow as tf
print(tf.__version__)
x=tf.ones(shape=(4,64,5,5))
with tf.Session() as sess: print(x[:,0,0,0].eval())
Output:
1.14.0
[1. 1. 1. 1.]
Let us know if the issue still persists. Thanks!
Related
I have trained one object detection model in tensorflow.
My Environment--
tf version == 1.15, network== ssd mobilnet v2
Now i want to convert my saved_model(.pb) file to tfjs(.json) format.
I followed below steps--
pip install tensorflowjs==0.8.6 # not sure if it's compatible with tf version 1.15
command==
tensorflowjs_converter --input_format=tf_saved_model --output_format=tfjs_graph_model --signature_name=serving_default --saved_model_tags=serve exported_path/saved_model exported_path/web_model_path
Error== AttributeError: module 'keras_applications' has no attribute 'set_keras_submodules'
Then i degrade keras_application version.
Now getting error as
usage: TensorFlow.js model converters. [-h]
[--input_format {keras,tf_session_bundle,keras_saved_model,tf_hub,tf_saved_model,tensorflowjs,tf_frozen_model}]
[--output_format {keras,tensorflowjs}]
[--output_node_names OUTPUT_NODE_NAMES]
[--signature_name SIGNATURE_NAME]
[--saved_model_tags SAVED_MODEL_TAGS]
[--quantization_bytes {1,2}]
[--split_weights_by_layer] [--version]
[--skip_op_check SKIP_OP_CHECK]
[--strip_debug_ops STRIP_DEBUG_OPS]
[--output_json OUTPUT_JSON]
[input_path] [output_path]
TensorFlow.js model converters.: error: argument --output_format: invalid choice: 'tfjs_graph_model' (choose from 'keras', 'tensorflowjs')
So there is no option for tf_graph_model in output_format.
Now when i am installing pip install tensorflowjs (not passing any specific version), then it installs tfjs==3.3.0, and uninstaling my current tf1.15 and installing new tf2.x version. which i need to avoid at any cost.
Can somebody please guide me , how to convert the saved_model to tf_js format in version tensorflow==1.15.
Thanks in Advance.
Can you please upgrade tensorflow to latest version tf 2.x, stable versions tf 2.6/2.7 and let us know if this issue exist as tf 1.x is not supported any more and hence these errors.
I use Python 3.5, Tensorflow-gpu 1.12.0, Keras 2.2.4 in ubuntu. When I use system interpreter in Pycharm, the code is run without any problem. But, when I create a virtual environment in Pycharm and install the same versions of all necessary packages (OpenCV, Sklearn, pandas, Keras, Tensorflow), it gives the following error:
Traceback (most recent call last):
File "/media/ehsan/48BE4782BE476810/AA_MY_PYTHON_CODE/MultiLable_MultiTask_Light_Examples/CodeTwo/2_Main_Code_Training_Multitask_Network.py", line 338, in <module>
base_model, multi_model, feature_map = multi_model(loss_list, test_metrics, dd)
File "/media/ehsan/48BE4782BE476810/AA_MY_PYTHON_CODE/MultiLable_MultiTask_Light_Examples/CodeTwo/2_Main_Code_Training_Multitask_Network.py", line 40, in multi_model
_, base_model = VGG19(weights='imagenet', include_top=False, input_shape=(175, 100, 3))
TypeError: 'Model' object is not iterable
I tried to reinstall Tensorflow and Keras. Also, I recreated the virtual environment. But, I got the same error while using the virtual environment.
Try importing the model from TensorFlow instead of Keras.
from tensorflow.keras.models import load_model
instead of
from keras.models import load_model
I was installing tensorboard using pip install tensorboard. All worked fine
I run my network and the writer also worked fine
with tf.Session() as sess:
writer = tf.summary.FileWriter("pathtofolder", sess.graph)
print(sess.run(h))
writer.close()
now I wanted to see in tensorboard how it learned
I inserted
import tensorflow, tensorboard
tensorboard --logdir /pathtofolder
and received the error message.
NameError: name 'logdir' is not defined
You should execute the command on terminal/cmd.
Open your terminal/cmd and run:
tensorboard --logdir ./PATH_TO_THE_EVENT_FILES
If you want to run Tensorboard on python file see here:
I can't seem to find exact question about what I am about to ask here. I just started following a Tensorflow tutorial on YouTube and got stuck at the very beginning. I wrote in my spyder IDE the below code:
import tensorflow as tf
a = tf.constant(2)
b = tf.constant(3)
x = tf.add(a,b)
#writer = tf.summary.FileWriter('./graphs', tf.get_default_graph())
with tf.Session() as sess:
writer = tf.summary.FileWriter('./graphs', sess.graph)
print(sess.run(x))
writer.close()
And via anaconda terminal I activated my env (which I newly created, installed all packages required, spyder as well) I typed python tftuts.py and got 2018-10-05 11:50:49.431174: I T:\src\github\tensorflow\tensorflow\core\platform\cpu_feature_guard.cc:141] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
5
Then I typed tensorboard --logdir="./graphs" --port 6006 as suggested in tutorial I am watching.
Now, when I go to http://localhost:6006/ the page shows
I am on Win10, using python 3.6.6 in Anaconda env, tensorflow 1.10.0.
How can solve this issue?
Following the tutorial on TensorFlow for Poets (Android) (https://codelabs.developers.google.com/codelabs/tensorflow-for-poets-2/#0)
Attempting to use Inception model instead of Mobilenet
Trying to strip DecodeJpeg Op from the retrained model using strip_unused.py, but encountered the following error.
Error:
/home/user/tensorflow/bin/python: Error while finding spec for 'tensorflow.python.tools.strip_unused.py' (AttributeError: module 'tensorflow.python.tools.strip_unused' has no attribute '__path__')
Command line:
python -m tensorflow.python.tools.strip_unused.py --input_graph=tf_files/retrained_graph.pb --output_graph=tf_files/stripped_graph.pb --input_node_names="Mul" --output_node_names="final_result" --input_binary=true
Machine:
Ubuntu 16.04 LTS
Python 3.5.2
TensorFlow 1.4.1
Any assistance is greatly appreciated. Thanks!
Might be due to the typo mistake as file extension .py was specified. This seemed to work:
python -m tensorflow.python.tools.strip_unused --input_graph=tf_files/retrained_graph.pb --output_graph=tf_files/stripped_graph.pb --input_node_names="Mul" --output_node_names="final_result" --input_binary=true
Result: 997 ops in the final graph.