# Upload Model Predictions

[block:callout]
{
  "type": "info",
  "title": "[Click for Python SDK](https://docs.nucleus.scale.com/en/latest/api/nucleus/index.html#nucleus.Dataset.upload_predictions)",
  "body": "```\nDataset.upload_predictions(\n    model: Model,\n    predictions: List[Prediction],\n    update: bool,\n    asynchronous: bool\n) -> Union[dict, AsyncJob]\n```"
}
[/block]

After inference is complete, you'll want to pack the model outputs into the format Nucleus requires to begin computation on your model's performance.

This JSON schema is almost exactly the same as that of [Annotations](https://nucleus.scale.com/reference/annotations-overview), but predictions also take in optional `confidence` and `class_pdf` key-value pairs.

## Definition: `BoxGeometry`

[block:parameters]
{
  "data": {
    "h-0": "Key",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "`x`",
    "0-1": "float (**required**)",
    "0-2": "The distance, in pixels, between the left border of the bounding box and the left border of the image.",
    "1-0": "`y`",
    "1-1": "float (**required**)",
    "1-2": "The distance, in pixels, between the top border of the bounding box and the top border of the image.",
    "2-0": "`width`",
    "2-1": "float (**required**)",
    "2-2": "The width in pixels of the annotation.",
    "3-0": "`height`",
    "3-1": "float (**required**)",
    "3-2": "The height in pixels of the annotation."
  },
  "cols": 3,
  "rows": 4
}
[/block]

## Definition: `Point2D`

[block:parameters]
{
  "data": {
    "h-0": "Key",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "`x`",
    "0-1": "float (**required**)",
    "0-2": "The distance, in pixels, between the left border of the bounding box and the left border of the image.",
    "1-0": "`y`",
    "1-1": "float (**required**)",
    "1-2": "The distance, in pixels, between the top border of the bounding box and the top border of the image."
  },
  "cols": 3,
  "rows": 2
}
[/block]

## Definition: `PolygonGeometry`

[block:parameters]
{
  "data": {
    "h-0": "Key",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "`vertices`",
    "0-1": "array of [`Point2D`](#definition-point2d)",
    "0-2": "Array of `Point` objects that represent vertices of the polygon."
  },
  "cols": 3,
  "rows": 1
}
[/block]

## Definition: `Point3D`

[block:parameters]
{
  "data": {
    "h-0": "Key",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "`x`",
    "0-1": "float (**required**)",
    "0-2": "The x coordinate of the point.",
    "1-2": "The y coordinate of the point.",
    "2-2": "The z coordinate of the point.",
    "1-1": "float (**required**)",
    "2-1": "float (**required**)",
    "1-0": "`y`",
    "2-0": "`z`"
  },
  "cols": 3,
  "rows": 3
}
[/block]

## Definition: `CuboidGeometry`

[block:parameters]
{
  "data": {
    "h-0": "Key",
    "h-1": "Type",
    "h-2": "Description",
    "0-0": "`position`",
    "0-1": "[`Point3D`](#definition-point3d) (**required**)",
    "0-2": "The center of the cuboid.",
    "1-0": "`dimensions`",
    "2-0": "`yaw`",
    "2-1": "float (**required**)",
    "2-2": "The rotation, in radians, about the z axis of the cuboid.",
    "1-1": "[`Point3D`](#definition-point3d) (**required**)",
    "1-2": "The length, width, and height of the cuboid."
  },
  "cols": 3,
  "rows": 3
}
[/block]

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "Nucleus API",
    "version": "1.1"
  },
  "servers": [
    {
      "url": "https://api.scale.com/v1/nucleus"
    }
  ],
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "http",
        "scheme": "basic"
      }
    }
  },
  "security": [
    {
      "sec0": []
    }
  ],
  "paths": {
    "/dataset/{dataset_id}/model/{model_id}/uploadPredictions": {
      "post": {
        "summary": "Upload Model Predictions",
        "description": "",
        "operationId": "upload-model-predictions",
        "parameters": [
          {
            "name": "dataset_id",
            "in": "query",
            "description": "The Scale-generated ID of the Dataset.",
            "schema": {
              "type": "string"
            }
          },
          {
            "name": "model_id",
            "in": "query",
            "description": "The Scale-generated ID of the Model.",
            "schema": {
              "type": "string"
            }
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "annotations": {
                    "type": "array",
                    "description": "Array of `GeometricPrediction` objects to upload. One or both of `annotations` or `segmentations` must be supplied.",
                    "items": {
                      "properties": {
                        "reference_id": {
                          "type": "string",
                          "description": "User-defined ID of the image to which to apply this Prediction."
                        },
                        "annotation_id": {
                          "type": "string",
                          "description": "Optional unique ID that uniquely identifies this Prediction within its target DatasetItem. Upon ingest, a matching annotation ID will be ignored by default, and updated if update=True for dataset.annotate. If not supplied, an annotation_id will be generated automatically. We do not support annotation_id for category predictions."
                        },
                        "label": {
                          "type": "string",
                          "description": "Label for this car (e.g. car, pedestrian, bicycle)."
                        },
                        "type": {
                          "type": "string",
                          "description": "One of `box`, `polygon`, `cuboid`, or `category`."
                        },
                        "geometry": {
                          "type": "object",
                          "description": "One of [BoxGeometry](#definition-boxgeometry), [PolygonGeometry](#definition-polygongeometry), [CuboidGeometry](#definition-cuboidgeometry) or an empty geometry object {}. Must correspond with the `type`. Set geometry to {} for category predictions since category predictions have no notion of geometry."
                        },
                        "confidence": {
                          "type": "number",
                          "description": "Optional confidence level within [0,1].",
                          "format": "float"
                        },
                        "class_pdf": {
                          "type": "object",
                          "description": "Optional class probability distribution. Maps each class `label` to a probability value within [0,1] such that all values sum to 1."
                        },
                        "metadata": {
                          "type": "string",
                          "description": "Arbitrary metadata blob for the prediction."
                        },
                        "taxonomy_name": {
                          "type": "string",
                          "description": "Optional name of the taxonomy for the prediction."
                        }
                      },
                      "required": [
                        "reference_id",
                        "label",
                        "type",
                        "geometry"
                      ],
                      "type": "object"
                    }
                  },
                  "segmentations": {
                    "type": "array",
                    "description": "Array of `SegmentationPrediction` objects to upload. One or both of `annotations` or `segmentations` must be supplied.",
                    "items": {
                      "properties": {
                        "reference_id": {
                          "type": "string",
                          "description": "User-specified ID of the image to which to apply this Annotation."
                        },
                        "annotation_id": {
                          "type": "string",
                          "description": "Optional unique ID that uniquely identifies this Prediction within its target DatasetItem. Upon ingest, a matching annotation ID will be ignored by default, and updated if update=True for dataset.annotate. If not supplied, an annotation_id will be generated automatically."
                        },
                        "mask_url": {
                          "type": "string",
                          "description": "URL pointing to the segmentation prediction mask which is accessible to Scale. The mask is an HxW int8 array saved in PNG format, with each pixel value ranging from [0, N), where N is the number of possible classes (for semantic segmentation) or instances (for instance segmentation). The height and width of the mask must be the same as the original image. The class name for each value in the mask is stored in the list of Segment objects passed for `annotations`."
                        },
                        "annotations": {
                          "type": "array",
                          "description": "Array of `Segments`, which represent mappings between the integer values contained in `mask_url` and class labels.",
                          "items": {
                            "properties": {
                              "index": {
                                "type": "integer",
                                "description": "Pixel value in the mask (i.e. [0,N) for N classes/instances) to which this mapping refers.",
                                "format": "int32"
                              },
                              "label": {
                                "type": "string",
                                "description": "Name of the class for the class/instance corresponding to `index` in the associated mask."
                              },
                              "metadata": {
                                "type": "string",
                                "description": "Arbitrary metadata blob for the segment."
                              }
                            },
                            "required": [
                              "index",
                              "label"
                            ],
                            "type": "object"
                          }
                        },
                        "type": {
                          "type": "string",
                          "description": "For segmentation, this `type` will always be `mask`."
                        }
                      },
                      "required": [
                        "reference_id",
                        "mask_url",
                        "type"
                      ],
                      "type": "object"
                    }
                  },
                  "update": {
                    "type": "boolean",
                    "description": "Whether to overwrite existing predictions upon `reference_id` and `annotation_id` collision. For category predictions, determines whether to overwrite upon `taxonomy_name` and `reference_id` collision.",
                    "default": false
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "200",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "400",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": "{}"
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          }
        },
        "deprecated": false
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "x-readme-fauxas": true,
  "_id": "60a66ff6bfbc7000736519dd:61a6d83366f20c002adf6e4a"
}
```