Cant load custom keras model in Jetson Nano

Hello, I built and test a digit detection DL model in Google Colab and I would like to load the model the same way as in my Jetson Nano as shown. However I encounter multiple errors.

Inside the folder modelTrained_textDetection_100 there are 2 more folders (assets and variables) and one file saved_model.pb.

I have attempted a lot methods but it still won’t work. Please guide me through how to import my model the right way.

Thanks

Hi,

Would you mind to share the error log with us?
Thanks.

`---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/execute.py in make_shape(v, arg_name)
210 try:
–> 211 shape = tensor_shape.as_shape(v)
212 except TypeError as e:

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/tensor_shape.py in as_shape(shape)
1210 else:
-> 1211 return TensorShape(shape)
1212

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/tensor_shape.py in init(self, dims)
770 else:
–> 771 self._dims = [as_dimension(d) for d in dims_iter]
772

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/tensor_shape.py in (.0)
770 else:
–> 771 self._dims = [as_dimension(d) for d in dims_iter]
772

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/tensor_shape.py in as_dimension(value)
715 else:
–> 716 return Dimension(value)
717

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/framework/tensor_shape.py in init(self, value)
199 “an index method, got {!r}”.format(value)),
–> 200 None)
201 if self._value < 0:

/usr/local/lib/python3.6/dist-packages/six.py in raise_from(value, from_value)

TypeError: Dimension value must be integer or None or have an index method, got ‘class_name’

During handling of the above exception, another exception occurred:

TypeError Traceback (most recent call last)
in
----> 1 model = keras.models.load_model("/home/jetbot/Notebooks/digit_detection/modelTrained_textDetection_100")
2 # Show its architecture
3 model.summary()

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/save.py in load_model(filepath, custom_objects, compile)
148 if isinstance(filepath, six.string_types):
149 loader_impl.parse_saved_model(filepath)
–> 150 return saved_model_load.load(filepath, compile)
151
152 raise IOError(

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/saved_model/load.py in load(path, compile)
87 # TODO(kathywu): Add saving/loading of optimizer, compiled losses and metrics.
88 # TODO(kathywu): Add code to load from objects that contain all endpoints
—> 89 model = tf_load.load_internal(path, loader_cls=KerasObjectLoader)
90
91 # pylint: disable=protected-access

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/saved_model/load.py in load_internal(export_dir, tags, loader_cls)
550 loader = loader_cls(object_graph_proto,
551 saved_model_proto,
–> 552 export_dir)
553 root = loader.get(0)
554 root.tensorflow_version = meta_graph_def.meta_info_def.tensorflow_version

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/saved_model/load.py in init(self, *args, **kwargs)
117 def init(self, *args, **kwargs):
118 super(KerasObjectLoader, self).init(*args, **kwargs)
–> 119 self._finalize()
120
121 def _finalize(self):

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/saving/saved_model/load.py in _finalize(self)
149 node._layers =
150 for layer in node.keras_api.layers:
–> 151 node.add(layer)
152 elif is_graph_network:
153 # Reconstruct functional model from the config and layers loaded

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/training/tracking/base.py in _method_wrapper(self, *args, **kwargs)
455 self._self_setattr_tracking = False # pylint: disable=protected-access
456 try:
–> 457 result = method(self, *args, **kwargs)
458 finally:
459 self._self_setattr_tracking = previous_value # pylint: disable=protected-access

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/sequential.py in add(self, layer)
179 # Instantiate an input layer.
180 x = input_layer.Input(
–> 181 batch_shape=batch_shape, dtype=dtype, name=layer.name + ‘_input’)
182 # This will build the current layer
183 # and create the node connecting the current layer

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/input_layer.py in Input(shape, batch_size, name, dtype, sparse, tensor, ragged, **kwargs)
268 ‘dimension.’)
269
–> 270 input_layer = InputLayer(**input_layer_config)
271
272 # Return tensor including _keras_history.

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/engine/input_layer.py in init(self, input_shape, batch_size, dtype, input_tensor, sparse, name, ragged, **kwargs)
125 name=self.name,
126 sparse=sparse,
–> 127 ragged=ragged)
128
129 self.is_placeholder = True

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/keras/backend.py in placeholder(shape, ndim, dtype, sparse, name, ragged)
1052 expand_composites=True)
1053 else:
-> 1054 x = array_ops.placeholder(dtype, shape=shape, name=name)
1055 return x
1056

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/array_ops.py in placeholder(dtype, shape, name)
2716 “eager execution.”)
2717
-> 2718 return gen_array_ops.placeholder(dtype=dtype, shape=shape, name=name)
2719
2720

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/ops/gen_array_ops.py in placeholder(dtype, shape, name)
6028 if shape is None:
6029 shape = None
-> 6030 shape = _execute.make_shape(shape, “shape”)
6031 _, _, _op, _outputs = _op_def_library._apply_op_helper(
6032 “Placeholder”, dtype=dtype, shape=shape, name=name)

/usr/local/lib/python3.6/dist-packages/tensorflow_core/python/eager/execute.py in make_shape(v, arg_name)
211 shape = tensor_shape.as_shape(v)
212 except TypeError as e:
–> 213 raise TypeError(“Error converting %s to a TensorShape: %s.” % (arg_name, e))
214 except ValueError as e:
215 raise ValueError(“Error converting %s to a TensorShape: %s.” % (arg_name,

TypeError: Error converting shape to a TensorShape: Dimension value must be integer or None or have an index method, got ‘class_name’.`

I installed TensorFlow 2.1 for Jetpack 4.3 but I think I needed TensorFlow 2.2 for my keras to work. What can I do?

Hi,

TypeError: Error converting shape to a TensorShape: Dimension value must be integer or None or have an index method, got ‘class_name’.`

According to the log, it seems the issue comes from the app rather than frameworks.
Have you run the app successfully on other platform?

More, please noticed that you will need to install the package built on same JetPack version to ensure compatibility.
For v2.2, please use JetPack4.4 with 2.2.0+nv20.6 or 2.2.0+nv20.7 file here:
https://developer.download.nvidia.com/compute/redist/jp/v44/tensorflow/

Thanks.

Hi,

I am using JetPack4.3 and install tensorflow 2.1.0. What can I do to download this?

JetPack4.4 with 2.2.0+nv20.6 or 2.2.0+nv20.7 file

Thanks

Hi,

You can flash and install the device with JetPack 4.4 via SDKManager:

After that, please setup TensorFlow with this document:
https://docs.nvidia.com/deeplearning/frameworks/install-tf-jetson-platform/index.html

For v2.2.0+nv20.7, please use this command:

$ sudo pip3 install --pre --extra-index-url https://developer.download.nvidia.com/compute/redist/jp/v44 tensorflow==2.2.0+nv20.7

Thanks.

Hi,
I need a help on a similar problem. I have a working python code on windows, while i am trying to get it up on Jetson Nano, I am facing below error.

crevavi@crevavi-desktop:~/Desktop/PC_Based_Object_Detection$ python object_detetion.py
Using TensorFlow backend.
2020-09-29 17:49:48.656875: I tensorflow/stream_executor/platform/default/dso_loader.cc:48] Successfully opened dynamic library libcudart.so.10.2
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (711) open OpenCV | GStreamer warning: Error opening bin: no element “C:”
[ WARN:0] global /home/nvidia/host/build_opencv/nv_opencv/modules/videoio/src/cap_gstreamer.cpp (480) isPipelinePlaying OpenCV | GStreamer warning: GStreamer: pipeline have not been created
Traceback (most recent call last):
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py”, line 66, in _get_default_graph
return tf.get_default_graph()
AttributeError: module ‘tensorflow’ has no attribute ‘get_default_graph’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “object_detetion.py”, line 108, in
model = load_model(‘full_CNN_model.h5’)
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/engine/saving.py”, line 458, in load_wrapper
return load_function(*args, **kwargs)
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/engine/saving.py”, line 550, in load_model
model = _deserialize_model(h5dict, custom_objects, compile)
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/engine/saving.py”, line 243, in _deserialize_model
model = model_from_config(model_config, custom_objects=custom_objects)
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/engine/saving.py”, line 593, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/layers/init.py”, line 168, in deserialize
printable_module_name=‘layer’)
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/utils/generic_utils.py”, line 147, in deserialize_keras_object
list(custom_objects.items())))
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/engine/sequential.py”, line 298, in from_config
model = cls(name=name)
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/engine/sequential.py”, line 88, in init
super(Sequential, self).init(name=name)
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/legacy/interfaces.py”, line 91, in wrapper
return func(*args, **kwargs)
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/engine/network.py”, line 97, in init
self._init_subclassed_network(**kwargs)
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/engine/network.py”, line 300, in _init_subclassed_network
self._base_init(name=name, **kwargs)
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/engine/network.py”, line 110, in base_init
name = prefix + '
’ + str(K.get_uid(prefix))
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py”, line 86, in get_uid
graph = _get_default_graph()
File “/home/crevavi/.local/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py”, line 69, in _get_default_graph
'It looks like you are trying to use ’
RuntimeError: It looks like you are trying to use a version of multi-backend Keras that does not support TensorFlow 2.0. We recommend using tf.keras, or alternatively, downgrading to TensorFlow 1.14.

Could you pls guide me what may be going wrong?

In fact i tried changing to
from tensorflow.keras.models import load_model
getting below error:

Traceback (most recent call last):
File “object_detetion.py”, line 108, in
model = load_model(‘full_CNN_model.h5’)
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/saving/save.py”, line 184, in load_model
return hdf5_format.load_model_from_hdf5(filepath, custom_objects, compile)
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/saving/hdf5_format.py”, line 178, in load_model_from_hdf5
custom_objects=custom_objects)
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/saving/model_config.py”, line 55, in model_from_config
return deserialize(config, custom_objects=custom_objects)
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/layers/serialization.py”, line 109, in deserialize
printable_module_name=‘layer’)
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/generic_utils.py”, line 362, in deserialize_keras_object
config, module_objects, custom_objects, printable_module_name)
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/utils/generic_utils.py”, line 325, in class_and_config_for_serialized_keras_object
for key, item in cls_config.items():
AttributeError: ‘list’ object has no attribute ‘items’

Hi sunil76joshi,

Please help to open a new topic for your issue. Thanks