I just wrote a simple program to test tensorflow library in my windows 10.
It is running well but only problem is that I am not being able to use tensorboard to visualize graphs.
Following is my code
import tensorflow as tf
a = tf.constant(5, name="input_a")
b = tf.constant(3, name="input_b")
c = tf.mul(a,b, name="mul_c")
d = tf.add(a,b, name="add_d")
e = tf.add(c,d, name="add_e")
sess = tf.Session()
output = sess.run(e)
writer = tf.train.SummaryWriter('./my_graph', sess.graph)
writer.close()
sess.close()
Error log
AttributeError Traceback (most recent call last)
<ipython-input-13-5c6b380c18c8> in <module>()
7 sess = tf.Session()
8 output = sess.run(e)
----> 9 writer = tf.train.SummaryWriter('./my_graph', sess.graph)
10 writer.close()
11 sess.close()
/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/summary_io.pyc in __init__(self, logdir, graph_def, max_queue, flush_secs)
/usr/local/lib/python2.7/dist-packages/tensorflow/python/training/summary_io.pyc in add_graph(self, graph_def, global_step)
AttributeError: 'Graph' object has no attribute 'SerializeToString'
Tensorflow version
In[14:]:tf.__version__
Out[14]:'0.7.1'
Tensorflow library upgrade
When I tried to upgrade tensorflow library to latest 0.12 using pip in jupyter notebook it downloaded and installed lot of stuffs and after that I again tested the version but it was same.So I again tried to upgrade but it displayed following message.
Requirement already up-to date
How to get out of this mess?
Related
Protobuf v3.15 Error: google.protobuf.message.DecodeError, When using tf.graph(), loading TensorFlow model into memory. After changing tf.graph() snippet above into TensorFlow v2, same error was getting.
I have tried protobuf 3.12.4(same on colabs), same error appeared
Traceback (most recent call last):
File "object_detection/webcam.py", line 25, in <module>
od_graph_def.ParseFromString(serialized_graph)
google.protobuf.message.DecodeError: Error parsing message
[ WARN:0] global C:\projects\opencv-python\opencv\modules\videoio\src\cap_msmf.cpp (674) SourceReaderCB::~SourceReaderCB terminating async callback
I have reinstalled different protobuf version and still same error is getting.
I have trained a "SSD MobileNet" model using TensorFlow version 1.14 CPU for Webcam Object-detection with OpenCV. After installing required libraries of TensorFlow, I run model_builder_tf1.py and it successfully passed all 21 tests.
Snippet: to load TensorFlow model into memory using tf.graph()
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.compat.v1.GraphDef()
with tf.gfile.GFile(PATH_TO_FROZEN_GRAPH, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
sess = tf.compat.v1.Session(graph=detection_graph)
Note that TensorFlow 1.14 is installed on conda environment.
Using protobuf==3.8, another of error appeared
AttributeError: module 'google.protobuf.descriptor' has no attribute '_internal_create_key
Can someone please give a solution to this problem.
I am using the following function in part of object detection application I am working on
detection_graph = tf.Graph()
with detection_graph.as_default():
od_graph_def = tf.GraphDef()
with tf.gfile.GFile(PATH_TO_FROZEN_GRAPH, 'rb') as fid:
serialized_graph = fid.read()
od_graph_def.ParseFromString(serialized_graph)
tf.import_graph_def(od_graph_def, name='')
When I run this code I get the following error :
AttributeError Traceback (most recent call last)
<ipython-input-6-d55b98fd5a78> in <module>
1 detection_graph = tf.Graph()
2 with detection_graph.as_default():
----> 3 od_graph_def = tf.GraphDef()
4 with tf.gfile.GFile(PATH_TO_FROZEN_GRAPH, 'rb') as fid:
5 serialized_graph = fid.read()
AttributeError: module 'tensorflow' has no attribute 'GraphDef'
I am using TensorFlow 2.0.0. Is this a version mismatch related?
This code is from the following link.
Yes, it is a version mismatch issue, you should not blindly assume that every library supports TensorFlow 2.0, which was only recently released.
If a library does not advertise explicit support for TensorFlow 2.0, then you should just use it with TensorFlow 1.x
Make sure you have properly installed the libraries as given in link,
https://github.com/tensorflow/models/blob/master/research/object_detection/g3doc/installation.md
I am using tf.kaeras in google colab with python3.0 notebook and getting the error with the following code:
model = tf.keras.Model(inputs=[Inp], outputs=[output])
tpu_model = tf.contrib.tpu.keras_to_tpu_model(
model,
strategy=tf.contrib.tpu.TPUDistributionStrategy(
tf.contrib.cluster_resolver.TPUClusterResolver(
tpu='grpc://' + os.environ['COLAB_TPU_ADDR'])
)
)
tpu_model.fit(
train_input_fn,
steps_per_epoch = 60,
epochs=epochs)
And the error message is
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-11-d6a0cf977e09> in <module>()
2 train_input_fn,
3 steps_per_epoch = 60,
----> 4 epochs=epochs)
5
6 score = tpu_model.evaluate(x_test, y_test, verbose=0)
3 frames
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in run_eagerly(self)
399 Boolean, whether the model should run eagerly.
400 """
--> 401 if self._run_eagerly is True and not context.executing_eagerly():
402 raise ValueError('You can only set `run_eagerly=True` if eager execution '
403 'is enabled.')
AttributeError: 'KerasTPUModel' object has no attribute '_run_eagerly'
INFO:
I get this error in google colab. Here is the Python and tensorflow version.
import sys
import tensorflow as tf
print("Python Version:", sys.version_info)
print("TensorFlow Version:", tf.__version__)
Python Version: sys.version_info(major=3, minor=6, micro=7, releaselevel='final', serial=0)
TensorFlow Version: 1.14.0-rc1
I created a TensorFlow estimator:
outlier_estimator = tf.estimator.BoostedTreesClassifier(
n_batches_per_layer = 15,
feature_columns=outlier_feature_columns,
model_dir="./tensorboard_logs/wifi_outliers/",
n_classes=2
)
and saved it:
def serving_input_receiver_fn():
inputs = {
"signal_0": tf.placeholder(shape=[1], dtype=tf.float32, name="signal_0"),
"signal_1": tf.placeholder(shape=[1], dtype=tf.float32, name="signal_1")
}
return tf.estimator.export.ServingInputReceiver(inputs, inputs)
outlier_estimator.export_savedmodel(export_dir_base="./export/", serving_input_receiver_fn=serving_input_receiver_fn)
But when I try to load saved model
tf.reset_default_graph()
with tf.Session() as sess:
tf.saved_model.loader.load(
sess,
[tf.saved_model.tag_constants.SERVING],
"./export/1551699998"
)
I faced an error:
KeyError: "The name 'boosted_trees/QuantileAccumulator/' refers to an
Operation not in the graph."
What am I doing wrong?
I'm using:
Python 3.7
tensorflow 1.13.1
I faced the same problem. Updating my Tensorflow version to Tensorflow 2 (precisely tf 2.1.0) solved the problem
I tried to run the following code in Jupyter Notebook, however I got the InvalidArgumentError for the placeholder.
But when I wrote a Python script and ran it in command window, it worked. I want to know how can I ran my code in the Notebook successfully, thanks.
OS: Ubuntu 16.04 LTS
Tensorflow version: 0.12rc (installed from source)
Programs and Output:
Command window:
Actural code:
import tensorflow as tf
import numpy as np
raw_data = np.random.normal(10, 1, 100)
# Define alpha as a constant
alpha = tf.constant(0.05)
# A placeholder is just like a variable, but the value is injected from the
# session
curr_value = tf.placeholder(tf.float32)
# Initialize the previous average to some
prev_avg = tf.Variable(0.)
avg_hist = tf.summary.scalar("running_average", update_avg)
value_hist = tf.summary.scalar("incoming_values", curr_value)
merged = tf.summary.merge_all()
writer = tf.summary.FileWriter("./logs")
init = tf.global_variables_initializer()
with tf.Session() as sess:
sess.run(init)
for i in range(len(raw_data)):
summary_str, curr_avg = sess.run([merged, update_avg], feed_dict={curr_value: raw_data[i]})
sess.run(tf.assign(prev_avg, curr_avg))
print(raw_data[i], curr_avg)
writer.add_summary(summary_str, i)
Your raw_data is float64 (default numpy float type) whereas your placeholder is float32 (default tensorflow float type). You should explicitly cast your data to float32