Import Local Models

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

#Feature

Currently, Instill Model 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 In this case, we use the Object Detection model YOLOv4. Let's download and extract the contents of the sample model.


# 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, Instill Model 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. [Optional] Give a short description of your model in the Description field
  4. Click the Model source ▾ drop-down and choose Local
  5. Click Upload to upload the model .zip file and click Set up
  6. Now go to the Model page, the corresponding model should be here. Note that it may take some time for the model to be deployed online.

#Low-code Setup

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

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

  1. Deploy the imported model yolov4.
cURL
Copy

curl -X POST http://localhost:8080/v1alpha/models/yolov4/deploy

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

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

Last updated: 10/28/2023, 1:21:44 PM