'Share large arrays between python nodes

I am looking for a way to share two fairly large arrays (~1 million floats) from Tensor Flow between two ROS2 nodes. I tried publishing them over a ROS topic using a custom message type containing two arrays. I only got this to work by converting it from a Device Array, to a Numpy Array, to a List, To an Array. And on the receiving side it also would have to be turned into a System Array again. This method seems really inefficient and takes about 0.15 seconds.

What is a better and more efficient way of doing this?

Edit: More info

  • I'm using ROS 2 Foxy on Ubuntu 20.04
  • The nodes are running on the same device in the same ROS environment


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source