Import Local Models

The Local model definition enables you to import a model from your local machine.

#Feature

Currently, VDP supports importing models from

  • ✅ A local .zip file

#Release stage

Alpha

#Configuration

FieldTypeNote
content*binarya .zip file that contains all the model files

#Getting started

#Requirements

  • A .zip file with all the model files

#Prepare a local model

The Local model definition accepts a .zip file that contains all files required for a model to be deployed.

Step 1: Download sample model data In this case, we use the object detection model YOLOv4. Let's download and extract the contents of the sample data.


# Create a folder
mkdir local-model
cd local-model
# Download sample model
curl -o yolov4-onnx-cpu.zip https://artifacts.instill.tech/vdp/sample-models/yolov4-onnx-cpu.zip
tar -xvf yolov4-onnx-cpu.zip
rm yolov4-onnx-cpu.zip

The extracted model files in /local-model should look like


├── README.md
├── post
│   ├── 1
│   │   ├── labels.py
│   │   ├── model.py
│   │   └── yolov4_anchors.txt
│   └── config.pbtxt
├── pre
│   ├── 1
│   │   └── model.py
│   └── config.pbtxt
├── yolov4
│   ├── 1
│   │   └── .keep
│   └── config.pbtxt
└── yolov4-infer
├── 1
│   └── model.onnx
└── config.pbtxt

Step 2: Create a local model zip file

In /local-model directory


zip -r "yolov4.zip" .

🎉 The model is ready, just run the setup guide below, VDP wll import it accordingly.

Caveat

✅ Make sure that the compressed model files are in the root directory of the zip file.


zipinfo yolov4.zip
# Output
Archive: yolov4.zip
Zip file size: 239252025 bytes, number of entries: 19
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 post/
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 post/1/
-rw-r--r-- 3.0 unx 1381 tx defN 22-Mar-27 16:25 post/1/labels.py
-rw-r--r-- 3.0 unx 7329 tx defN 22-Mar-30 01:17 post/1/model.py
-rw-r--r-- 3.0 unx 69 tx defN 22-Mar-27 16:25 post/1/yolov4_anchors.txt
-rw-r--r-- 3.0 unx 778 tx defN 22-Mar-27 16:25 post/config.pbtxt
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 yolov4-infer/
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 yolov4-infer/1/
-rw-r--r-- 3.0 unx 257470589 bx defN 22-Mar-27 16:25 yolov4-infer/1/model.onnx
-rw-r--r-- 3.0 unx 559 tx defN 22-Mar-27 16:25 yolov4-infer/config.pbtxt
-rw-r--r-- 3.0 unx 110 tx defN 22-Jul-10 02:41 README.md
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 yolov4/
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:13 yolov4/1/
-rw-r--r-- 3.0 unx 0 bx stor 22-Jul-21 12:13 yolov4/1/.keep
-rw-r--r-- 3.0 unx 1843 tx defN 22-Mar-27 16:25 yolov4/config.pbtxt
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 pre/
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 pre/1/
-rw-r--r-- 3.0 unx 4629 tx defN 22-Mar-30 01:17 pre/1/model.py
-rw-r--r-- 3.0 unx 507 tx defN 22-Mar-27 16:25 pre/config.pbtxt
19 files, 257487794 bytes uncompressed, 239249049 bytes compressed: 7.1%

❌ Don't compress the model files in another root directory


zipinfo yolov4.zip
# Output
Archive: yolov4.zip
Zip file size: 239252633 bytes, number of entries: 20
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:26 local-model/
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 local-model/post/
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 local-model/post/1/
-rw-r--r-- 3.0 unx 1381 tx defN 22-Mar-27 16:25 local-model/post/1/labels.py
-rw-r--r-- 3.0 unx 7329 tx defN 22-Mar-30 01:17 local-model/post/1/model.py
-rw-r--r-- 3.0 unx 69 tx defN 22-Mar-27 16:25 local-model/post/1/yolov4_anchors.txt
-rw-r--r-- 3.0 unx 778 tx defN 22-Mar-27 16:25 local-model/post/config.pbtxt
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 local-model/yolov4-infer/
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 local-model/yolov4-infer/1/
-rw-r--r-- 3.0 unx 257470589 bx defN 22-Mar-27 16:25 local-model/yolov4-infer/1/model.onnx
-rw-r--r-- 3.0 unx 559 tx defN 22-Mar-27 16:25 local-model/yolov4-infer/config.pbtxt
-rw-r--r-- 3.0 unx 110 tx defN 22-Jul-10 02:41 local-model/README.md
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 local-model/yolov4/
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:13 local-model/yolov4/1/
-rw-r--r-- 3.0 unx 0 bx stor 22-Jul-21 12:13 local-model/yolov4/1/.keep
-rw-r--r-- 3.0 unx 1843 tx defN 22-Mar-27 16:25 local-model/yolov4/config.pbtxt
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 local-model/pre/
drwxr-xr-x 3.0 unx 0 bx stor 22-Jul-21 12:12 local-model/pre/1/
-rw-r--r-- 3.0 unx 4629 tx defN 22-Mar-30 01:17 local-model/pre/1/model.py
-rw-r--r-- 3.0 unx 507 tx defN 22-Mar-27 16:25 local-model/pre/config.pbtxt
20 files, 257487794 bytes uncompressed, 239249049 bytes compressed: 7.1%

#No-code setup

To create a local model in the Console, do the following:

  1. Go to the Model page and click Add new model
  2. In the Set Up New Model page, fill an ID for your model, this will be the unique identifier of this model
  3. Click the Model type ▾ drop-down and choose Local
  4. [Optional] Give a short description of your model in the Description field
  5. Click Upload to upload the model .zip file and click Setup new model
  6. Once the model is imported, click the Model instances ▾ drop-down, pick the latest model instance and click Deploy
  7. Now go to the Model page, the corresponding model instance should be online

Since a local model has no version control, when the model is successfully imported, the model will has and only has one model instance tagged with latest.

#Low-code setup

  1. Send a HTTP request to the VDP model-backend to import a local model.
cURL
Copy

curl -X POST http://localhost:8083/v1alpha/models:multipart \
--form 'id="yolov4"' \
--form 'model_definition="model-definitions/local"' \
--form 'content=@"yolov4.zip"'

  1. Deploy the latest model instance.
cURL
Copy

curl -X POST http://localhost:8083/v1alpha/models/yolov4/instances/latest:deploy

  1. Perform an inference to test the model
cURL(url)
cURL(base64)
cURL(multipart)
Copy

curl -X POST http://localhost:8083/v1alpha/models/yolov4/instances/latest:test -d '{
"inputs": [
{
"image_url": "https://artifacts.instill.tech/imgs/dog.jpg"
}
]
}'

in which http://localhost:8083 is the model-backend default URL.

Last updated: 8/16/2022, 8:11:51 AM