Error following lesson ROS Developers Open Class n.193: Human Pose Estimation with AI in ROS2

I’ve followed this class and all goes well but i’m stuck here:
ros2 run advanced_perception yolo_pose_estimation_node
having this error:
A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.2.6 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with ‘pybind11>=2.12’.

If you are a user of the module, the easiest solution will be to
downgrade to ‘numpy<2’ or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last): File “/home/user/ros2_ws/install/advanced_perception/lib/advanced_perception/yolo_pose_estimation_node”, line 33, in
sys.exit(load_entry_point(‘advanced-perception==0.0.0’, ‘console_scripts’, ‘yolo_pose_estimation_node’)())
File “/home/user/ros2_ws/install/advanced_perception/lib/advanced_perception/yolo_pose_estimation_node”,line 25, in importlib_load_entry_point
return next(matches).load()
File “/usr/lib/python3.10/importlib/metadata/init.py”, line 171, in load
module = import_module(match.group(‘module’))
File “/usr/lib/python3.10/importlib/init.py”, line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File “/home/user/ros2_ws/install/advanced_perception/lib/python3.10/site-packages/advanced_perception/yolo_pose_estimation.py”, line 11, in
from cv_bridge import CvBridge
File “/opt/ros/humble/local/lib/python3.10/dist-packages/cv_bridge/init.py”, line 6, in
from cv_bridge.boost.cv_bridge_boost import cvtColorForDisplay, getCvType
AttributeError: _ARRAY_API not found

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.2.6 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with ‘pybind11>=2.12’.

If you are a user of the module, the easiest solution will be to
downgrade to ‘numpy<2’ or try to upgrade the affected module.
We expect that some modules will need time to support NumPy 2.

Traceback (most recent call last): File “/home/user/ros2_ws/install/advanced_perception/lib/advanced_perception/yolo_pose_estimation_node”, line 33, in
sys.exit(load_entry_point(‘advanced-perception==0.0.0’, ‘console_scripts’, ‘yolo_pose_estimation_node’)())
File “/home/user/ros2_ws/install/advanced_perception/lib/python3.10/site-packages/advanced_perception/yolo_pose_estimation.py”, line 187, in main
rclpy.spin(pose_estimation)
File “/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/init.py”, line 222, in spin
executor.spin_once()
File “/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py”, line 739, in spin_once
self._spin_once_impl(timeout_sec)
File “/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py”, line 734, in _spin_once_impl
handler()
File “/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/task.py”, line 239, in call
self._handler.send(None)
File “/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py”, line 437, in handler
await call_coroutine(entity, arg)
File “/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py”, line 362, in _execute_subscription
await await_or_execute(sub.callback, msg)
File “/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py”, line 107, in await_or_execute
return callback(*args)
File “/home/user/ros2_ws/install/advanced_perception/lib/python3.10/site-packages/advanced_perception/yolo_pose_estimation.py”, line 63, in image_callback
img = self.bridge.imgmsg_to_cv2(data, “bgr8”)
File “/opt/ros/humble/local/lib/python3.10/dist-packages/cv_bridge/core.py”, line 194, in imgmsg_to_cv2
res = cvtColor2(im, img_msg.encoding, desired_encoding)
AttributeError: _ARRAY_API not found
[ros2run]: Segmentation fault

I’m not following the same class, but I had a similar issue and managed to fix it by downgrading NumPy. You can try running:

pip install "numpy<2"

@frabbit, please let us know if you were able to resolve this issue or if you still need help.

i have this problem now:

user:~$ ros2 run advanced_perception yolo_pose_estimation_node
WARNING ⚠️ user config directory '/home/user/.config/Ultralytics' is not writeable, defaulting to '/tmp' or CWD.Alternatively you can define a YOLO_CONFIG_DIR environment variable for this path.
Creating new Ultralytics Settings v0.0.6 file ✅
View Ultralytics Settings with 'yolo settings' or at '/tmp/Ultralytics/settings.json'
Update Settings with 'yolo settings key=value', i.e. 'yolo settings runs_dir=path/to/dir'. For help see https://docs.ultralytics.com/quickstart/#ultralytics-settings.

^CTraceback (most recent call last):
  File "/home/user/ros2_ws/install/advanced_perception/lib/advanced_perception/yolo_pose_estimation_node", line 33, in <module>
    sys.exit(load_entry_point('advanced-perception==0.0.0', 'console_scripts', 'yolo_pose_estimation_node')())
  File "/home/user/ros2_ws/install/advanced_perception/lib/python3.10/site-packages/advanced_perception/yolo_pose_estimation.py", line 187, in main
    rclpy.spin(pose_estimation)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/__init__.py", line 222, in spin
    executor.spin_once()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 739, in spin_once
    self._spin_once_impl(timeout_sec)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 734, in _spin_once_impl
    handler()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/task.py", line 239, in __call__
    self._handler.send(None)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 437, in handler
    await call_coroutine(entity, arg)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 362, in _execute_subscription
    await await_or_execute(sub.callback, msg)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 107, in await_or_execute
    return callback(*args)
  File "/home/user/ros2_ws/install/advanced_perception/lib/python3.10/site-packages/advanced_perception/yolo_pose_estimation.py", line 65, in image_callback
    results = self.model(img)
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/model.py", line 185, in __call__
    return self.predict(source, stream, **kwargs)
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/model.py", line 555, in predict
    return self.predictor.predict_cli(source=source) if is_cli else self.predictor(source=source, stream=stream)
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/predictor.py", line 227, in __call__
    return list(self.stream_inference(source, model, *args, **kwargs))  # merge list of Result into one
  File "/usr/local/lib/python3.10/dist-packages/torch/utils/_contextlib.py", line 36, in generator_context
    response = gen.send(None)
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/engine/predictor.py", line 308, in stream_inference
    self.model.warmup(
  File "/usr/local/lib/python3.10/dist-packages/ultralytics/nn/autobackend.py", line 856, in warmup
    import torchvision  # noqa (import here so torchvision import time not recorded in postprocess time)
  File "/usr/local/lib/python3.10/dist-packages/torchvision/__init__.py", line 10, in <module>
    from torchvision import _meta_registrations, datasets, io, models, ops, transforms, utils  # usort:skip
  File "/usr/local/lib/python3.10/dist-packages/torchvision/models/__init__.py", line 2, in <module>
    from .convnext import *
  File "/usr/local/lib/python3.10/dist-packages/torchvision/models/convnext.py", line 8, in <module>
    from ..ops.misc import Conv2dNormActivation, Permute
  File "/usr/local/lib/python3.10/dist-packages/torchvision/ops/__init__.py", line 23, in <module>
    from .poolers import MultiScaleRoIAlign
  File "/usr/local/lib/python3.10/dist-packages/torchvision/ops/poolers.py", line 10, in <module>
    from .roi_align import roi_align
  File "/usr/local/lib/python3.10/dist-packages/torchvision/ops/roi_align.py", line 7, in <module>
    from torch._dynamo.utils import is_compile_supported
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/__init__.py", line 13, in <module>
    from . import config, convert_frame, eval_frame, resume_execution
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/convert_frame.py", line 52, in <module>
    from torch._dynamo.symbolic_convert import TensorifyState
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/symbolic_convert.py", line 57, in <module>
    from . import (
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/trace_rules.py", line 32, in <module>
    from .variables import (
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/__init__.py", line 19, in <module>
    from .base import VariableTracker
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/base.py", line 581, in <module>
    from . import builder
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/builder.py", line 86, in <module>
    from ..side_effects import SideEffects
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/side_effects.py", line 21, in <module>
    from .codegen import PyCodegen
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/codegen.py", line 47, in <module>
    from .variables.nn_module import NNModuleVariable
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/nn_module.py", line 72, in <module>
    from .lazy import LazyVariableTracker
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/lazy.py", line 9, in <module>
    from .tensor import SymNodeVariable
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/variables/tensor.py", line 35, in <module>
    from torch._dynamo import compiled_autograd
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/compiled_autograd.py", line 162, in <module>
    class AutogradCompilerInstance:
  File "/usr/local/lib/python3.10/dist-packages/torch/_dynamo/compiled_autograd.py", line 1187, in AutogradCompilerInstance
    self, objects, proxies, origins: Optional[list[tuple[int, str]]] = None
  File "/usr/lib/python3.10/typing.py", line 309, in inner
    return cached(*args, **kwds)
  File "/usr/lib/python3.10/typing.py", line 401, in __getitem__
    @_tp_cache
KeyboardInterrupt
[ros2run]: Interrupt
user:~$ ros2 run advanced_perception yolo_pose_estimation_node
Creating new Ultralytics Settings v0.0.6 file ✅
View Ultralytics Settings with 'yolo settings' or at '/home/user/.config/Ultralytics/settings.json'
Update Settings with 'yolo settings key=value', i.e. 'yolo settings runs_dir=path/to/dir'. For help see https://docs.ultralytics.com/quickstart/#ultralytics-settings.

0: 480x640 (no detections), 2869.1ms
Speed: 22.4ms preprocess, 2869.1ms inference, 9.6ms postprocess per image at shape (1, 3, 480, 640)
Traceback (most recent call last):
  File "/home/user/ros2_ws/install/advanced_perception/lib/advanced_perception/yolo_pose_estimation_node", line 33, in <module>
    sys.exit(load_entry_point('advanced-perception==0.0.0', 'console_scripts', 'yolo_pose_estimation_node')())
  File "/home/user/ros2_ws/install/advanced_perception/lib/python3.10/site-packages/advanced_perception/yolo_pose_estimation.py", line 187, in main
    rclpy.spin(pose_estimation)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/__init__.py", line 222, in spin
    executor.spin_once()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 739, in spin_once
    self._spin_once_impl(timeout_sec)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 736, in _spin_once_impl
    raise handler.exception()
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/task.py", line 239, in __call__
    self._handler.send(None)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 437, in handler
    await call_coroutine(entity, arg)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 362, in _execute_subscription
    await await_or_execute(sub.callback, msg)
  File "/opt/ros/humble/local/lib/python3.10/dist-packages/rclpy/executors.py", line 107, in await_or_execute
    return callback(*args)
  File "/home/user/ros2_ws/install/advanced_perception/lib/python3.10/site-packages/advanced_perception/yolo_pose_estimation.py", line 85, in image_callback
    keypoints = results[0].keypoints.xy.cpu().numpy()[0]
IndexError: index 0 is out of bounds for axis 0 with size 0
[ros2run]: Process exited with failure 1

It appears that the problem here is that there were no detections. Perhaps some nodes are not running, and/or settings are missing or misconfigured?