forked from intel-retail/automated-self-checkout
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: init add capi yolov8 ensemble profile implementation
Signed-off-by: Jim Wang <[email protected]>
- Loading branch information
1 parent
056f2e6
commit 9165a4b
Showing
31 changed files
with
5,635 additions
and
10 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
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
19 changes: 19 additions & 0 deletions
19
configs/opencv-ovms/cmd_client/res/capi_yolov8_ensemble/configuration.yaml
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,19 @@ | ||
OvmsSingleContainer: true | ||
OvmsClient: | ||
DockerLauncher: | ||
Script: docker-launcher.sh | ||
DockerImage: openvino/model_server-capi-gst-ovms-capi_yolov8_ensemble:latest | ||
ContainerName: capi_yolov8_ensemble | ||
Volumes: | ||
- "$cl_cache_dir:/home/intel/gst-ovms/.cl-cache" | ||
- /tmp/.X11-unix:/tmp/.X11-unix | ||
- "$RUN_PATH/sample-media/:/home/intel/gst-ovms/vids" | ||
- "$RUN_PATH/configs/opencv-ovms/gst_capi/extensions:/home/intel/gst-ovms/extensions" | ||
- "$RUN_PATH/results:/tmp/results" | ||
- "$RUN_PATH/configs/opencv-ovms/models/2022/:/models" | ||
# when the OVMSCustomNodeJson is not empty, then it will add or replace the existing customNode info for CAPI-OVMS server config | ||
OVMSCustomNodeJson: yolov8_custom_node.json | ||
PipelineScript: ./run_gst_capi.sh | ||
PipelineInputArgs: "" # space delimited like we run the script in command and take those input arguments | ||
EnvironmentVariableFiles: | ||
- capi_yolov8_ensemble.env |
85 changes: 85 additions & 0 deletions
85
configs/opencv-ovms/cmd_client/res/capi_yolov8_ensemble/yolov8_custom_node.json
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,85 @@ | ||
{ | ||
"custom_node_library_config_list": [ | ||
{ | ||
"name": "efficientnetb0_extractor", | ||
"base_path": "/ovms/lib/libcustom_node_efficientnetb0-yolov8.so" | ||
} | ||
], | ||
"pipeline_config_list": [ | ||
{ | ||
"name": "detect_classify", | ||
"inputs": ["images"], | ||
"nodes": [ | ||
{ | ||
"name": "detection_node", | ||
"model_name": "yolov8", | ||
"type": "DL model", | ||
"inputs": [ | ||
{"images": {"node_name": "request", | ||
"data_item": "images"} | ||
} | ||
], | ||
"outputs": [ | ||
{"data_item": "output0", | ||
"alias": "boxes"} | ||
] | ||
}, | ||
{ | ||
"name": "extract_node", | ||
"library_name": "efficientnetb0_extractor", | ||
"type": "custom", | ||
"demultiply_count": 0, | ||
"params": { | ||
"original_image_width": "416", | ||
"original_image_height": "416", | ||
"original_image_layout": "NCHW", | ||
"target_image_width": "224", | ||
"target_image_height": "224", | ||
"target_image_layout": "NCHW", | ||
"convert_to_gray_scale": "false", | ||
"confidence_threshold": "0.5", | ||
"max_output_batch": "100", | ||
"debug": "false" | ||
}, | ||
"inputs": [ | ||
{"images": {"node_name": "request", | ||
"data_item": "images"}}, | ||
{"boxes": {"node_name": "detection_node", | ||
"data_item": "boxes"}} | ||
], | ||
"outputs": [ | ||
{"data_item": "roi_images", | ||
"alias": "roi_images"}, | ||
{"data_item": "roi_coordinates", | ||
"alias": "roi_coordinates"}, | ||
{"data_item": "confidence_levels", | ||
"alias": "confidence_levels"} | ||
] | ||
}, | ||
{ | ||
"name": "classification_node", | ||
"model_name": "efficientnetb0_FP32INT8", | ||
"type": "DL model", | ||
"inputs": [ | ||
{"sub": {"node_name": "extract_node", | ||
"data_item": "roi_images"}} | ||
], | ||
"outputs": [ | ||
{"data_item": "efficientnet-b0/model/head/dense/BiasAdd/Add", | ||
"alias": "classify_output"} | ||
] | ||
} | ||
], | ||
"outputs": [ | ||
{"roi_images": {"node_name": "extract_node", | ||
"data_item": "roi_images"}}, | ||
{"roi_coordinates": {"node_name": "extract_node", | ||
"data_item": "roi_coordinates"}}, | ||
{"confidence_levels": {"node_name": "extract_node", | ||
"data_item": "confidence_levels"}}, | ||
{"classify_output": {"node_name": "classification_node", | ||
"data_item": "classify_output"}} | ||
] | ||
} | ||
] | ||
} |
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,90 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright 2024 Intel Corp. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// ---------------------------------------------------------------------------------- | ||
|
||
package server | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
) | ||
|
||
type CustomNodeUpdater struct { | ||
customNodeConfigJsonFile string | ||
templateConfigJsonDir string | ||
templateConfigJsonFileName string | ||
} | ||
|
||
type OvmsCustomNodeConfig struct { | ||
CustomNode []map[string]interface{} `json:"custom_node_library_config_list"` | ||
PipelineConfig []map[string]interface{} `json:"pipeline_config_list"` | ||
} | ||
|
||
func NewCustomNodeUpdater(customNodeConfigJsonFile string, templateConfigJsonDir, templateConfigJsonFileName string) *CustomNodeUpdater { | ||
return &CustomNodeUpdater{ | ||
customNodeConfigJsonFile: customNodeConfigJsonFile, | ||
templateConfigJsonDir: templateConfigJsonDir, | ||
templateConfigJsonFileName: templateConfigJsonFileName, | ||
} | ||
} | ||
|
||
// UpdateCustomNode adds (if not exists) or updates custom_node_library_config_list and related json information from customNodeConfigJsonFile into | ||
// the template config json file and then produces a new config json file based on the input newConfigJsonFile; | ||
// it returns error if failed to parse json or failed to produce a new config json file | ||
func (cu *CustomNodeUpdater) UpdateCustomNode(newConfigJsonFile string) error { | ||
templateConfigJsonFile := filepath.Join(cu.templateConfigJsonDir, cu.templateConfigJsonFileName) | ||
contents, err := os.ReadFile(templateConfigJsonFile) | ||
if err != nil { | ||
return fmt.Errorf("CustomNodeUpdater failed to read OVMS template config json file %s: %v", templateConfigJsonFile, err) | ||
} | ||
|
||
var ovmsConfigData OvmsConfig | ||
err = json.Unmarshal(contents, &ovmsConfigData) | ||
if err != nil { | ||
return fmt.Errorf("CustomNodeUpdater parsing OVMS template config json error: %v", err) | ||
} | ||
|
||
// read also the customNodeConfigJsonFile: | ||
customNodeConfig, err := os.ReadFile(cu.customNodeConfigJsonFile) | ||
if err != nil { | ||
return fmt.Errorf("CustomNodeUpdater failed to read OVMS custom node json file %s: %v", cu.customNodeConfigJsonFile, err) | ||
} | ||
|
||
var customNodeData OvmsCustomNodeConfig | ||
err = json.Unmarshal(customNodeConfig, &customNodeData) | ||
if err != nil { | ||
return fmt.Errorf("CustomNodeUpdater parsing OVMS custom node json error: %v", err) | ||
} | ||
|
||
if len(customNodeData.CustomNode) > 0 { | ||
// replacing: | ||
ovmsConfigData.CustomNode = customNodeData.CustomNode | ||
ovmsConfigData.PipelineConfig = customNodeData.PipelineConfig | ||
} | ||
|
||
updateConfig, err := json.MarshalIndent(ovmsConfigData, "", " ") | ||
if err != nil { | ||
return fmt.Errorf("CustomNodeUpdater could not marshal config to JSON: %v", err) | ||
} | ||
|
||
if err := os.WriteFile(newConfigJsonFile, updateConfig, 0644); err != nil { | ||
return fmt.Errorf("CustomNodeUpdater could not write a updated config to a new JSON: %v", err) | ||
} | ||
|
||
return nil | ||
} |
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,67 @@ | ||
// ---------------------------------------------------------------------------------- | ||
// Copyright 2024 Intel Corp. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
// ---------------------------------------------------------------------------------- | ||
|
||
package server | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestCustomNodes(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
customNodeJsonFile string | ||
templateJsonFileDir string | ||
templateJsonFileName string | ||
newJsonFileName string | ||
expectError bool | ||
expectedCustomNodeLib string | ||
}{ | ||
{"add a new test custom node", "./test-yolov8_custom_node.json", ".", "test-update-device.json", "./add-test-yolov8.json", false, "/ovms/lib/libcustom_node_efficientnetb0-yolov8.so"}, | ||
{"replacing an existing custom node", "./test-yolov8_custom_node.json", ".", "test-customnode.json", "./a-replacing-test-yolov8.json", false, "/ovms/lib/libcustom_node_efficientnetb0-yolov8.so"}, | ||
{"non-existing custom node file", "./non-existing", ".", "test-update-device.json", "./failed-non-existing.json", true, ""}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
customNodeUpdater := NewCustomNodeUpdater(tt.customNodeJsonFile, tt.templateJsonFileDir, tt.templateJsonFileName) | ||
|
||
err := customNodeUpdater.UpdateCustomNode(tt.newJsonFileName) | ||
defer func() { | ||
_ = os.Remove(tt.newJsonFileName) | ||
}() | ||
|
||
if !tt.expectError { | ||
require.NoError(t, err) | ||
require.NotEmpty(t, customNodeUpdater) | ||
require.FileExists(t, tt.newJsonFileName) | ||
newData, readErr := os.ReadFile(tt.newJsonFileName) | ||
require.NoError(t, readErr) | ||
require.Contains(t, string(newData), "\"base_path\": \""+tt.expectedCustomNodeLib+"\"") | ||
if tt.templateJsonFileName == "test-customnode.json" { | ||
require.Contains(t, string(newData), "\"custom_node_library_config_list\":") | ||
require.Contains(t, string(newData), "\"pipeline_config_list\":") | ||
} | ||
} else { | ||
require.Error(t, err) | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.