TypeError: 'AutoTrackable' object is not callable - tensorflow

I am trying to run inference on my trained model following this tutorial. I am using TF 2.1.0 and I have tried with tf-nightly 2.5.0.dev20201202.
But I get TypeError: 'AutoTrackable' object is not callable when I hit the following line detections = detect_fn(input_tensor)
I am aware that
'AutoTrackable' object is not callable in Python
exists but I am not using tensorflow hub and I don't understand how the answer could help me.
Thanks

Try using detect_fn.signatures\['default'](input_tensor)

Changing detections = detect_fn(input_tensor) to
detections = detect_fn.signatures['serving_default'](input_tensor)
fixed the issue for me.

Related

How to implement tensorflow cosine_decay

When I call the cosine_decay function in tensorflow, it shows this error:
'<' not supported between instances of 'CosineDecay' and 'int'
Here is my code:
decay_steps = 1000
lr_decayed_fn = tf.keras.experimental.CosineDecay(initial_learning_rate=0.01, decay_steps=1000)
model.compile(optimizer=Adam(lr=lr_decayed_fn), loss=dice_coef_loss, metrics=[dice_coef])
I just followed the tutorial on tensorflow and I don't know why there is this error
Change Adam(lr=lr_decayed_fn) to Adam(learning_rate=lr_decayed_fn)
The Adam optimizer call in tensorflow v2 needs learning_rate to be spelled out, it does not take the argument as "lr." See this issue: https://github.com/tensorflow/tensorflow/issues/44172

How to fix AttributeError: module 'tensorflow' has no attribute 'keras'?

I'm following a basic tensorflow tutorial (to recognize the 28x28 pixel handwritten digits 0-9), but when I run these two lines:
import tensorflow as tf
mnist = tf.keras.datasets.mnist
I get the error message
AttributeError: module 'tensorflow' has no attribute 'keras'
I've looked at posts where people have similar questions, and it seems the answers are usually to update your tensorflow and keras version, but I think I did that already, and this error message is still appearing. How can I resolve this issue?
I think you have typo there.
Should change this line:
mnist = tf.kera.datasets.mnist
to:
mnist = tf.keras.datasets.mnist
Notice that I change kera to keras

Problem in Keras with 'merge' - TypeError: 'module' object is not callable

I tried to merge layer3, layer4 and layer5 with following line of code:
layer = merge([layer3,layer4,layer5],mode='sum')
But it throws this error:
show the TypeError: 'module' object is not callable
Why is my code not working?
I assume you're trying to run source code written for an older Keras version. 'sum' just adds your layers element wise. You could also use TensorFlow to do the same:
layer = tf.add(layer3, layer4)
layer = tf.add(layer, layer5)

AttributeError: module 'tensorflow.contrib.lite.python.convert_saved_model' has no attribute 'convert'

I am trying to convert my premade DNN Model to tflite file, using the function:
from tensorflow.contrib.lite.python import convert_saved_model
convert_saved_model.convert(saved_model_dir=saved_model, output_tflite="/TF_Lite_Model")
I have the last verison of tensorflow installed 1.10
I am using UBUNTU 16.04
the error is the following:
AttributeError: module 'tensorflow.contrib.lite.python.convert_saved_model' has no attribute 'convert'
The API for converting SavedModels to TensorFlow Lite FlatBuffers is TocoConverter.from_saved_model as documented here. The documentation has been copied below.
To provide a general explanation. from_saved_model is a classmethod that returns a TocoConverter object. TocoConverter has a function convert. convert_saved_model is a function and therefore does not have its own convert function.
Copied from documentation:
The following example shows how to convert a SavedModel into a TensorFlow Lite FlatBuffer.
import tensorflow as tf
converter = tf.contrib.lite.TocoConverter.from_saved_model(saved_model_dir)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)
For more complex SavedModels, the optional parameters that can be passed into TocoConverter.from_saved_model() are input_arrays, input_shapes, output_arrays, tag_set and signature_key. Details of each parameter are available by running help(tf.contrib.lite.TocoConverter).
I had to compile the tflite contrib module as it was missing on my repo.

how to create a tf.layers.Dense object

I want to create a dense layer in tensorflow. I tried tf.layers.dense(input_placeholder, units) which will directly create this layer and get result, but what I want is just a "layer module", i.e. an object of the class tf.layers.Dense(units). I want to first declare these modules/layers in a class, and then to have several member functions apply1(x, y), apply2(x,y) to use these layers.
But when I did in tensorflow tf.layers.Dense(units), it returned:
layer = tf.layers.Dense(100) AttributeError: 'module' object has no
attribute 'Dense'
But if I do tf.layers.dense(x, units), there's no problem.
Any help is appreciated, thanks.
tf.layers.Dense returns a function object that you later apply to your input. It performs variable definitions.
func = tf.layers.Dense(out_dim)
out = func(inputs)
tf.layers.dense performs both variable definitions and application of the dense layer to your input to calculate your output.
out = tf.layers.dense(inputs, out_dim)
Try to avoid the usage of placeholders, you have to feed_dict into the tf.Session so its probably causing this issue.
Try to use the new estimator api to load the data and then use dense layers as is done in the tensorflow's github examoples: [https://github.com/tensorflow/tensorflow/blob/master/tensorflow/examples/tutorials/layers/cnn_mnist.py]:
tf.layers.Dense was not exported in TensorFlow before version 1.4. You probably have version 1.3 or earlier installed. (You can check the version with python -c 'import tensorflow as tf; print(tf.__version__)'.)