Bring your own Writer

Writers in AIAA is the last stage, it will write the result and send it back to the client. You can bring your own writer just make sure it implements this method: __call__(self, data) and it returns a tuple of (output_filename, result_json).

Write a Custom Writer

Below is an example of custom writer:

class CustomWriter:
    def __init__(
        self,
        image='pred',
        label_names=None
    ):
        self.image = image
        self.label_names = label_names

    def __call__(self, data):
        result = []
        for label in data[self.image]:
            result.append(self.label_names[int(label)])
        # in this writer it does not save things into a file
        # it just return the prediction result as json
        return None, {'prediction': result}

Use a Custom Writer

Assume you saved this custom transform in a file called custom_writer.py. For AIAA to pick up, you need to copy that file inside <AIAA workspace>/lib folder.

Then you can use it in config_aiaa.json as the following:

{
  "name": "custom_writer.CustomWriter",
  "args": {
    "image": "pred",
    "label_names": [
      "label-0",
      "label-1",
      "label-2",
      "label-3",
      "label-4"
    ]
  }
}

Note

Although AIAA supports only one writer, you can still return multiple results by packing them together using custom writer and unpack on the client side.