I’ve recently manage to train a custom object detection model in Tensorflow using ssd_mobilenet_v1_coco_11_06_2017. I used TensorRT to get an optimized model and I ran into this problem while trying to do inference with the optimized model:
tegra@nvidia:~/marco/Object_detection$ python3 TRT_object_detection.py
2019-06-20 10:12:14.683101: W tensorflow/core/platform/profile_utils/cpu_utils.cc:98] Failed to find bogomips in /proc/cpuinfo; cannot determine CPU frequency
2019-06-20 10:12:14.684393: I tensorflow/compiler/xla/service/service.cc:161] XLA service 0x3633da60 executing computations on platform Host. Devices:
2019-06-20 10:12:14.684769: I tensorflow/compiler/xla/service/service.cc:168] StreamExecutor device (0): <undefined>, <undefined>
2019-06-20 10:12:14.844122: I tensorflow/stream_executor/cuda/cuda_gpu_executor.cc:965] ARM64 does not support NUMA - returning NUMA node zero
2019-06-20 10:12:14.844629: I tensorflow/compiler/xla/service/service.cc:161] XLA service 0x363a7ef0 executing computations on platform CUDA. Devices:
2019-06-20 10:12:14.844699: I tensorflow/compiler/xla/service/service.cc:168] StreamExecutor device (0): NVIDIA Tegra X2, Compute Capability 6.2
2019-06-20 10:12:14.845794: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1433] Found device 0 with properties:
name: NVIDIA Tegra X2 major: 6 minor: 2 memoryClockRate(GHz): 1.02
pciBusID: 0000:00:00.0
totalMemory: 7.68GiB freeMemory: 5.47GiB
2019-06-20 10:12:14.845874: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1512] Adding visible gpu devices: 0
2019-06-20 10:12:17.879692: I tensorflow/core/common_runtime/gpu/gpu_device.cc:984] Device interconnect StreamExecutor with strength 1 edge matrix:
2019-06-20 10:12:17.879818: I tensorflow/core/common_runtime/gpu/gpu_device.cc:990] 0
2019-06-20 10:12:17.879886: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1003] 0: N
2019-06-20 10:12:17.880243: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1115] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 4730 MB memory) -> physical GPU (device: 0, name: NVIDIA Tegra X2, pci bus id: 0000:00:00.0, compute capability: 6.2)
2019-06-20 10:12:19.962506: W ./tensorflow/core/grappler/optimizers/graph_optimizer_stage.h:241] Failed to run optimizer ArithmeticOptimizer, stage RemoveStackStridedSliceSameAxis node Preprocessor/ResizeToRange/strided_slice_3. Error: Pack node (Preprocessor/ResizeToRange/stack_2) axis attribute is out of bounds: 0
2019-06-20 10:12:22.387329: W ./tensorflow/core/grappler/optimizers/graph_optimizer_stage.h:241] Failed to run optimizer ArithmeticOptimizer, stage RemoveStackStridedSliceSameAxis node Preprocessor/ResizeToRange/strided_slice_3. Error: Pack node (Preprocessor/ResizeToRange/stack_2) axis attribute is out of bounds: 0
Traceback (most recent call last):
File "/home/tegra/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1334, in _do_call
return fn(*args)
File "/home/tegra/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1319, in _run_fn
options, feed_dict, fetch_list, target_list, run_metadata)
File "/home/tegra/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1407, in _call_tf_sessionrun
run_metadata)
tensorflow.python.framework.errors_impl.InvalidArgumentError: {{node BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/ClipToWindow/Gather/GatherV2_1}} has inputs from different frames. The input {{node BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/Gather_1/GatherV2/axis}} is in frame 'BatchMultiClassNonMaxSuppression/map/while/while_context'. The input {{node BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/FilterGreaterThan/Gather/GatherV2_1}} is in frame ''.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "TRT_object_detection.py", line 106, in <module>
feed_dict={image_tensor: frame_expanded})
File "/home/tegra/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 929, in run
run_metadata_ptr)
File "/home/tegra/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1152, in _run
feed_dict_tensor, options, run_metadata)
File "/home/tegra/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1328, in _do_run
run_metadata)
File "/home/tegra/.local/lib/python3.6/site-packages/tensorflow/python/client/session.py", line 1348, in _do_call
raise type(e)(node_def, op, message)
tensorflow.python.framework.errors_impl.InvalidArgumentError: node BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/ClipToWindow/Gather/GatherV2_1 (defined at TRT_object_detection.py:70) has inputs from different frames. The input node BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/Gather_1/GatherV2/axis (defined at TRT_object_detection.py:70) is in frame 'BatchMultiClassNonMaxSuppression/map/while/while_context'. The input node BatchMultiClassNonMaxSuppression/map/while/MultiClassNonMaxSuppression/FilterGreaterThan/Gather/GatherV2_1 (defined at TRT_object_detection.py:70) is in frame ''.
I think it is caused because i used this lines to get the input and output tensors in the model in my inference code:
# Define input and output tensors (i.e. data) for the object detection classifier
# Input tensor is the image
image_tensor = detection_graph.get_tensor_by_name('image_tensor:0')
# Output tensors are the detection boxes, scores, and classes
# Each box represents a part of the image where a particular object was detected
detection_boxes = detection_graph.get_tensor_by_name('detection_boxes:0')
# Each score represents level of confidence for each of the objects.
# The score is shown on the result image, together with the class label.
detection_scores = detection_graph.get_tensor_by_name('detection_scores:0')
detection_classes = detection_graph.get_tensor_by_name('detection_classes:0')
# Number of objects detected
num_detections = detection_graph.get_tensor_by_name('num_detections:0')
# Load image using OpenCV and
# expand image dimensions to have shape: [1, None, None, 3]
# i.e. a single-column array, where each item in the column has the pixel RGB value
image = cv2.imread(PATH_TO_IMAGE)
image_expanded = np.expand_dims(image, axis=0)
# Perform the actual detection by running the model with the image as input
(boxes, scores, classes, num) = sess.run(
[detection_boxes, detection_scores, detection_classes, num_detections],
feed_dict={image_tensor: image_expanded})
How could I get the correct name for the input and output tensors for the new model? If that’s not the problem, what could it be?
Thanks in advance for any help given or advice.