Hi all,
I’m deploying Torchserve as service on local server. To optimize time processing in sending image data to Torchserve (my image size is about 2000x2000), I send request (REST API) to my Torchserve by sending image path. However, the Torchserve can not read the input image path. The Torchserve doesn’t know where is the image path, even I put image file to “model-store” directory that contains model in .mar format.
So my question is how to setup Torchserve can read image file in expected directory?
If it is possible, I also want to save the output as image file to other directory.
Thank you!
For more detail, please refer to my source code of Torchserve handler in below:
class VTO(BaseHandler):
def initialize(self, context):
"""Initialize function loads the model.pt file and initialized the model object.
First try to load torchscript else load eager mode state_dict based model.
Args:
context (context): It is a JSON Object containing information
pertaining to the model artifacts parameters.
Raises:
RuntimeError: Raises the Runtime error when the model.py is missing
"""
properties = context.system_properties
self.manifest = context.manifest
self.map_location = "cuda" if torch.cuda.is_available() else "cpu"
self.device = torch.device(
# self.map_location + ":" + str(properties.get("gpu_id"))
self.map_location + ":0"
if torch.cuda.is_available()
else self.map_location
)
self.transform = MLSDeformation()
self.initialized = True
def preprocess(self, requests):
preprocessed_data = []
for req in requests:
data = req.get("data") or req.get("body")
### Final ###
## data_str = data.decode("utf-8")
data_obj = json.loads(data)
### Get image path ###
img_path = data_obj['image']
print(img_path)
file_exists = os.path.exists(img_path)
input_image = cv2.imread(img_path,1)
preprocessed_data.append((input_image))
return preprocessed_data
def inference(self, model_inputs):
........................................................
My request code as below:
dict = {"image": './test.jpeg',
"p_list": p_data,
"q_list": q_data}
data_obj = json.dumps(dict)
response = requests.post(url_0, json=data_obj)