Skip to content

Predict endpoints


Routers for processing image data with CNNs

predict_tags(request) async

Endpoint for processing a list of images via Tagger multilabel network

Parameters:

Name Type Description Default
request PredictBatchRequest

data to process

required

Returns:

Name Type Description
response PredictBatchResponse

predicted tags and scores for each processed sample

Source code in src/app/routers/predict/predict.py
@router.post("/tagger", response_model=schemas.PredictBatchResponse,
             response_model_exclude_none=True)
async def predict_tags(request: schemas.PredictBatchRequest):
    """
    Endpoint for processing a list of images via Tagger multilabel network

    Parameters
    ----------
    request: schemas.PredictBatchRequest
        data to process

    Returns
    -------
    response : schemas.PredictBatchResponse
        predicted tags and scores for each processed sample
    """
    ids = [image.id for image in request.images]
    images = [image.image for image in request.images]
    predictions = await services.predict_tags(instances=images, ids=ids,
                                              custom_thresholds=request.thresholds)
    return schemas.PredictBatchResponse(predictions=predictions)

predict_exterior_styles(request) async

Endpoint for processing a list of images via Exterior Styles Classifier network

Parameters:

Name Type Description Default
request PredictBatchRequest

data to process

required

Returns:

Name Type Description
response PredictBatchResponse

tag and score for each processed sample

Source code in src/app/routers/predict/predict.py
@router.post("/exterior_styles", response_model=schemas.PredictBatchResponse,
             response_model_exclude_none=True)
async def predict_exterior_styles(request: schemas.PredictBatchRequest):
    """
    Endpoint for processing a list of images via Exterior Styles Classifier network

    Parameters
    ----------
    request : schemas.PredictBatchRequest
        data to process

    Returns
    -------
    response : schemas.PredictBatchResponse
        tag and score for each processed sample
    """
    ids = [image.id for image in request.images]
    images = [image.image for image in request.images]
    predictions = await services.predict_exterior_styles(instances=images, ids=ids)

    return schemas.PredictBatchResponse(predictions=predictions)

process_house_images(request) async

Endpoint for processing all images of a single house via all available models and extracting house-specific information based on that

Parameters:

Name Type Description Default
request PredictHomeRequest

data to process

required

Returns:

Name Type Description
response PredictHomeResponse

predictions for each image and general information about the house gathered from those predictions, like average exterior style or features it has

Source code in src/app/routers/predict/predict.py
@router.post("/process_house_images", response_model=schemas.PredictHomeResponse,
             response_model_exclude_none=True)
async def process_house_images(request: schemas.PredictHomeRequest):
    """
    Endpoint for processing all images of a single house via all available models and extracting
    house-specific information based on that

    Parameters
    ----------
    request : schemas.PredictHomeRequest
        data to process

    Returns
    -------
    response : schemas.PredictHomeResponse
        predictions for each image and general information about the house gathered from
        those predictions, like average exterior style or features it has
    """
    core_listing_id = request.core_listing_id
    ids = [image.id for image in request.images]
    images = [image.image for image in request.images]

    response = await services.process_house_images(instances=images,
                                                   ids=ids,
                                                   custom_thresholds=request.thresholds)
    enqueue_results = None
    if request.publish_embeddings:
        enqueue_results = await services.publish_embeddings(core_listing_id=core_listing_id,
                                                            instance_ids=ids,
                                                            instances=images,
                                                            compression=request.embeddings_compression)
    return schemas.PredictHomeResponse(core_listing_id=core_listing_id, publish_results=enqueue_results,
                                       **response)

encode(request) async

Endpoint for encoding a list of images into vectors via Encoder network

Parameters:

Name Type Description Default
request PredictBatchRequest

data to process

required

Returns:

Name Type Description
response PredictBatchResponse

embedding vectors of inputs

Source code in src/app/routers/predict/predict.py
@router.post("/encoder", response_model=schemas.PredictBatchResponse,
             response_model_exclude_none=True)
async def encode(request: schemas.PredictBatchRequest):
    """
    Endpoint for encoding a list of images into vectors via Encoder network

    Parameters
    ----------
    request : schemas.PredictBatchRequest
        data to process

    Returns
    -------
    response : schemas.PredictBatchResponse
        embedding vectors of inputs
    """
    ids = [image.id for image in request.images]
    images = [image.image for image in request.images]
    predictions = await services.encode(instances=images, ids=ids)

    return schemas.PredictBatchResponse(predictions=predictions)

Routers for checking application status

info() async

Endpoint for getting basic information on deployed networks, like number and names of output classes

Returns:

Name Type Description
response InfoResponse

Status of the API and each of its dependencies

Source code in src/app/routers/predict/info.py
@router.get("/get_info", response_model=schemas.InfoResponse,
            response_model_exclude_none=True)
async def info():
    """
    Endpoint for getting basic information on deployed networks, like number and names of output
    classes

    Returns
    -------
    response : schemas.InfoResponse
        Status of the API and each of its dependencies
    """
    # check API all dependencies
    return schemas.InfoResponse(networks=services.info())