ML Model inputs and outputs analogy
As I learn more and more about ML (I am a mobile DEV) I'm starting to form an analogy in my head. I would like the communities opinion / validation.

As a front end DEV you have a backend and an API that you can make requests to. The standard format for the inputs and outputs to the API is JSON.

I'm running into a problem with ML Models that I am trying to use where I don't know how to read the expected input (API) and I don't know how to decode the expected output.

So far I my experience has been fragmented because some models say "Give me an image of [1,2,120,120]" or something like that.

To analogize, is there a unified way to define inputs and outputs for a ML model like JSON unifies the inputs and outputs for an backend API?

If so, what are some rules one must follow to encode and decode data into this format?

Assuming this "ML Model" is in the context of running an input through say a trained pytorch model's forward pass to get an output, the unified way to define inputs and outputs for an ML model are through Tensors.  Tensors are essentially a multi-dimensional matrix containing elements of a single data type.  Think multi-dimensional lists with a single data type.

Tensors:MLModels::JSON:WebAPI

An Example using an Object Detector 
Model


Let's say your model example with the image is an object detector model that takes in an image as input and outputs either dog or cat
The input would usually be:
A tensor representation of an Image with the shape of [1, 2, 120, 120] where 1 represents the batch size, 2 is the dimension of your rgb channels, and 120x120 is the width and height of an image.
The output would usually be:
A normalized 2 dimensional tensor like [0.7, 0.3] where index 0 represents the probability of the image depicting a dog and index 1 represents the probability it's a cat.


Encoding and Decoding


Decoding the output to a string like "dog" or "cat" is obvious.
Encoding an image is slightly less obvious.  At its heart, the format
of an image is that of a tensor...a multi-dimensional matrix
containing a single datatype.  So is still intuitive to encode an
image in the form of a JPEG or PNG to a tensor representation through
the rgb channel dimensions and the pixel values for each channel. 
Typically image files are loaded in using libraries and methods like
the python imaging library and pytorch's
torchvision.transforms.ToTensor().


This example is very specific to an object detector type model, but most supervised ML models will output a tensor like the above or a one-hot label.  Most ML models in general will always have data inputs and outputs that can be represented as Tensors. 
