# To build the function you need to adjust docker settings. Be sure that you
# have enough memory (more than 4GB). Look here how to do that
# https://stackoverflow.com/questions/44417159/docker-process-killed-with-cryptic-killed-message
metadata:
  name: openvino-mask-rcnn-inception-resnet-v2-atrous-coco
  namespace: cvat
  annotations:
    name: Mask RCNN
    type: detector
    framework: openvino
    spec: |
      [
        { "id": 1, "name": "person" },
        { "id": 2, "name": "bicycle" },
        { "id": 3, "name": "car" },
        { "id": 4, "name": "motorcycle" },
        { "id": 5, "name": "airplane" },
        { "id": 6, "name": "bus" },
        { "id": 7, "name": "train" },
        { "id": 8, "name": "truck" },
        { "id": 9, "name": "boat" },
        { "id":10, "name": "traffic_light" },
        { "id":11, "name": "fire_hydrant" },
        { "id":13, "name": "stop_sign" },
        { "id":14, "name": "parking_meter" },
        { "id":15, "name": "bench" },
        { "id":16, "name": "bird" },
        { "id":17, "name": "cat" },
        { "id":18, "name": "dog" },
        { "id":19, "name": "horse" },
        { "id":20, "name": "sheep" },
        { "id":21, "name": "cow" },
        { "id":22, "name": "elephant" },
        { "id":23, "name": "bear" },
        { "id":24, "name": "zebra" },
        { "id":25, "name": "giraffe" },
        { "id":27, "name": "backpack" },
        { "id":28, "name": "umbrella" },
        { "id":31, "name": "handbag" },
        { "id":32, "name": "tie" },
        { "id":33, "name": "suitcase" },
        { "id":34, "name": "frisbee" },
        { "id":35, "name": "skis" },
        { "id":36, "name": "snowboard" },
        { "id":37, "name": "sports_ball" },
        { "id":38, "name": "kite" },
        { "id":39, "name": "baseball_bat" },
        { "id":40, "name": "baseball_glove" },
        { "id":41, "name": "skateboard" },
        { "id":42, "name": "surfboard" },
        { "id":43, "name": "tennis_racket" },
        { "id":44, "name": "bottle" },
        { "id":46, "name": "wine_glass" },
        { "id":47, "name": "cup" },
        { "id":48, "name": "fork" },
        { "id":49, "name": "knife" },
        { "id":50, "name": "spoon" },
        { "id":51, "name": "bowl" },
        { "id":52, "name": "banana" },
        { "id":53, "name": "apple" },
        { "id":54, "name": "sandwich" },
        { "id":55, "name": "orange" },
        { "id":56, "name": "broccoli" },
        { "id":57, "name": "carrot" },
        { "id":58, "name": "hot_dog" },
        { "id":59, "name": "pizza" },
        { "id":60, "name": "donut" },
        { "id":61, "name": "cake" },
        { "id":62, "name": "chair" },
        { "id":63, "name": "couch" },
        { "id":64, "name": "potted_plant" },
        { "id":65, "name": "bed" },
        { "id":67, "name": "dining_table" },
        { "id":70, "name": "toilet" },
        { "id":72, "name": "tv" },
        { "id":73, "name": "laptop" },
        { "id":74, "name": "mouse" },
        { "id":75, "name": "remote" },
        { "id":76, "name": "keyboard" },
        { "id":77, "name": "cell_phone" },
        { "id":78, "name": "microwave" },
        { "id":79, "name": "oven" },
        { "id":80, "name": "toaster" },
        { "id":81, "name": "sink" },
        { "id":83, "name": "refrigerator" },
        { "id":84, "name": "book" },
        { "id":85, "name": "clock" },
        { "id":86, "name": "vase" },
        { "id":87, "name": "scissors" },
        { "id":88, "name": "teddy_bear" },
        { "id":89, "name": "hair_drier" },
        { "id":90, "name": "toothbrush" }
      ]

spec:
  description: Mask RCNN inception resnet v2 COCO via Intel OpenVINO
  runtime: 'python:3.6'
  handler: main:handler
  eventTimeout: 60s
  env:
    - name: NUCLIO_PYTHON_EXE_PATH
      value: /opt/nuclio/common/python3

  build:
    image: cvat/openvino.omz.public.mask_rcnn_inception_resnet_v2_atrous_coco
    baseImage: openvino/ubuntu18_dev:2020.2

    directives:
      preCopy:
        - kind: USER
          value: root
        - kind: WORKDIR
          value: /opt/nuclio
        - kind: RUN
          value: ln -s /usr/bin/pip3 /usr/bin/pip
        - kind: RUN
          value: /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/downloader.py --name mask_rcnn_inception_resnet_v2_atrous_coco -o /opt/nuclio/open_model_zoo
        - kind: RUN
          value: /opt/intel/openvino/deployment_tools/open_model_zoo/tools/downloader/converter.py --name mask_rcnn_inception_resnet_v2_atrous_coco --precisions FP32 -d /opt/nuclio/open_model_zoo -o /opt/nuclio/open_model_zoo

      postCopy:
        - kind: RUN
          value: apt update && DEBIAN_FRONTEND=noninteractive apt install --no-install-recommends -y python3-skimage
        - kind: RUN
          value: pip3 install "numpy<1.16.0" # workaround for skimage

  triggers:
    myHttpTrigger:
      maxWorkers: 2
      kind: 'http'
      workerAvailabilityTimeoutMilliseconds: 10000
      attributes:
        maxRequestBodySize: 33554432 # 32MB

  platform:
    attributes:
      restartPolicy:
        name: always
        maximumRetryCount: 3
