Hi Elman, thanks for opening this thread, this is a super interesting topic 
No matter what model you deploy to a Sagemaker (SM) endpoint, the input always requires preprocessing before it can be passed to the model. The reason you can just pass some text in the case of DistilBert without having to do the processing yourself is that the SageMaker Hugging Face Inference Toolkit 1 does all the work for you. This toolkit on builds on top of the Pipeline API, which is what makes it so easy to call.
What does that mean for you when you want to use a LayoutLMV2 model? I see two possibilities:


The Pipeline API offers a class for Object Detection: Pipelines 2. I’m not familiar with it but I would imagine that it is quite straightforward to use. Again, because the Inference Toolkit is based on Pipelines, once you figure out how to use the Pipeline API for Object Detection you can use the same call for the SM Endpoint


The Inference Toolkit also allows you to provide your own preprocessing script, see more details here: Deploy models to Amazon SageMaker 4. That means you can process the inputs yourself before passing it to the model. What I would do (because I’m lazy) is to just look at an already existing demo to see how the preprocessing for a LayoutLMV2 model works. For example this one: app.py · nielsr/LayoutLMv2-FUNSD at main 5, and use that.


Hope this helps, please let me know how it goes and/or reach out if any questions.
Cheers
Heiko