-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added sample to deploy online endpoint running inference (#2)
* Added inference samples. * Use latest mlflow versions * Use latest ultralytics version. * quick cleanup. * cleanup. * Updated libraries version in notebook. * renamed inference environment folder. * Added infoo about request_timeout_ms.
- Loading branch information
Showing
12 changed files
with
597 additions
and
419 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
yolov8n.pt | ||
coco128/* | ||
coco128/* | ||
.vscode | ||
.idea | ||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineDeployment.schema.json | ||
name: yolodeployment | ||
endpoint_name: yolovendpoint | ||
model: | ||
#azureml:<your-model-name>:1 | ||
#path: <relative local path to your .pt model from the azureml folder> | ||
code_configuration: | ||
code: ../inference-code | ||
scoring_script: score.py | ||
environment: | ||
build: | ||
path: ../inference-environment | ||
dockerfile_path: Dockerfile | ||
instance_type: Standard_DS3_v2 | ||
instance_count: 1 | ||
# Note that you might need to increase the request_timeout_ms if running the inference takes time. | ||
# request_timeout_ms: 10000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
$schema: https://azuremlschemas.azureedge.net/latest/managedOnlineEndpoint.schema.json | ||
name: my-endpoint | ||
auth_mode: key |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
set -ex | ||
|
||
export ENDPOINT_NAME=endpt-`echo $RANDOM` | ||
az ml online-endpoint create -n $ENDPOINT_NAME -f azureml/endpoint.yaml | ||
az ml online-deployment create -n blue --endpoint $ENDPOINT_NAME -f azureml/deployment.yaml | ||
az ml online-endpoint show -n $ENDPOINT_NAME | ||
SCORING_URI=$(az ml online-endpoint show -n $ENDPOINT_NAME -o tsv --query scoring_uri) | ||
echo "Endpoint name: $ENDPOINT_NAME" | ||
echo "Scoring uri: $SCORING_URI" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
set -ex | ||
|
||
export ENDPOINT_NAME=endpt-`echo $RANDOM` | ||
az ml online-endpoint create --local -n $ENDPOINT_NAME -f azureml/endpoint.yaml | ||
|
||
# <create_deployment> | ||
az ml online-deployment create --local -n blue --endpoint $ENDPOINT_NAME -f azureml/deployment.yaml | ||
# </create_deployment> | ||
|
||
# <get_status> | ||
az ml online-endpoint show -n $ENDPOINT_NAME --local | ||
# </get_status> | ||
|
||
# check if create was successful | ||
endpoint_status=`az ml online-endpoint show --local --name $ENDPOINT_NAME --query "provisioning_state" -o tsv` | ||
echo $endpoint_status | ||
if [[ $endpoint_status == "Succeeded" ]] | ||
then | ||
echo "Endpoint created successfully" | ||
else | ||
echo "Endpoint creation failed" | ||
exit 1 | ||
fi | ||
|
||
deploy_status=`az ml online-deployment show --local --name blue --endpoint $ENDPOINT_NAME --query "provisioning_state" -o tsv` | ||
echo $deploy_status | ||
if [[ $deploy_status == "Succeeded" ]] | ||
then | ||
echo "Deployment completed successfully" | ||
else | ||
echo "Deployment failed" | ||
exit 1 | ||
fi | ||
|
||
# <test_endpoint> | ||
az ml online-endpoint invoke --local --name $ENDPOINT_NAME --request-file inference-sample-request.json | ||
# </test_endpoint> | ||
|
||
# <test_endpoint_using_curl> | ||
SCORING_URI=$(az ml online-endpoint show --local -n $ENDPOINT_NAME -o tsv --query scoring_uri) | ||
|
||
curl --request POST "$SCORING_URI" --header 'Content-Type: application/json' --data @inference-sample-request.json | ||
|
||
# <get_logs> | ||
#az ml online-deployment get-logs --local -n blue --endpoint $ENDPOINT_NAME | ||
# </get_logs> | ||
|
||
curl -X POST -H "Content-Type: application/json" -d '{"image_url": "https://ultralytics.com/images/bus.jpg"}' $SCORING_URI | ||
|
||
# <delete_endpoint> | ||
#az ml online-endpoint delete --local --name $ENDPOINT_NAME --yes | ||
# </delete_endpoint> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import os | ||
import json | ||
from ultralytics import YOLO | ||
|
||
def init(): | ||
global model | ||
model_path = os.path.join( | ||
os.getenv("AZUREML_MODEL_DIR"), "best.pt" | ||
) | ||
model = YOLO(model_path) | ||
|
||
|
||
def run(raw_data): | ||
image_url = json.loads(raw_data)["image_url"] | ||
results = model(image_url) | ||
result = results[0] | ||
serialized_result = json.loads(result.tojson()) | ||
return serialized_result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
FROM mcr.microsoft.com/azureml/openmpi4.1.0-ubuntu20.04:latest | ||
|
||
ENV DEBIAN_FRONTEND noninteractive | ||
RUN apt update | ||
RUN TZ=Etc/UTC apt install -y tzdata | ||
RUN apt install --no-install-recommends -y gcc git zip curl htop libgl1-mesa-glx libglib2.0-0 libpython3-dev gnupg g++ | ||
RUN apt upgrade --no-install-recommends -y openssl tar | ||
RUN pip install azureml-inference-server-http | ||
RUN pip install ultralytics==8.0.180 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"image_url": "https://ultralytics.com/images/bus.jpg" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.