I have written a ros2 python service node. In this node I want to use functionalities from another python project so I can run inference using a pretrained model with the node. I have cloned the git repository into my /ros2_ws under source. This is my node:
import rclpy
from rclpy.node import Node
from inference_interfaces.srv import Inference
#SPIGA INCLDUES:
import cv2
import numpy as np
from SPIGA.spiga.inference.config import ModelConfig
from SPIGA.spiga.inference.framework import SPIGAFramework
import copy
class Inference_Service(Node):
def __init__(self):
super().__init__('inference_service')
self.srv = self.create_service(Inference, 'inference', self.inference_callback)
#instatiating processor:
dataset = 'wflw'
self.processor = SPIGAFramework(ModelConfig(dataset, load_model_url=False))
def inference_callback(self, request, response):
features = self.processor.inference(request.image, request.bbox)
# Prepare variables
response.landmarks = np.array(features['landmarks'][0])
response.headpose = np.array(features['headpose'][0])
return response
def main(args=None):
rclpy.init(args=args)
inference = Inference_Service()
rclpy.spin(inference)
rclpy.shutdown()
if __name__ == '__main__':
main()
The layout of my /ros2_ws looks like the following:
-ros2_ws
--src
---py_inference_service
---cpp_inference_client
---inference_interfaces
---SPIGA
Im working in the py_inference_service package and I want to include modules from my SPIGA repository. When I do this using the "from SPIGA.spiga.inference.config import ModelConfig" it builds using colcon but when i try to run the code it tells me:
File "/home/victor/ros2_ws/install/py_inference_service/lib/python3.10/site-packages/py_inference_service/service_memberfunction.py", line 9, in
from SPIGA.spiga.inference.config import ModelConfig
ModuleNotFoundError: No module named 'SPIGA'
In my package.xml I have linked SPIGA as a dependency. Can anyone tell me what Im doing wrong?
The issue i was faceing was standard python filepath issues. Because I was working in my ros workspace the root folder wherent where I thought. I solved the issue using a workaround tho where I used pip to install my source file as a local library.