Runnining model.py from the directory /usr/src/tensorrt/samples/python/end_to_end_tensorflow_mnist gives error

Hi all, the execution of the statement (x_train, y_train),(x_test, y_test) = tf.keras.datasets.mnist.load_data() from the file model.py from the dirctory /usr/src/tensorrt/samples/python/end_to_end_tensorflow_mnist

is giving below error. Let me know what error it is and what is the fix for it.

/usr/src/tensorrt/samples/python/end_to_end_tensorflow_mnist$ python3.6 model.py
Traceback (most recent call last):
File “model.py”, line 65, in
main()
File “model.py”, line 54, in main
x_train, y_train, x_test, y_test = process_dataset()
File “model.py”, line 24, in process_dataset
(x_train, y_train),(x_test, y_test) = tf.keras.datasets.mnist.load_data()
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/lazy_loader.py”, line 62, in getattr
module = self._load()
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/lazy_loader.py”, line 45, in _load
module = importlib.import_module(self.name)
File “/usr/lib/python3.6/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 941, in _find_and_load_unlocked
File “”, line 219, in _call_with_frames_removed
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 941, in _find_and_load_unlocked
File “”, line 219, in _call_with_frames_removed
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 941, in _find_and_load_unlocked
File “”, line 219, in _call_with_frames_removed
File “”, line 994, in _gcd_import
File “”, line 971, in _find_and_load
File “”, line 955, in _find_and_load_unlocked
File “”, line 665, in _load_unlocked
File “”, line 678, in exec_module
File “”, line 219, in _call_with_frames_removed
File “/usr/local/lib/python3.6/dist-packages/keras/init.py”, line 20, in
from keras import distribute
File “/usr/local/lib/python3.6/dist-packages/keras/distribute/init.py”, line 18, in
from keras.distribute import sidecar_evaluator
File “/usr/local/lib/python3.6/dist-packages/keras/distribute/sidecar_evaluator.py”, line 22, in
from keras.optimizers.optimizer_experimental import (
File “/usr/local/lib/python3.6/dist-packages/keras/optimizers/init.py”, line 26, in
from keras.optimizers.legacy import adadelta as adadelta_legacy
File “/usr/local/lib/python3.6/dist-packages/keras/optimizers/legacy/adadelta.py”, line 17, in
from keras.optimizers.optimizer_v2 import adadelta
File “/usr/local/lib/python3.6/dist-packages/keras/optimizers/optimizer_v2/adadelta.py”, line 21, in
from keras.optimizers.optimizer_v2 import optimizer_v2
File “/usr/local/lib/python3.6/dist-packages/keras/optimizers/optimizer_v2/optimizer_v2.py”, line 26, in
from keras import initializers
File “/usr/local/lib/python3.6/dist-packages/keras/initializers/init.py”, line 22, in
from keras.initializers import initializers_v2
File “/usr/local/lib/python3.6/dist-packages/keras/initializers/initializers_v2.py”, line 23, in
from keras.dtensor import utils
File “/usr/local/lib/python3.6/dist-packages/keras/dtensor/init.py”, line 22, in
from tensorflow.compat.v2.experimental import dtensor as dtensor_api
ImportError: cannot import name ‘dtensor’

Ultimately the reason for this error is the execution of the statement
from tensorflow.compat.v2.experimental import dtensor as dtensor_api

in the file

/usr/local/lib/python3.6/dist-packages/keras/dtensor/init.py and its contents are
“”“Keras’ DTensor library.”“”

_DTENSOR_API_ENABLED = True

Conditional import the dtensor API, since it is currently broken in OSS.

if _DTENSOR_API_ENABLED:
from tensorflow.compat.v2.experimental import dtensor as dtensor_api
else:
# Leave it with a placeholder, so that the import line from other python
# file will not break.
dtensor_api = None

Dear @trivedi.nagaraj,
Could you confirm the platform and Jetpack version details?

Hi SivaRamaKrishna, the board is Jetson Nano and the jetpack version is

Package: nvidia-jetpack
Version: 4.6-b199
Priority: standard
Section: metapackages
Maintainer: NVIDIA Corporation
Installed-Size: 199 kB
Depends: nvidia-cuda (= 4.6-b199), nvidia-opencv (= 4.6-b199), nvidia-cudnn8 (= 4.6-b199), nvidia-tensorrt (= 4.6-b199), nvidia-visionworks (= 4.6-b199), nvidia -container (= 4.6-b199), nvidia-vpi (= 4.6-b199), nvidia-l4t-jetson-multimedia-a pi (>> 32.6-0), nvidia-l4t-jetson-multimedia-api (<< 32.7-0)
Homepage: http://developer.nvidia.com/jetson
Download-Size: 29.4 kB
APT-Sources: https://repo.download.nvidia.com/jetson/t194 r32.6/main arm64 Packa ges
Description: NVIDIA Jetpack Meta Package

N: There is 1 additional record. Please use the ‘-a’ switch to see it

Hi SivaRamaKrishna, request you to please update me on this.

Thanks and Regards

Nagaraj Trivedi

Dear @trivedi.nagaraj,
Did you check with Jetpack 4.6.4 release?

Hi SivaRamakrishna, no I have not checked with it. Is there a way by which dtensor can be installed/imported on the existing jetpack version. Otherwise, it makes me to keep updating jetpack version. I am worried about will it affect working/execution of remaining sample programs.

Thanks and Regards

Nagaraj Trivedi

Hi SivaRamaKrishna, I am more worried about updating from one version of Jetpack to another version. Because in this process if some thing happens to the working environment which is already working.
Does NVIDIA provide remote login to the learners/interested people to login to their cloud/lab and try all these?

Thanks and Regards

Nagaraj Trivedi

Dear @trivedi.nagaraj,
Does NVIDIA provide remote login to the learners/interested people to login to their cloud/lab and try all these

We don’t have this facility to give access to jetson boards.

Did you use docker to TF docker to generate frozen graph? If not, could you check that process?

ok I will try to use TF docker.

Thanks and Regards

Nagaraj Trivedi

May I know any useful document how to use TF docker.

Dear @trivedi.nagaraj,
please check the README file in the sample folder. It has details about using docker container.

Hi SivaRamakrishna, I don’t want to use other JETPACK 4.6.4 version and also the docker. Now I don’t to try many versions. On JETPACK 4.6.1 version itself I want this to be working. Let me know how to fix this issue.

ImportError: cannot import name ‘dtensor’

Thanks and Regards

Nagaraj Trivedi

Hi SivaRamaKrishna, please update me on this. It is very urgently required as I have stuck for a month.

Thanks and Regards

N.M.Trivedi

Hi SivaRamaKrishna, please update on this. It has taken more days and blocking my work.

Thanks and Regards

Nagaraj Trivedi

Dear @trivedi.nagaraj,
My apologies for missing this topic.
Using docker container will take care of all the dependent software packages and can run sample as is. We recommend to try that method. Do you see guidance for running sample on docker in README?

Thank you SivaRamaKrishna. I will try and get back to you.

Thanks and Regards

Nagaraj Trivedi

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.