养猪大户必备!教你用ModelBox开发一个AI数猪应用

本文分享自华为云社区《ModelBox-视频应用开发:AI智能数猪【玩转华为云】》,作者: 阳光大猫。

一、准备环境

ModelBox端云协同AI开发套件(Windows)环境准备ModelArts+ModelBox 端云协同AI应用开发实训课程

二、应用开发

1. 创建工程

ModelBox sdk目录下使用create.bat创建yolov7_pig工程:

css 复制代码
(tensorflow) PS D:\modelbox-win10-x64-1.5.3> .\create.bat -t server -n yolov7_pig 

(tensorflow) D:\modelbox-win10-x64-1.5.3>set BASE_PATH=D:\modelbox-win10-x64-1.5.3\ 

(tensorflow) D:\modelbox-win10-x64-1.5.3>set PATH=D:\modelbox-win10-x64-1.5.3\\python-embed;C:\Users\yanso\miniconda3\envs\tensorflow\lib\site-packages\pywin32_system32;C:\Users\yanso\miniconda3\envs\tensorflow;C:\Users\yanso\miniconda3\envs\tensorflow\Library\mingw-w64\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Library\usr\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Library\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Scripts;C:\Users\yanso\miniconda3\envs\tensorflow\bin;C:\Users\yanso\miniconda3\condabin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\yanso\miniconda3\envs\tensorflow\lib\site-packages\pywin32_system32;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Library\mingw-w64\bin;C:\Users\yanso\miniconda3\Library\usr\bin;C:\Users\yanso\miniconda3\Library\bin;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\bin;C:\Users\yanso\miniconda3\condabin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin 

(tensorflow) D:\modelbox-win10-x64-1.5.3>set PYTHONPATH=

(tensorflow) D:\modelbox-win10-x64-1.5.3>set PYTHONHOME=

(tensorflow) D:\modelbox-win10-x64-1.5.3>python.exe -u D:\modelbox-win10-x64-1.5.3\\create.py -t server -n yolov7_pig
sdk version is modelbox-win10-x64-1.5.3
dos2unix: converting file D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig/graph\modelbox.conf to Unix format...
dos2unix: converting file D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig/graph\yolov7_pig.toml to Unix format...
dos2unix: converting file D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig/bin\mock_task.toml to Unix format...
success: create yolov7_pig in D:\modelbox-win10-x64-1.5.3\workspace

create.bat工具的参数中,-t表示所创建实例的类型,包括serverModelBox工程)、python(Python功能单元)、c++(C++功能单元)、infer(推理功能单元)等;-n表示所创建实例的名称,开发者自行命名。

2. 创建推理功能单元

ModelBox sdk目录下使用create.bat创建yolov7_infer推理功能单元:

css 复制代码
(tensorflow) PS D:\modelbox-win10-x64-1.5.3> .\create.bat -t infer -n yolov7_infer -p yolov7_pig  

(tensorflow) D:\modelbox-win10-x64-1.5.3>set BASE_PATH=D:\modelbox-win10-x64-1.5.3\

(tensorflow) D:\modelbox-win10-x64-1.5.3>set PATH=D:\modelbox-win10-x64-1.5.3\\python-embed;C:\Users\yanso\miniconda3\envs\tensorflow\lib\site-packages\pywin32_system32;C:\Users\yanso\miniconda3\envs\tensorflow;C:\Users\yanso\miniconda3\envs\tensorflow\Library\mingw-w64\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Library\usr\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Library\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Scripts;C:\Users\yanso\miniconda3\envs\tensorflow\bin;C:\Users\yanso\miniconda3\condabin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\yanso\miniconda3\envs\tensorflow\lib\site-packages\pywin32_system32;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Library\mingw-w64\bin;C:\Users\yanso\miniconda3\Library\usr\bin;C:\Users\yanso\miniconda3\Library\bin;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\bin;C:\Users\yanso\miniconda3\condabin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin

(tensorflow) D:\modelbox-win10-x64-1.5.3>set PYTHONPATH=

(tensorflow) D:\modelbox-win10-x64-1.5.3>set PYTHONHOME=

(tensorflow) D:\modelbox-win10-x64-1.5.3>python.exe -u D:\modelbox-win10-x64-1.5.3\\create.py -t infer -n yolov7_infer -p yolov7_pig
sdk version is modelbox-win10-x64-1.5.3

create.bat工具使用时,-t infer 即表示创建的是推理功能单元;-n xxx_infer 表示创建的功能单元名称为xxx_infer-p yolov7_pig 表示所创建的功能单元属于yolov7_pig应用。

a. 下载转换好的模型

运行Notebook下载转换好的ONNX格式模型

b. 修改模型配置文件

模型和配置文件保持在同级目录下

ini 复制代码
# Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.

[base]
name = "yolov7_infer"
device = "cpu"
version = "1.0.0"
description = "your description"
entry = "./best.onnx"  # model file path, use relative path
type = "inference" 
virtual_type = "onnx" # inference engine type: win10 now only support onnx
group_type = "Inference"  # flowunit group attribution, do not change

# Input ports description
[input]
[input.input1]  # input port number, Format is input.input[N]
name = "Input"  # input port name
type = "float"  # input port data type ,e.g. float or uint8
device = "cpu"  # input buffer type: cpu, win10 now copy input from cpu

# Output ports description
[output]
[output.output1] # output port number, Format is output.output[N]
name = "Output"  # output port name
type = "float"   # output port data type ,e.g. float or uint8

3. 创建后处理功能单元

ModelBox sdk目录下使用create.bat创建yolov7_post后处理功能单元

css 复制代码
(tensorflow) PS D:\modelbox-win10-x64-1.5.3> .\create.bat -t python -n yolov7_post -p yolov7_pig

(tensorflow) D:\modelbox-win10-x64-1.5.3>set BASE_PATH=D:\modelbox-win10-x64-1.5.3\ 

(tensorflow) D:\modelbox-win10-x64-1.5.3>set PATH=D:\modelbox-win10-x64-1.5.3\\python-embed;C:\Users\yanso\miniconda3\envs\tensorflow\lib\site-packages\pywin32_system32;C:\Users\yanso\miniconda3\envs\tensorflow;C:\Users\yanso\miniconda3\envs\tensorflow\Library\mingw-w64\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Library\usr\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Library\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Scripts;C:\Users\yanso\miniconda3\envs\tensorflow\bin;C:\Users\yanso\miniconda3\condabin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\yanso\miniconda3\envs\tensorflow\lib\site-packages\pywin32_system32;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Library\mingw-w64\bin;C:\Users\yanso\miniconda3\Library\usr\bin;C:\Users\yanso\miniconda3\Library\bin;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\bin;C:\Users\yanso\miniconda3\condabin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin

(tensorflow) D:\modelbox-win10-x64-1.5.3>set PYTHONPATH=

(tensorflow) D:\modelbox-win10-x64-1.5.3>set PYTHONHOME=

(tensorflow) D:\modelbox-win10-x64-1.5.3>python.exe -u D:\modelbox-win10-x64-1.5.3\\create.py -t python -n yolov7_post -p yolov7_pig
sdk version is modelbox-win10-x64-1.5.3
success: create python yolov7_post in D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig/etc/flowunit/yolov7_post

a. 修改配置文件

ini 复制代码
# Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.

# Basic config
[base]
name = "yolov7_post" # The FlowUnit name
device = "cpu" # The flowunit runs on cpu
version = "1.0.0" # The version of the flowunit
type = "python" # Fixed value, do not change
description = "description" # The description of the flowunit
entry = "yolov7_post@yolov7_postFlowUnit" # Python flowunit entry function
group_type = "Generic"  # flowunit group attribution, change as Input/Output/Image/Generic ...

# Flowunit Type
stream = false # Whether the flowunit is a stream flowunit
condition = false # Whether the flowunit is a condition flowunit
collapse = false # Whether the flowunit is a collapse flowunit
collapse_all = false # Whether the flowunit will collapse all the data
expand = false #  Whether the flowunit is a expand flowunit

# The default Flowunit config
[config]
net_h = 640
net_w = 640
num_classes = 1
conf_threshold = 0.5
iou_threshold = 0.45

# Input ports description
[input]
[input.input1] # Input port number, the format is input.input[N]
name = "in_feat" # Input port name
type = "float" # Input port type

# Output ports description
[output]
[output.output1] # Output port number, the format is output.output[N]
name = "out_data" # Output port name
type = "string" # Output port type

b. 修改逻辑代码

ini 复制代码
# Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import _flowunit as modelbox
import numpy as np
import json
import cv2

class yolov7_postFlowUnit(modelbox.FlowUnit):
    # Derived from modelbox.FlowUnit
    def __init__(self):
        super().__init__()

    # Open the flowunit to obtain configuration information
    def open(self, config):
        # 获取功能单元的配置参数
        self.params = {}
        self.params['net_h'] = config.get_int('net_h')
        self.params['net_w'] = config.get_int('net_w')
        self.params['num_classes'] = config.get_int('num_classes')
        self.params['conf_thre'] = config.get_float('conf_threshold')
        self.params['nms_thre'] = config.get_float('iou_threshold')
        self.num_classes = config.get_int('num_classes')

        return modelbox.Status.StatusCode.STATUS_SUCCESS

    # Process the data
    def process(self, data_context):
        # 从DataContext中获取输入输出BufferList对象
        in_feat = data_context.input("in_feat")
        out_data = data_context.output("out_data")

        # yolov7_post process code.
        # 循环处理每一个输入Buffer数据
        for buffer_feat in in_feat:
            # 将输入Buffer转换为numpy对象
            feat_data = np.array(buffer_feat.as_object(), copy=False)
            feat_data = feat_data.reshape((-1, self.num_classes + 5))

            # 业务处理:解码yolov7模型的输出数据,得到检测框,转化为json数据
            bboxes = self.postprocess(feat_data, self.params)
            result = {"det_result": str(bboxes)}

            # 将业务处理返回的结果数据转换为Buffer
            result_str = json.dumps(result)
            out_buffer = modelbox.Buffer(self.get_bind_device(), result_str)

            # 将输出Buffer放入输出BufferList中
            out_data.push_back(out_buffer)

        return modelbox.Status.StatusCode.STATUS_SUCCESS
    
    # model post-processing function
    def postprocess(self, feat_data, params):
        """postprocess for yolo7 model"""
        boxes = []
        class_ids = []
        confidences = []
        for detection in feat_data:
            scores = detection[5:]
            class_id = np.argmax(scores)
            if params['num_classes'] == 1:
                confidence = detection[4]
            else:
                confidence = detection[4] * scores[class_id] 
            if confidence > params['conf_thre']:
                center_x = detection[0] / params['net_w']
                center_y = detection[1] / params['net_h']
                width = detection[2] / params['net_w']
                height = detection[3] / params['net_h']

                left = center_x - width / 2
                top = center_y - height / 2

                class_ids.append(class_id)
                confidences.append(confidence)
                boxes.append([left, top, width, height])

        # use nms algorithm in opencv
        box_idx = cv2.dnn.NMSBoxes(boxes, confidences, params['conf_thre'], params['nms_thre'])

        detections = []
        for i in box_idx:
            boxes[i][0] = max(0.0, boxes[i][0])  # [0, 1]
            boxes[i][1] = max(0.0, boxes[i][1])  # [0, 1]
            boxes[i][2] = min(1.0, boxes[i][0] + boxes[i][2])  # [0, 1]
            boxes[i][3] = min(1.0, boxes[i][1] + boxes[i][3])  # [0, 1]
            dets = np.concatenate(
                [boxes[i], np.array([confidences[i]]), np.array([class_ids[i]])], 0).tolist()
            detections.append(dets)

        return detections

    def close(self):
        # Close the flowunit
        return modelbox.Status()

    def data_pre(self, data_context):
        # Before streaming data starts
        return modelbox.Status()

    def data_post(self, data_context):
        # After streaming data ends
        return modelbox.Status()

    def data_group_pre(self, data_context):
        # Before all streaming data starts
        return modelbox.Status()

    def data_group_post(self, data_context):
        # After all streaming data ends
        return modelbox.Status()

4. 创建绘图功能单元

ModelBox sdk目录下使用create.bat创建draw_pig_bbox绘图功能单元:

a. 修改配置文件

ini 复制代码
# Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.

# Basic config
[base]
name = "draw_pig_bbox" # The FlowUnit name
device = "cpu" # The flowunit runs on cpu
version = "1.0.0" # The version of the flowunit
type = "python" # Fixed value, do not change
description = "description" # The description of the flowunit
entry = "draw_pig_bbox@draw_pig_bboxFlowUnit" # Python flowunit entry function
group_type = "Generic"  # flowunit group attribution, change as Input/Output/Image/Generic ...

# Flowunit Type
stream = false # Whether the flowunit is a stream flowunit
condition = false # Whether the flowunit is a condition flowunit
collapse = false # Whether the flowunit is a collapse flowunit
collapse_all = false # Whether the flowunit will collapse all the data
expand = false #  Whether the flowunit is a expand flowunit

# The default Flowunit config
[config]
item = "value"

# Input ports description
[input]
[input.input1] # Input port number, the format is input.input[N]
name = "in_image" # Input port name
type = "uint8" # Input port type

[input.input2] # Input port number, the format is input.input[N]
name = "in_box" # Input port name
type = "string" # Input port type

# Output ports description
[output]
[output.output1] # Output port number, the format is output.output[N]
name = "out_image" # Output port name
type = "uint8" # Output port type

b. 修改逻辑代码

python 复制代码
# Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
import _flowunit as modelbox
import numpy as np
import json
import cv2

class draw_pig_bboxFlowUnit(modelbox.FlowUnit):
    # Derived from modelbox.FlowUnit
    def __init__(self):
        super().__init__()

    def open(self, config):
        # Open the flowunit to obtain configuration information
        return modelbox.Status.StatusCode.STATUS_SUCCESS

    def process(self, data_context):
        # Process the data
        in_image = data_context.input("in_image")
        in_box = data_context.input("in_box")
        out_image = data_context.output("out_image")

        # draw_image process code.
        # Remove the following code and add your own code here.
        for buffer_img, buffer_box in zip(in_image, in_box):
            width =  buffer_img.get("width")
            height = buffer_img.get("height")
            channel = buffer_img.get("channel")

            img_data = np.array(buffer_img.as_object(), copy=False)
            img_data = img_data.reshape((height, width, channel))

            bbox_str = buffer_box.as_object()
            bboxes = self.decode_car_bboxes(bbox_str, (height, width))
            img_out = self.draw_bboxes(img_data, bboxes)

            out_buffer = modelbox.Buffer(self.get_bind_device(), img_out)
            out_buffer.copy_meta(buffer_img)
            out_image.push_back(out_buffer)

        return modelbox.Status.StatusCode.STATUS_SUCCESS
    
    def decode_car_bboxes(self, bbox_str, input_shape):
        try:
            labels = [0]  # pig
            bboxes = json.loads(json.loads(bbox_str)['det_result'])
            bboxes = list(filter(lambda x: int(x[5]) in labels, bboxes))
        except Exception as ex:
            print(str(ex))
            return []
        else:
            for bbox in bboxes:
                bbox[0] = int(bbox[0] * input_shape[1])
                bbox[1] = int(bbox[1] * input_shape[0])
                bbox[2] = int(bbox[2] * input_shape[1])
                bbox[3] = int(bbox[3] * input_shape[0])
            return bboxes
        
    def draw_bboxes(self, img_data, bboxes):
        '''画框'''
        count = len(bboxes)
        cv2.putText(img_data, 'pig_count: '+str(count), (20, 40), cv2.FONT_HERSHEY_TRIPLEX, 1.5, (255, 0, 0), thickness=2)
        for bbox in bboxes:
            x1, y1, x2, y2, score, label = bbox
            color = (0, 0, 255)
            names = ['pig']  
            score = '%.2f' % score
            label = '%s:%s' % (names[int(label)], score)
            cv2.rectangle(img_data, (x1, y1), (x2, y2), color, 2)
            cv2.putText(img_data, label, (x1, y1 - 10), cv2.FONT_HERSHEY_TRIPLEX, 0.5, (0, 255, 0), thickness=1)
        return img_data

    def close(self):
        # Close the flowunit
        return modelbox.Status()

    def data_pre(self, data_context):
        # Before streaming data starts
        return modelbox.Status()

    def data_post(self, data_context):
        # After streaming data ends
        return modelbox.Status()

    def data_group_pre(self, data_context):
        # Before all streaming data starts
        return modelbox.Status()

    def data_group_post(self, data_context):
        # After all streaming data ends
        return modelbox.Status()

5. 修改流程图

yolov7_pig工程graph目录下存放流程图,默认的流程图yolov7_pig.toml与工程同名,其内容为(以Windows版ModelBox为例):

ini 复制代码
# Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.

[driver]
dir = ["${HILENS_APP_ROOT}/etc/flowunit",
"${HILENS_APP_ROOT}/etc/flowunit/cpp",
"${HILENS_APP_ROOT}/model",
"${HILENS_MB_SDK_PATH}/flowunit"]
skip-default = true
[profile]
profile=false
trace=false
dir="${HILENS_DATA_DIR}/mb_profile"
[graph]
format = "graphviz"
graphconf = """digraph yolov7_pig {
    node [shape=Mrecord]
    queue_size = 4
    batch_size = 1
    input1[type=input,flowunit=input,device=cpu,deviceid=0]
    data_source_parser[type=flowunit, flowunit=data_source_parser, device=cpu, deviceid=0]
    video_demuxer[type=flowunit, flowunit=video_demuxer, device=cpu, deviceid=0]
    video_decoder[type=flowunit, flowunit=video_decoder, device=cpu, deviceid=0, pix_fmt=rgb]
    image_resize[type=flowunit, flowunit=resize, device=cpu, deviceid=0, image_width=640, image_height=640]
    image_transpose[type=flowunit, flowunit=packed_planar_transpose, device=cpu, deviceid=0]
    normalize[type=flowunit flowunit=normalize device=cpu deviceid=0 standard_deviation_inverse="0.0039215686,0.0039215686,0.0039215686"]
    yolov7_infer[type=flowunit, flowunit=yolov7_infer, device=cpu, deviceid=0, batch_size = 1]
    yolov7_post[type=flowunit, flowunit=yolov7_post, device=cpu, deviceid=0]
    draw_pig_bbox[type=flowunit, flowunit=draw_pig_bbox, device=cpu, deviceid=0]
    video_out[type=flowunit, flowunit=video_out, device=cpu, deviceid=0]
    
    input1:input -> data_source_parser:in_data
    data_source_parser:out_video_url -> video_demuxer:in_video_url
    video_demuxer:out_video_packet -> video_decoder:in_video_packet
    video_decoder:out_video_frame -> image_resize:in_image
    image_resize:out_image -> image_transpose:in_image
    image_transpose:out_image -> normalize:in_data
    normalize:out_data -> yolov7_infer:Input
    yolov7_infer:Output -> yolov7_post:in_feat
    video_decoder:out_video_frame -> draw_pig_bbox:in_image
    yolov7_post:out_data -> draw_pig_bbox:in_box
    draw_pig_bbox:out_image -> video_out:in_video_frame
}"""
[flow]
desc = "yolov7_pig run in modelbox-win10-x64"

yolov7_pig工程graph目录下存放流程图,新建流程图yolov7_pig_http.toml,其内容为(以Windows版ModelBox为例):

ini 复制代码
# Copyright (C) 2020 Huawei Technologies Co., Ltd. All rights reserved.

[driver]
dir = ["${HILENS_APP_ROOT}/etc/flowunit",
"${HILENS_APP_ROOT}/etc/flowunit/cpp",
"${HILENS_APP_ROOT}/model",
"${HILENS_MB_SDK_PATH}/flowunit"]
skip-default = true
[profile]
profile=false
trace=false
dir="${HILENS_DATA_DIR}/mb_profile"
[graph]
format = "graphviz"
graphconf = """digraph yolov7_pig {
    node [shape=Mrecord]
    queue_size = 4
    batch_size = 1
    input1[type=input,flowunit=input,device=cpu,deviceid=0]

    httpserver_sync_receive[type=flowunit, flowunit=httpserver_sync_receive_v2, device=cpu, deviceid=0, time_out_ms=5000, endpoint="http://0.0.0.0:8083/v1/yolov7_pig", max_requests=100]
    image_decoder[type=flowunit, flowunit=image_decoder, device=cpu, key="image_base64", queue_size=4]
    image_resize[type=flowunit, flowunit=resize, device=cpu, deviceid=0, image_width=640, image_height=640]
    image_transpose[type=flowunit, flowunit=packed_planar_transpose, device=cpu, deviceid=0]
    normalize[type=flowunit flowunit=normalize device=cpu deviceid=0 standard_deviation_inverse="0.0039215686,0.0039215686,0.0039215686"]
    yolov7_infer[type=flowunit, flowunit=yolov7_infer, device=cpu, deviceid=0, batch_size = 1]
    yolov7_post[type=flowunit, flowunit=yolov7_post, device=cpu, deviceid=0]
    httpserver_sync_reply[type=flowunit, flowunit=httpserver_sync_reply_v2, device=cpu, deviceid=0]
    
    input1:input -> httpserver_sync_receive:in_url
    httpserver_sync_receive:out_request_info -> image_decoder:in_encoded_image
    image_decoder:out_image -> image_resize:in_image
    image_resize:out_image -> image_transpose:in_image
    image_transpose:out_image -> normalize:in_data
    normalize:out_data -> yolov7_infer:Input
    yolov7_infer:Output -> yolov7_post:in_feat
    yolov7_post:out_data -> httpserver_sync_reply:in_reply_info
}"""
[flow]
desc = "yolov7_pig run in modelbox-win10-x64"

三、运行应用

准备测试视频和测试图片,在yolov7_pet工程目录下修改bin/mock_task.toml配置文件:

shell 复制代码
# 用于本地mock文件读取任务,脚本中已经配置了IVA_SVC_CONFIG环境变量, 添加了此文件路径
########### 请确定使用linux的路径类型,比如在windows上要用  D:/xxx/xxx  不能用D:\xxx\xxx  ###########
# 任务的参数为一个压缩并转义后的json字符串
# 直接写需要转义双引号, 也可以用 content_file 添加一个json文件,如果content和content_file都存在content会被覆盖
# content_file支持绝对路径或者相对路径,不支持解析环境变量(包括${HILENS_APP_ROOT}、${HILENS_DATA_DIR}等)
[common]
content = "{\"param_str\":\"string param\",\"param_int\":10,\"param_float\":10.5}"

# 任务输入配置,mock模拟目前仅支持一路rtsp或者本地url, 当前支持以下几种输入方式:
# 1. rtsp摄像头或rtsp视频流:type="rtsp", url="rtsp://xxx.xxx"  (type为rtsp的时候,支持视频中断自动重连)
# 2. 设备自带摄像头或者USB摄像头:type="url",url="摄像头编号,比如 0 或者 1 等" (需配合local_camera功能单元使用)
# 3. 本地视频文件:type="url",url="视频文件路径" (可以是相对路径 -- 相对这个mock_task.toml文件, 也支持从环境变量${HILENS_APP_ROOT}所在目录文件输入)
# 4. http服务:type="url", url="http://xxx.xxx"(指的是任务作为http服务启动,此处需填写对外暴露的http服务地址,需配合httpserver类的功能单元使用)
# 5. 支持多输入[input] [input1] [input2] ...,对应的输出为[output] [output1] [output2] ...,如果使用videoout功能单元输出,则输入和输出个数必须匹配,同时url不能重名
[input]
type = "url"
url = "${HILENS_APP_ROOT}/data/pig.mp4"

# 任务输出配置,当前支持以下几种输出方式:
# 1. rtsp视频流:type="local", url="rtsp://xxx.xxx" 
# 2. 本地屏幕:type="local", url="0:xxx" (设备需要接显示器,系统需要安装桌面)
# 3. 本地视频文件:type="local",url="视频文件路径" (可以是相对路径------相对这个mock_task.toml文件, 也支持输出到环境变量${HILENS_DATA_DIR}所在目录或子目录)
# 4. http服务:type="webhook", url="http://xxx.xxx" (指的是任务产生的数据上报给某个http服务,此处需填写上传的http服务地址)
[output]
type = "local"
# url = "0:pig_det"  
url = "${HILENS_APP_ROOT}/hilens_data_dir/pig_detection_result.mp4"

yolov7_pig工程目录下执行.\bin\main.bat运行应用:

css 复制代码
(tensorflow) PS D:\modelbox-win10-x64-1.5.3> cd D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig
(tensorflow) PS D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig> .\bin\main.bat     

(tensorflow) D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig>set PATH=D:/modelbox-win10-x64-1.5.3/workspace/yolov7_pig/bin/../../../python-embed;D:/modelbox-win10-x64-1.5.3/workspace/yolov7_pig/bin/../../../modelbox-win10-x64/bin;D:/modelbox-win10-x64-1.5.3/workspace/yolov7_pig/bin/../dependence/lib;C:\Users\yanso\miniconda3\envs\tensorflow\lib\site-packages\pywin32_system32;C:\Users\yanso\miniconda3\envs\tensorflow;C:\Users\yanso\miniconda3\envs\tensorflow\Library\mingw-w64\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Library\usr\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Library\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Scripts;C:\Users\yanso\miniconda3\envs\tensorflow\bin;C:\Users\yanso\miniconda3\condabin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\yanso\miniconda3\envs\tensorflow\lib\site-packages\pywin32_system32;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Library\mingw-w64\bin;C:\Users\yanso\miniconda3\Library\usr\bin;C:\Users\yanso\miniconda3\Library\bin;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\bin;C:\Users\yanso\miniconda3\condabin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin

(tensorflow) D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig>modelbox.exe -c D:/modelbox-win10-x64-1.5.3/workspace/yolov7_pig/bin/../graph/modelbox.conf
[2024-06-18 19:16:51,441][ WARN][    iva_config.cc:143 ] update vas url failed. Fault, no vas projectid or iva endpoint
open log file D:/modelbox-win10-x64-1.5.3/workspace/yolov7_pig/bin/../hilens_data_dir/log/modelbox.log failed, No error
input dims is:1,3,640,640,
output dims is:1,25200,6,
[h264_mf @ 0000000046bab040] MFT name: 'H264 Encoder MFT'
[2024-06-18 19:17:44,535][ WARN][ffmpeg_video_muxer.cc:78  ] Success: video stream has been written to D:/modelbox-win10-x64-1.5.3/workspace/yolov7_pig/hilens_data_dir/pig_detection_result.mp4
[2024-06-18 19:17:44,788][ERROR][flow_scheduler.cc:438 ] the scheduler caught an error : Stop operation
Press any key to continue . . . 

生成的视频保存在yolov7_pig工程目录下hilens_data_dir文件夹中:

yolov7_pig工程目录下执行.\bin\main.bat http开启HTTP服务:

css 复制代码
(tensorflow) PS D:\modelbox-win10-x64-1.5.3> cd D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig                                                                             
(tensorflow) PS D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig> .\bin\main.bat http

(tensorflow) D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig>set PATH=D:/modelbox-win10-x64-1.5.3/workspace/yolov7_pig/bin/../../../python-embed;D:/modelbox-win10-x64-1.5.3/workspace/yolov7_pig/bin/../../../modelbox-win10-x64/bin;D:/modelbox-win10-x64-1.5.3/workspace/yolov7_pig/bin/../dependence/lib;C:\Users\yanso\miniconda3\envs\tensorflow\lib\site-packages\pywin32_system32;C:\Users\yanso\miniconda3\envs\tensorflow;C:\Users\yanso\miniconda3\envs\tensorflow\Library\mingw-w64\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Library\usr\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Library\bin;C:\Users\yanso\miniconda3\envs\tensorflow\Scripts;C:\Users\yanso\miniconda3\envs\tensorflow\bin;C:\Users\yanso\miniconda3\condabin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin;C:\Users\yanso\miniconda3\envs\tensorflow\lib\site-packages\pywin32_system32;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Library\mingw-w64\bin;C:\Users\yanso\miniconda3\Library\usr\bin;C:\Users\yanso\miniconda3\Library\bin;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\bin;C:\Users\yanso\miniconda3\condabin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin;C:\Windows\System32\HWAudioDriverLibs;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0;C:\Windows\System32\OpenSSH;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files\Git\cmd;C:\Users\yanso\miniconda3;C:\Users\yanso\miniconda3\Scripts;C:\Users\yanso\miniconda3\Library\bin;.;C:\Program Files\Git LFS;C:\Users\yanso\AppData\Local\Microsoft\WindowsApps;.;C:\Users\yanso\AppData\Local\Programs\Microsoft VS Code\bin

(tensorflow) D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig>modelbox.exe -c D:/modelbox-win10-x64-1.5.3/workspace/yolov7_pig/bin/../graph/modelbox.conf
[2024-06-18 19:23:53,655][ WARN][    iva_config.cc:143 ] update vas url failed. Fault, no vas projectid or iva endpoint
open log file D:/modelbox-win10-x64-1.5.3/workspace/yolov7_pig/bin/../hilens_data_dir/log/modelbox.log failed, No error
input dims is:1,3,640,640,
output dims is:1,25200,6,

HTTP服务启动后可以在另一个终端进行请求测试,进入yolov7_pig工程目录data文件夹中创建test_http.py脚本然后发起HTTP请求进行测试:

less 复制代码
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved.

import os
import cv2
import json
import base64
import http.client
class HttpConfig:
    '''http调用的参数配置'''
    def __init__(self, host_ip, port, url, img_base64_str):
        self.hostIP = host_ip
        self.Port = port

        self.httpMethod = "POST"
        self.requstURL = url
        self.headerdata = {
            "Content-Type": "application/json"
        }
        self.test_data = {
            "image_base64": img_base64_str
        }
        self.body = json.dumps(self.test_data)
def read_image(img_path):
    '''读取图片数据并转为base64编码的字符串'''
    img_data = cv2.imread(img_path)
    img_str = cv2.imencode('.jpg', img_data)[1].tostring()
    img_bin = base64.b64encode(img_str)
    img_base64_str = str(img_bin, encoding='utf8')

    return img_data, img_base64_str
def decode_car_bboxes(bbox_str, input_shape):
    try:
        labels = [0, 1]  # cat, dog
        bboxes = json.loads(json.loads(bbox_str)['det_result'])
        bboxes = list(filter(lambda x: int(x[5]) in labels, bboxes))
    except Exception as ex:
        print(str(ex))
        return []
    else:
        for bbox in bboxes:
            bbox[0] = int(bbox[0] * input_shape[1])
            bbox[1] = int(bbox[1] * input_shape[0])
            bbox[2] = int(bbox[2] * input_shape[1])
            bbox[3] = int(bbox[3] * input_shape[0])

        return bboxes
def draw_bboxes(img_data, bboxes):
    '''绘制检测框'''
    count = len(bboxes)
    cv2.putText(img_data, 'pig_count: '+str(count), (20, 40), cv2.FONT_HERSHEY_TRIPLEX, 1.5, (255, 0, 0), thickness=2)
    for bbox in bboxes:
        x1, y1, x2, y2, score, label = bbox
        color = (0, 0, 255)
        names = ['pig']  
        score = '%.2f' % score
        label = '%s:%s' % (names[int(label)], score)
        cv2.rectangle(img_data, (x1, y1), (x2, y2), color, 2)
        cv2.putText(img_data, label, (x1, y1 - 10), cv2.FONT_HERSHEY_TRIPLEX, 0.5, (0, 255, 0), thickness=1)

    return img_data, count
def test_image(img_path, ip, port, url):
    '''单张图片测试'''
    img_data, img_base64_str = read_image(img_path)
    http_config = HttpConfig(ip, port, url, img_base64_str)

    conn = http.client.HTTPConnection(host=http_config.hostIP, port=http_config.Port)
    conn.request(method=http_config.httpMethod, url=http_config.requstURL,
                body=http_config.body, headers=http_config.headerdata)

    response = conn.getresponse().read().decode()
    print('response: ', response)

    bboxes = decode_car_bboxes(response, img_data.shape)
    imt_out, count = draw_bboxes(img_data, bboxes)
    cv2.imwrite('./result-' + os.path.basename(img_path), imt_out)

    return count
if __name__ == "__main__":
    port = 8083
    ip = "127.0.0.1"
    url = "/v1/yolov7_pig"
    img_folder = './test_imgs'
    file_list = os.listdir(img_folder)
    for img_file in file_list:
        print("\n================ {} ================".format(img_file))
        img_path = os.path.join(img_folder, img_file)
        count = test_image(img_path, ip, port, url)
        print("================ pig_count: {} ================".format(count))
        

(tensorflow) PS D:\modelbox-win10-x64-1.5.3> cd D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig\data
(tensorflow) PS D:\modelbox-win10-x64-1.5.3\workspace\yolov7_pig\data> D:\modelbox-win10-x64-1.5.3\python-embed\python.exe .\test_http.py

================ 20190515142012.jpg ================
.\test_http.py:33: DeprecationWarning: tostring() is deprecated. Use tobytes() instead.
  img_str = cv2.imencode('.jpg', img_data)[1].tostring()
response:  {"det_result": "[[0.5314995586872101, 0.41453492641448975, 0.6529222667217255, 0.6227057695388794, 0.9563100934028625, 0.0], [0.5491283953189849, 0.6111114203929902, 0.6829706609249114, 0.7607279121875763, 0.9505243301391602, 0.0], [0.7092265635728836, 0.32529172897338865, 0.7929001301527023, 0.5090352058410644, 0.9247245192527771, 0.0], [0.7478243410587311, 0.24942492246627807, 0.8540475308895111, 0.3306758046150208, 0.8886529207229614, 0.0], [0.2863448441028595, 0.7783691227436066, 0.40429784655570983, 0.9388670146465301, 0.8832182288169861, 0.0], [0.3198540091514588, 0.7068635761737824, 0.469990885257721, 0.8155526340007783, 0.8750752806663513, 0.0], [0.8573761910200118, 0.1112288475036621, 0.9163458853960037, 0.24985072612762452, 0.8558010458946228, 0.0], [0.19583110213279725, 0.4393650829792023, 0.3086510717868805, 0.5697859942913055, 0.8494003415107727, 0.0], [0.6343106091022491, 0.031079763174057015, 0.7757764041423798, 0.11533512473106385, 0.8335027098655701, 0.0], [0.32979671955108647, 0.24954813718795776, 0.41185748577117925, 0.4911258816719055, 0.8318935036659241, 0.0], [0.42157947421073916, 0.6686352252960205, 0.5486672222614288, 0.8406521320343017, 0.8014721274375916, 0.0], [0.036364993453025816, 0.3792011857032776, 0.11506653130054473, 0.5173661589622498, 0.7864469289779663, 0.0], [0.18477005362510682, 0.7536652505397796, 0.2830569803714752, 0.9396657049655914, 0.7493076324462891, 0.0], [0.7877487927675247, 0.0820700079202652, 0.8679187029600144, 0.16506505906581878, 0.7153295278549194, 0.0], [0.8873884886503219, 0.4463221430778504, 0.968685844540596, 0.6051429867744447, 0.6919704675674438, 0.0], [0.08014355301856996, 0.73122136592865, 0.14829849600791933, 0.8797563791275025, 0.6634459495544434, 0.0], [0.2530277907848358, 0.7759395956993104, 0.31589220166206355, 0.9465934395790101, 0.6256685853004456, 0.0], [0.059241372346878055, 0.7150145590305328, 0.1196309506893158, 0.8592026650905609, 0.6242099404335022, 0.0], [0.5020054757595062, 0.7558817148208619, 0.6267922461032867, 0.9292884588241578, 0.6164543032646179, 0.0], [0.12215411663055419, 0.6416930139064789, 0.2372045278549194, 0.7511061728000641, 0.5967950224876404, 0.0], [0.5455536484718323, 0.7130935192108154, 0.6122338652610779, 0.8517275333404541, 0.5695550441741943, 0.0]]"}
================ pig_count: 21 ================

================ 20190515142128.jpg ================
response:  {"det_result": "[[0.2530054211616516, 0.3259969651699066, 0.37694138288497925, 0.5073411047458649, 0.9552642107009888, 0.0], [0.7655192792415619, 0.37133423089981077, 0.8948265612125397, 0.5411525130271911, 0.946380078792572, 0.0], [0.7068361639976501, 0.6438457131385803, 0.8532623887062073, 0.7564051985740662, 0.9442737698554993, 0.0], [0.4689387619495392, 0.6953599870204925, 0.6093841254711152, 0.8904086172580719, 0.9394132494926453, 0.0], [0.5610995948314667, 0.41046096086502076, 0.7043379127979279, 0.5980172038078309, 0.9185187816619873, 0.0], [0.1679925262928009, 0.7986599743366241, 0.27840816378593447, 0.9098593890666961, 0.9116157293319702, 0.0], [0.6167296946048737, 0.47176125049591067, 0.7882755696773529, 0.5939736127853393, 0.9113425016403198, 0.0], [0.8483672857284545, 0.558952933549881, 0.9509815454483032, 0.6832078635692597, 0.9013326168060303, 0.0], [0.6976672232151032, 0.05890357494354248, 0.7643234193325044, 0.14790127277374268, 0.8907486200332642, 0.0], [0.3439214825630188, 0.764359337091446, 0.48462504148483276, 0.9410788953304292, 0.8897976875305176, 0.0], [0.9087600618600845, 0.41939428448677063, 0.9657777875661849, 0.5442929446697236, 0.8668227791786194, 0.0], [0.5307900249958039, 0.013786908984184262, 0.6927152812480927, 0.10742981731891632, 0.8617266416549683, 0.0], [0.06923194527626038, 0.2071500480175018, 0.1422653615474701, 0.354218989610672, 0.8515089154243469, 0.0], [0.46218110322952266, 0.543884563446045, 0.5642802119255066, 0.7718154907226563, 0.8315367102622986, 0.0], [0.12014133036136627, 0.7533746421337127, 0.20710271298885347, 0.8859859764575958, 0.8161348700523376, 0.0], [0.6099689096212387, 0.6311885595321655, 0.6959998518228531, 0.8344843149185179, 0.8158949613571167, 0.0], [0.47475093603134155, 0.15836940407752992, 0.5509012818336487, 0.3299554765224457, 0.7964221239089966, 0.0], [0.7360249996185303, 0.20219690799713136, 0.8462663173675538, 0.2739208459854126, 0.7939417958259583, 0.0], [0.8505313932895661, 0.15010038614273072, 0.905955308675766, 0.22253469228744507, 0.766402542591095, 0.0], [0.8721131294965744, 0.3546452701091766, 0.9455597907304764, 0.4159835159778595, 0.7579628825187683, 0.0], [0.8202457576990128, 0.07152213156223297, 0.8842441409826278, 0.16832662522792816, 0.7537699937820435, 0.0], [0.4672187626361847, 0.8035521984100341, 0.6121010005474091, 0.9495066165924071, 0.7330396771430969, 0.0], [0.7931241631507874, 0.07484636306762696, 0.8552763342857361, 0.2041161298751831, 0.7252987623214722, 0.0], [0.05245172083377838, 0.34656997919082644, 0.11882493197917937, 0.4487423300743103, 0.711035966873169, 0.0], [0.039842239022254936, 0.6570722877979278, 0.10100120007991789, 0.7980956733226776, 0.7003825902938843, 0.0], [0.07937039136886598, 0.6993482947349549, 0.14970344305038452, 0.808335554599762, 0.6464911699295044, 0.0], [0.0408034861087799, 0.24992489218711852, 0.08359875082969664, 0.36381874680519105, 0.6194641590118408, 0.0]]"}
================ pig_count: 27 ================

================ 20190515143224.jpg ================
response:  {"det_result": "[[0.33151587247848513, 0.7472196042537689, 0.4520726799964905, 0.944657951593399, 0.9549262523651123, 0.0], [0.6966262102127075, 0.38143407106399535, 0.8187609434127808, 0.5275840640068055, 0.9383824467658997, 0.0], [0.3309335768222809, 0.38504688739776616, 0.5029547631740571, 0.5163029432296753, 0.9308131337165833, 0.0], [0.22159602940082548, 0.2502309620380402, 0.2970270365476608, 0.4074728190898895, 0.9295130372047424, 0.0], [0.52587131857872, 0.6116060733795166, 0.6969760477542877, 0.7392594814300537, 0.9274167418479919, 0.0], [0.8019156157970428, 0.5839392662048339, 0.9134944260120392, 0.6862605094909667, 0.9207823276519775, 0.0], [0.22548656463623046, 0.7824307978153229, 0.3473879337310791, 0.9226225316524506, 0.9075026512145996, 0.0], [0.7616031408309937, 0.23449447751045227, 0.8773191690444947, 0.30470640063285825, 0.8723774552345276, 0.0], [0.47462679147720344, 0.7428544700145722, 0.659464204311371, 0.8985731422901153, 0.8692379593849182, 0.0], [0.7726404637098313, 0.047815185785293576, 0.8582356959581375, 0.16538638472557066, 0.857752799987793, 0.0], [0.04095276296138763, 0.35726237297058105, 0.09002236425876617, 0.4370449066162109, 0.8512980937957764, 0.0], [0.5121502339839935, 0.16153932213783262, 0.5878590166568756, 0.35389813780784607, 0.8481522798538208, 0.0], [0.6813990414142609, 0.5552682638168336, 0.8241379916667939, 0.7315007448196412, 0.8349569439888, 0.0], [0.7848798453807831, 0.2997883439064026, 0.8487448036670685, 0.4219695448875427, 0.8328686952590942, 0.0], [0.675277727842331, 0.5038471221923828, 0.788842660188675, 0.5971584320068359, 0.8305914998054504, 0.0], [0.36567584276199344, 0.1846299886703491, 0.4232009768486023, 0.32693817615509035, 0.8237928748130798, 0.0], [0.8332049459218979, 0.15594483613967897, 0.9077650934457778, 0.21918100118637085, 0.8095088005065918, 0.0], [0.8188231199979782, 0.5099769771099091, 0.9065980225801468, 0.5991565525531769, 0.789814293384552, 0.0], [0.16333829164505004, 0.7263919234275817, 0.23472834825515745, 0.8557828545570373, 0.77839595079422, 0.0], [0.09923059344291688, 0.5434492200613021, 0.2318732798099518, 0.6342397600412368, 0.7709190249443054, 0.0], [0.04113772809505463, 0.6769565641880035, 0.09518382847309112, 0.7874909341335297, 0.7675528526306152, 0.0], [0.12286571264266968, 0.7784929722547531, 0.18941720724105837, 0.8611520320177078, 0.7538224458694458, 0.0], [0.8486063361167908, 0.1046980857849121, 0.8987706780433655, 0.17449078559875486, 0.6860058307647705, 0.0], [0.8597557455301285, 0.3714954495429993, 0.9395408242940902, 0.5046039462089539, 0.6594332456588745, 0.0], [0.725972306728363, 0.2879889786243439, 0.8093014359474182, 0.4364859759807587, 0.6504802703857422, 0.0], [0.80337233543396, 0.43979210257530216, 0.9095016956329346, 0.5416744768619538, 0.5330303907394409, 0.0], [0.0, 0.44415642619132994, 0.03889097571372986, 0.5607487976551055, 0.5000762939453125, 0.0]]"}
================ pig_count: 27 ================

================ 20190515143432.jpg ================
response:  {"det_result": "[[0.6373811900615692, 0.4556077837944031, 0.7505947887897492, 0.6163338780403137, 0.958651065826416, 0.0], [0.7536835551261902, 0.19262979030609134, 0.853804886341095, 0.3675990819931031, 0.9556296467781067, 0.0], [0.24914194345474241, 0.1605188548564911, 0.37957080602645876, 0.2712996304035187, 0.9410728812217712, 0.0], [0.5784417808055878, 0.6893238723278046, 0.7007974922657013, 0.8144921600818634, 0.9311926364898682, 0.0], [0.4877449214458466, 0.838113933801651, 0.6275949299335479, 0.9414070546627045, 0.9248373508453369, 0.0], [0.7326700747013092, 0.5087914645671845, 0.8424749791622161, 0.6524371922016144, 0.9235878586769104, 0.0], [0.6557062178850174, 0.04749650359153747, 0.7422844856977463, 0.22362623810768129, 0.8662278056144714, 0.0], [0.7520786702632904, 0.37903311252593996, 0.8365497171878815, 0.5275002241134643, 0.8632115721702576, 0.0], [0.4560465335845947, 0.7834814339876175, 0.5788590908050537, 0.875244876742363, 0.8591019511222839, 0.0], [0.8486663192510605, 0.24308437108993527, 0.9209946304559707, 0.38057256937026973, 0.8481018543243408, 0.0], [0.06989501118659974, 0.21171223521232607, 0.14719852805137634, 0.2901284992694855, 0.8403106927871704, 0.0], [0.07931529581546784, 0.7274754464626313, 0.14586327970027924, 0.8284106314182282, 0.8276875019073486, 0.0], [0.8199215471744538, 0.5190264046192169, 0.916180557012558, 0.601987999677658, 0.8218949437141418, 0.0], [0.7753406018018723, 0.6247795641422271, 0.869887974858284, 0.7028177678585052, 0.8103967905044556, 0.0], [0.5350410103797912, 0.2904348909854889, 0.7034945845603943, 0.47202824950218203, 0.7742581367492676, 0.0], [0.7052563428878784, 0.594559383392334, 0.7930361032485962, 0.802627182006836, 0.7661027312278748, 0.0], [0.2078638195991516, 0.836474758386612, 0.3327731490135193, 0.9146723210811616, 0.7656165361404419, 0.0], [0.35651546716690063, 0.8356708973646164, 0.48673042058944704, 0.9123004466295243, 0.7651214599609375, 0.0], [0.04286686778068543, 0.651385509967804, 0.1189558446407318, 0.7819379687309265, 0.7318003177642822, 0.0], [0.16353363096714021, 0.7001014947891235, 0.23111434876918796, 0.8483508825302124, 0.7219746112823486, 0.0], [0.8943167269229888, 0.465467381477356, 0.9480641782283782, 0.5696653127670288, 0.7132480144500732, 0.0], [0.13475828468799592, 0.7123962700366974, 0.19173202216625213, 0.8635941207408905, 0.6760420203208923, 0.0], [0.9031854838132858, 0.37944490909576417, 0.9443069249391556, 0.4960151433944702, 0.6697810292243958, 0.0], [0.7169572085142135, 0.051375272870063785, 0.7699337750673294, 0.11804214417934418, 0.5670255422592163, 0.0]]"}
================ pig_count: 24 ================

================ 20190621141141.jpg ================
response:  {"det_result": "[[0.2858048617839813, 0.6920524835586548, 0.40033505558967586, 0.876273512840271, 0.9693846702575684, 0.0], [0.8160727888345719, 0.3245592772960663, 0.9153503984212876, 0.44209216237068183, 0.9652171730995178, 0.0], [0.3276993572711945, 0.2825296759605408, 0.48299114108085633, 0.4778394341468811, 0.9459359049797058, 0.0], [0.7524076730012894, 0.6082898855209351, 0.8520412176847458, 0.7410279512405396, 0.9435095191001892, 0.0], [0.52833012342453, 0.6118248403072357, 0.7453569531440735, 0.7360025942325592, 0.9292019009590149, 0.0], [0.7283130764961242, 0.24003291130065915, 0.8490503191947937, 0.41690392494201656, 0.9274832010269165, 0.0], [0.5753984153270721, 0.7113316237926484, 0.7098467171192169, 0.8695607483386993, 0.9142341613769531, 0.0], [0.3426991164684296, 0.160414856672287, 0.502489310503006, 0.24934423565864564, 0.8892913460731506, 0.0], [0.21955735087394712, 0.14540990591049194, 0.34493497014045715, 0.25439044237136843, 0.8848840594291687, 0.0], [0.17622598409652712, 0.7975501120090485, 0.28576570749282837, 0.894774717092514, 0.8471149206161499, 0.0], [0.4498146414756775, 0.7951198756694794, 0.602517569065094, 0.8975848972797394, 0.8465115427970886, 0.0], [0.336152708530426, 0.7672465980052948, 0.4467101454734802, 0.9145124733448029, 0.8383660912513733, 0.0], [0.8808505088090897, 0.5050277709960938, 0.9662985771894455, 0.6021172523498535, 0.8287425637245178, 0.0], [0.5983243703842164, 0.05242392122745514, 0.7141552209854126, 0.10514067113399506, 0.8067843317985535, 0.0], [0.03119544088840484, 0.5027143061161041, 0.09562594592571258, 0.6602520406246185, 0.8055742383003235, 0.0], [0.3866620540618897, 0.8470147281885146, 0.5265138149261475, 0.9368914455175399, 0.8049367666244507, 0.0], [0.8214336901903153, 0.2318374812602997, 0.8985568493604661, 0.337394791841507, 0.7954773902893066, 0.0], [0.6170122742652893, 0.07954724133014679, 0.7388171553611755, 0.14763021171092988, 0.7868005633354187, 0.0], [0.7230192244052887, 0.07258228063583373, 0.8153064668178558, 0.15148414373397828, 0.7648471593856812, 0.0], [0.050417631864547736, 0.6464603543281555, 0.11656169295310975, 0.7629135966300964, 0.7563851475715637, 0.0], [0.8766493797302246, 0.25733983516693115, 0.929527759552002, 0.373953652381897, 0.731341540813446, 0.0], [0.8231545478105545, 0.10986250042915345, 0.8790049523115159, 0.19118310809135436, 0.7140998840332031, 0.0], [0.10614479780197145, 0.7547796964645386, 0.18728572130203247, 0.8611701250076294, 0.6874741911888123, 0.0], [0.9011492043733597, 0.40590643882751465, 0.9454408377408982, 0.5230727672576905, 0.6780690550804138, 0.0], [0.0784837692975998, 0.7619574457406998, 0.13632536232471468, 0.8540185064077378, 0.602765679359436, 0.0]]"}
================ pig_count: 25 ================

================ 20190621141249.jpg ================
response:  {"det_result": "[[0.32586483359336854, 0.24259638190269472, 0.44065051674842837, 0.4332111418247223, 0.9233660697937012, 0.0], [0.7415802776813507, 0.20339409708976744, 0.8526828944683075, 0.3355763256549835, 0.9134587645530701, 0.0], [0.5598558843135834, 0.06444359421730042, 0.6583136141300201, 0.2255875051021576, 0.9114824533462524, 0.0], [0.25549439787864686, 0.3045780062675476, 0.3439884722232819, 0.5094657063484191, 0.8858470916748047, 0.0], [0.13424646258354186, 0.4089730978012085, 0.25759304165840147, 0.6323755502700805, 0.8812260031700134, 0.0], [0.8928446710109711, 0.36205734610557555, 0.9444068014621735, 0.5137213289737701, 0.8466163277626038, 0.0], [0.23145273327827454, 0.6901010632514953, 0.3217297732830048, 0.8946843981742858, 0.8444425463676453, 0.0], [0.8465079367160797, 0.11456479430198671, 0.89749955534935, 0.22315168976783756, 0.8440980911254883, 0.0], [0.6389145582914353, 0.08545876145362855, 0.7304814606904984, 0.15657412409782412, 0.8438040614128113, 0.0], [0.8596288859844208, 0.2315908432006836, 0.9259816944599152, 0.37012472152709963, 0.8362818956375122, 0.0], [0.3882917046546936, 0.8376923948526382, 0.524693238735199, 0.9266737550497055, 0.8342019319534302, 0.0], [0.6816271901130677, 0.6371851027011872, 0.7663943171501161, 0.8309317529201509, 0.8334851264953613, 0.0], [0.3005506873130798, 0.6813186645507812, 0.3791545510292053, 0.8741531372070311, 0.8274812698364258, 0.0], [0.33739756345748906, 0.33437139391899107, 0.5387834668159486, 0.5037173092365265, 0.8089301586151123, 0.0], [0.8224694639444351, 0.579327318072319, 0.9104406923055649, 0.6655360966920852, 0.8041741847991943, 0.0], [0.6123552083969116, 0.05221189558506012, 0.7181327104568481, 0.11119897067546844, 0.7695637345314026, 0.0], [0.8055596232414245, 0.09786717295646667, 0.8591267704963683, 0.20656116604804992, 0.7643899917602539, 0.0], [0.424746036529541, 0.10845542550086976, 0.5769085884094238, 0.19416474699974062, 0.7628222107887268, 0.0], [0.10420677959918975, 0.7469959199428557, 0.19218709170818327, 0.8613018095493316, 0.7571574449539185, 0.0], [0.17412686347961426, 0.40185985565185545, 0.27423748970031736, 0.5151351928710938, 0.7561619877815247, 0.0], [0.05058914422988891, 0.6416772782802582, 0.1131001591682434, 0.7677843153476716, 0.7416978478431702, 0.0], [0.3409019768238068, 0.7796604573726654, 0.4453953921794892, 0.9214360773563386, 0.7141085863113403, 0.0], [0.18340975642204282, 0.7990216165781021, 0.27464697957038875, 0.8974507421255111, 0.6413347125053406, 0.0], [0.04150465726852417, 0.49037010669708253, 0.08957942724227905, 0.6455666303634644, 0.546801745891571, 0.0]]"}
================ pig_count: 24 ================

================ 20190621141252.jpg ================
response:  {"det_result": "[[0.33483492136001586, 0.24801833033561704, 0.46570180654525756, 0.42209818959236145, 0.9716753363609314, 0.0], [0.2519586384296417, 0.36687822341918946, 0.3474899470806122, 0.5718529701232911, 0.9303265810012817, 0.0], [0.4155482828617096, 0.8238115727901458, 0.533502334356308, 0.9323083460330963, 0.9205400347709656, 0.0], [0.3207600831985473, 0.3376201748847961, 0.5225308179855346, 0.515419566631317, 0.8988451361656189, 0.0], [0.554785406589508, 0.05943803191184999, 0.6596805930137634, 0.22677205204963685, 0.8893870711326599, 0.0], [0.46912367045879366, 0.06897258758544922, 0.5670793324708939, 0.2043828248977661, 0.8699984550476074, 0.0], [0.8252426624298096, 0.4277828633785247, 0.9124511241912842, 0.5882897913455962, 0.8698359131813049, 0.0], [0.6787687718868256, 0.6382624804973602, 0.7658585131168366, 0.8285960018634796, 0.8679203391075134, 0.0], [0.7809970557689666, 0.18303799629211426, 0.8583998024463653, 0.3013877868652344, 0.862260639667511, 0.0], [0.2980193674564362, 0.6860662639141083, 0.3834327161312104, 0.8751100361347199, 0.8417824506759644, 0.0], [0.821492999792099, 0.5867913573980331, 0.9123088419437408, 0.6672211319208144, 0.8390227556228638, 0.0], [0.6389112740755082, 0.0899557739496231, 0.7319891661405564, 0.15791340768337248, 0.8321851491928101, 0.0], [0.33291764855384826, 0.8251787841320037, 0.4365656316280365, 0.954769641160965, 0.8283060789108276, 0.0], [0.8935729414224625, 0.35864530801773076, 0.9461084932088852, 0.5104689955711366, 0.8208484053611755, 0.0], [0.050797092914581295, 0.6406578123569489, 0.11242005825042725, 0.7678249299526214, 0.8082728385925293, 0.0], [0.08978922665119171, 0.7454609930515289, 0.18675152957439423, 0.8624686181545257, 0.8028767704963684, 0.0], [0.23195808827877046, 0.6860327363014221, 0.31602269709110264, 0.8831139922142028, 0.7864329218864441, 0.0], [0.8766951024532319, 0.23855491876602175, 0.9269677698612214, 0.36291831731796265, 0.7816985249519348, 0.0], [0.6164859116077424, 0.051790457963943486, 0.7212261855602264, 0.110322505235672, 0.7430948615074158, 0.0], [0.8110435038805008, 0.095573490858078, 0.8672638386487961, 0.21423617005348206, 0.7066771984100342, 0.0], [0.13872788548469545, 0.4524787902832031, 0.24725345969200135, 0.6506900787353516, 0.6665958762168884, 0.0], [0.8341281533241272, 0.10387264490127564, 0.8950199484825134, 0.2346912741661072, 0.6608691811561584, 0.0], [0.1852737754583359, 0.7818301141262054, 0.28252197802066803, 0.8940926611423492, 0.5649592876434326, 0.0], [0.18228755295276644, 0.38649161458015446, 0.27544007003307347, 0.5115441977977753, 0.5577556490898132, 0.0], [0.3280117630958557, 0.7540877401828766, 0.4142733454704285, 0.9178435266017915, 0.5334183573722839, 0.0]]"}
================ pig_count: 25 ================

================ 20190621141536.jpg ================
response:  {"det_result": "[[0.2564292013645172, 0.33026397228240967, 0.3786363542079925, 0.46099493503570554, 0.9311189651489258, 0.0], [0.2409549355506897, 0.8311348974704742, 0.38049153089523313, 0.9368552148342132, 0.9104359149932861, 0.0], [0.22517320513725278, 0.7295086562633515, 0.35199616551399227, 0.8581309616565704, 0.9079555869102478, 0.0], [0.509332823753357, 0.16211927831172943, 0.678995442390442, 0.2507202297449112, 0.8845471143722534, 0.0], [0.8918281033635139, 0.359416526556015, 0.9418209597468375, 0.5050676882266998, 0.8670594096183777, 0.0], [0.13428189754486083, 0.22141119837760925, 0.23520941734313966, 0.2884054481983185, 0.8528635501861572, 0.0], [0.3410702019929886, 0.3611745774745941, 0.4340797632932663, 0.558493810892105, 0.8483645915985107, 0.0], [0.7241697609424591, 0.07349232137203217, 0.8059853255748749, 0.12879067957401275, 0.8442279696464539, 0.0], [0.6255776345729828, 0.0848228543996811, 0.7324755728244782, 0.146994486451149, 0.8437628746032715, 0.0], [0.653466972708702, 0.670866173505783, 0.746815600991249, 0.820464926958084, 0.8422113656997681, 0.0], [0.6650887668132782, 0.5841597139835358, 0.7750390827655792, 0.768796867132187, 0.8336865901947021, 0.0], [0.2169145882129669, 0.21263003945350648, 0.3436411082744598, 0.3021322667598724, 0.8271554112434387, 0.0], [0.4619706332683563, 0.05729991793632507, 0.6198791325092315, 0.14921229481697082, 0.8270950317382812, 0.0], [0.06911774277687073, 0.6581771194934845, 0.155986088514328, 0.7640855491161346, 0.8267779350280762, 0.0], [0.3990143120288849, 0.14327797889709473, 0.49909006953239443, 0.35340886116027836, 0.8233563899993896, 0.0], [0.8789778590202332, 0.5045474946498871, 0.94303218126297, 0.6238326132297516, 0.8230924606323242, 0.0], [0.3704736530780792, 0.829938891530037, 0.5245399653911591, 0.914329144358635, 0.8186348080635071, 0.0], [0.02738518118858338, 0.28757553100585936, 0.10491183400154114, 0.3996100902557373, 0.8149338364601135, 0.0], [0.797269806265831, 0.09430788457393648, 0.8423305660486221, 0.17682687342166903, 0.8068960309028625, 0.0], [0.03154720366001129, 0.4114041835069656, 0.09893070161342621, 0.4865117520093918, 0.8057674169540405, 0.0], [0.6097052663564682, 0.05152719318866729, 0.7083381563425064, 0.12496560513973236, 0.7765578627586365, 0.0], [0.08852570354938508, 0.7560727655887604, 0.18432852923870086, 0.8482656896114349, 0.7733961343765259, 0.0], [0.8717862963676453, 0.23248609304428097, 0.9263553738594055, 0.3671873688697814, 0.768665611743927, 0.0], [0.18057649135589598, 0.7914771914482117, 0.2740844964981079, 0.8918428540229798, 0.6631293892860413, 0.0], [0.043877321481704715, 0.49001536369323734, 0.08380160927772523, 0.6480004787445068, 0.6335869431495667, 0.0], [0.024194097518920904, 0.3770942836999893, 0.09230124950408936, 0.4345268100500107, 0.6028335690498352, 0.0], [0.05362071692943572, 0.6374618589878083, 0.11426236927509306, 0.7620976388454438, 0.5033589005470276, 0.0]]"}
================ pig_count: 27 ================

================ 20190621141547.jpg ================
response:  {"det_result": "[[0.25542197823524476, 0.3353059649467468, 0.4001975476741791, 0.46317635774612426, 0.9657758474349976, 0.0], [0.19315977990627287, 0.19535972476005556, 0.27108272612094875, 0.33660319447517395, 0.949517011642456, 0.0], [0.43480150699615483, 0.3039972484111786, 0.5892340421676636, 0.4782595932483673, 0.909212052822113, 0.0], [0.37013662457466123, 0.8164689779281616, 0.5137144267559051, 0.9206547021865845, 0.8970624804496765, 0.0], [0.22979669570922853, 0.7306497871875763, 0.35400352478027347, 0.8579780280590058, 0.888817310333252, 0.0], [0.5079127192497254, 0.15616052746772766, 0.6740846753120422, 0.2519838035106659, 0.8762063384056091, 0.0], [0.8885972797870636, 0.35916802287101746, 0.9409824550151825, 0.5116722404956817, 0.8757234811782837, 0.0], [0.3222222745418548, 0.18495855331420902, 0.38973417878150934, 0.34347743988037116, 0.8678868412971497, 0.0], [0.6322253465652465, 0.09085698425769807, 0.7458428144454956, 0.17094678580760958, 0.8662753701210022, 0.0], [0.8779263228178024, 0.5219457924365997, 0.9453038483858108, 0.6253760993480681, 0.8568877577781677, 0.0], [0.5138076961040497, 0.8030386507511139, 0.6839913189411164, 0.9039411008358001, 0.8443552851676941, 0.0], [0.7182290017604828, 0.0744344174861908, 0.8086081564426422, 0.12769191861152648, 0.8384566307067871, 0.0], [0.1342449128627777, 0.7035930752754211, 0.24380694031715394, 0.8636772990226745, 0.8185152411460876, 0.0], [0.041655927896499634, 0.24391731023788454, 0.11607009768486024, 0.3222251534461975, 0.8157849907875061, 0.0], [0.6842417269945145, 0.600456154346466, 0.769045302271843, 0.8204650759696961, 0.807222843170166, 0.0], [0.04178522527217866, 0.428575050830841, 0.09567042887210847, 0.5276386141777039, 0.7973988652229309, 0.0], [0.8679279178380966, 0.2271733820438385, 0.9221431881189347, 0.3715844571590423, 0.7918534278869629, 0.0], [0.10267244279384613, 0.19571231603622435, 0.18719500601291655, 0.27740641832351687, 0.7810215353965759, 0.0], [0.7959055691957474, 0.09352061152458191, 0.8447329729795456, 0.17925546765327455, 0.7788087129592896, 0.0], [0.4553974390029907, 0.060482102632522586, 0.6319695234298706, 0.14058579802513121, 0.7483526468276978, 0.0], [0.15876931250095366, 0.14991192817687987, 0.22859269082546232, 0.26780047416687014, 0.7464203238487244, 0.0], [0.6014808595180511, 0.056060454249382025, 0.7039685308933258, 0.12097258865833282, 0.7415891289710999, 0.0], [0.05432936996221543, 0.6389926671981812, 0.1036943569779396, 0.7548634767532348, 0.7370787262916565, 0.0], [0.08496533930301667, 0.7542163580656052, 0.16024259030818938, 0.8530056267976761, 0.6618684530258179, 0.0], [0.08317945897579193, 0.6818564742803573, 0.15303505957126617, 0.7622250229120254, 0.5794874429702759, 0.0], [0.04344537556171417, 0.5141217648983002, 0.08364923894405366, 0.6476760447025299, 0.504276692867279, 0.0]]"}
================ pig_count: 26 ================

================ 20190621141550.jpg ================
response:  {"det_result": "[[0.6838599711656571, 0.6606208086013794, 0.7710892170667649, 0.8272748708724975, 0.9402938485145569, 0.0], [0.26520926952362056, 0.32953397631645204, 0.38649857044219965, 0.4697645485401154, 0.8982011675834656, 0.0], [0.5156374216079712, 0.15312602519989013, 0.6798028707504273, 0.2708028078079224, 0.8904911875724792, 0.0], [0.36130602955818175, 0.8099759340286256, 0.5101854026317596, 0.9193880796432495, 0.8739372491836548, 0.0], [0.1700303077697754, 0.15172920227050782, 0.23570561408996582, 0.2642632484436035, 0.8728594779968262, 0.0], [0.1329492390155792, 0.21252053380012514, 0.24662813544273374, 0.3257600009441376, 0.8699913620948792, 0.0], [0.8888531982898712, 0.3569968342781067, 0.9418507277965545, 0.5080092310905456, 0.8673768639564514, 0.0], [0.5139020681381226, 0.8026381134986877, 0.6852060556411743, 0.9051722884178162, 0.8656722903251648, 0.0], [0.23541388511657715, 0.7340538442134857, 0.35212721824646, 0.8585911333560944, 0.859419047832489, 0.0], [0.719459256529808, 0.07310810685157776, 0.8092071443796157, 0.12624335885047913, 0.8516564965248108, 0.0], [0.34085788726806643, 0.3349116802215576, 0.5023260116577148, 0.44398775100708004, 0.8464704751968384, 0.0], [0.24616360664367676, 0.13308675289154054, 0.35294475555419924, 0.2814420938491822, 0.8323164582252502, 0.0], [0.795803265273571, 0.09264526665210723, 0.8423913910984994, 0.17893531024456022, 0.8284755349159241, 0.0], [0.4587976574897766, 0.06322473287582397, 0.6270232081413268, 0.14883238077163696, 0.8243702054023743, 0.0], [0.326967653632164, 0.06881043910980225, 0.4206260830163956, 0.2294994354248047, 0.8068063259124756, 0.0], [0.8782558888196945, 0.5038030922412873, 0.943597748875618, 0.6235027015209198, 0.8011397123336792, 0.0], [0.867403370141983, 0.22882308959960937, 0.9206940114498138, 0.3692127227783203, 0.7902088761329651, 0.0], [0.03723717927932739, 0.4061479508876801, 0.0984946608543396, 0.5185569822788239, 0.7802959084510803, 0.0], [0.11167682707309723, 0.763188025355339, 0.1834775060415268, 0.8457253962755203, 0.7796980142593384, 0.0], [0.04055920243263245, 0.23195657432079317, 0.11710016131401063, 0.3247019797563553, 0.7576957941055298, 0.0], [0.6161630868911743, 0.07711478769779206, 0.7365776777267455, 0.16915811002254488, 0.7339129447937012, 0.0], [0.05336735397577286, 0.6376380324363708, 0.10140782445669175, 0.7546170830726624, 0.7209601998329163, 0.0], [0.13452087640762328, 0.7048075258731842, 0.24099754095077514, 0.8507577359676362, 0.7165915369987488, 0.0], [0.17935211658477784, 0.7974438011646271, 0.2714140176773071, 0.897455757856369, 0.6387768387794495, 0.0], [0.08230576813220977, 0.6784022957086563, 0.15640814006328582, 0.7686613410711288, 0.6189611554145813, 0.0], [0.08143793940544128, 0.7604445695877075, 0.1541825830936432, 0.848276400566101, 0.602925181388855, 0.0]]"}
================ pig_count: 26 ================

================ 20190621141553.jpg ================
response:  {"det_result": "[[0.25505531430244444, 0.1648145318031311, 0.36948043704032896, 0.319969117641449, 0.9663053750991821, 0.0], [0.6804072797298432, 0.6567524552345275, 0.7649277269840241, 0.8261979460716247, 0.9214552640914917, 0.0], [0.5162991523742676, 0.1550707459449768, 0.6786110877990723, 0.26980427503585813, 0.89951092004776, 0.0], [0.04029585719108582, 0.39804551005363464, 0.09393433928489686, 0.5120114624500275, 0.8869109749794006, 0.0], [0.2331909120082855, 0.7339452266693115, 0.35462484955787654, 0.8563205242156983, 0.8849216103553772, 0.0], [0.8875470131635665, 0.35947387814521786, 0.9421267539262771, 0.5058832347393035, 0.8830375671386719, 0.0], [0.35890615582466123, 0.8096627533435822, 0.5082674205303193, 0.9209826171398163, 0.8803096413612366, 0.0], [0.22905958890914918, 0.32565538287162776, 0.3996945500373841, 0.466394692659378, 0.8800082206726074, 0.0], [0.3235291659832001, 0.09731526970863341, 0.46806238293647767, 0.2023240029811859, 0.8659636378288269, 0.0], [0.7194619923830032, 0.07266746759414673, 0.8077177256345749, 0.12683988809585572, 0.8515225648880005, 0.0], [0.5173878550529479, 0.8031063377857208, 0.6822316288948058, 0.9041860282421113, 0.8419069051742554, 0.0], [0.7942464396357537, 0.09258331954479218, 0.8421867802739144, 0.17845857441425322, 0.8290656208992004, 0.0], [0.8780211091041564, 0.5133154094219208, 0.9525304198265075, 0.6248787701129913, 0.8264977335929871, 0.0], [0.1312229812145233, 0.23110288381576538, 0.26738985180854796, 0.32273465394973755, 0.8258971571922302, 0.0], [0.1273337364196777, 0.7012694180011749, 0.24159545898437498, 0.8553301990032196, 0.8090124130249023, 0.0], [0.869355183839798, 0.2267285704612732, 0.9228637874126435, 0.37382589578628544, 0.7690571546554565, 0.0], [0.1645243227481842, 0.16016942262649536, 0.23051308989524844, 0.2507018446922302, 0.7572027444839478, 0.0], [0.4552234292030334, 0.06282475888729096, 0.6467123389244078, 0.14914280474185942, 0.7095248699188232, 0.0], [0.6207995533943176, 0.07808120846748351, 0.7318315386772155, 0.17110306620597837, 0.6961165070533752, 0.0], [0.08310246467590332, 0.7593006700277328, 0.16655261516571046, 0.8486085325479508, 0.6946851015090942, 0.0], [0.0550129920244217, 0.6377000391483307, 0.10035936534404755, 0.7601681172847748, 0.6907160878181458, 0.0], [0.1823414504528046, 0.8208630412817001, 0.2753485023975373, 0.8927535206079482, 0.6773250102996826, 0.0], [0.03336356282234192, 0.33990943133831025, 0.09926139712333679, 0.4163350373506546, 0.6322934031486511, 0.0], [0.09137872457504273, 0.6876684784889221, 0.1576262593269348, 0.7882758498191833, 0.5370994806289673, 0.0]]"}
================ pig_count: 24 ================

================ 20190621141702.jpg ================
response:  {"det_result": "[[0.22350141406059268, 0.6762887954711914, 0.3731423199176789, 0.8184487342834472, 0.9548922181129456, 0.0], [0.3554376900196075, 0.8033478677272797, 0.5178024947643279, 0.916188532114029, 0.9342366456985474, 0.0], [0.41963348984718324, 0.10559765100479125, 0.5215966165065765, 0.31351484060287477, 0.9148365259170532, 0.0], [0.24928047060966493, 0.327079701423645, 0.40166056752204893, 0.4416670560836792, 0.8924790620803833, 0.0], [0.5149345755577087, 0.17052462100982668, 0.6779902100563049, 0.29205095767974854, 0.8909578323364258, 0.0], [0.5388258635997771, 0.7447358965873718, 0.6867108643054961, 0.8399172902107239, 0.8849926590919495, 0.0], [0.71777563393116, 0.06494015455245972, 0.7983715027570725, 0.12339491844177246, 0.8744017481803894, 0.0], [0.7954665750265122, 0.5785638570785522, 0.8826254278421403, 0.7036791086196899, 0.8737918138504028, 0.0], [0.6637972176074982, 0.6482859671115876, 0.8199613273143769, 0.7434307992458344, 0.8732413649559021, 0.0], [0.8661074936389923, 0.22600043416023252, 0.9228401839733124, 0.3657041251659393, 0.8627683520317078, 0.0], [0.7602462828159332, 0.11995237469673156, 0.8734313905239105, 0.23398701548576356, 0.8567670583724976, 0.0], [0.8956452071666717, 0.3657357215881347, 0.9450255692005157, 0.5135135650634766, 0.8445569276809692, 0.0], [0.14634484350681304, 0.7393070816993714, 0.23839896619319914, 0.8807906508445741, 0.8305044770240784, 0.0], [0.8794899225234986, 0.5026386678218842, 0.9294854879379273, 0.634317833185196, 0.8270094394683838, 0.0], [0.5092974722385407, 0.815280893445015, 0.6741485536098482, 0.9056802958250046, 0.8193835616111755, 0.0], [0.07616996467113496, 0.21829421520233155, 0.15875621140003204, 0.32190282344818116, 0.8052489757537842, 0.0], [0.6853458523750305, 0.07137364149093627, 0.7411078333854676, 0.2028606295585632, 0.7820446491241455, 0.0], [0.07674590349197388, 0.7687113344669342, 0.14894877672195433, 0.8493100583553314, 0.7341012954711914, 0.0], [0.039960877597332, 0.3126288890838623, 0.08451076298952104, 0.4022897243499756, 0.7196946144104004, 0.0], [0.06600799262523652, 0.6542474508285523, 0.16344936192035675, 0.8114694833755494, 0.6840709447860718, 0.0], [0.5587529957294464, 0.06180830597877503, 0.7073469340801238, 0.2052306354045868, 0.5386325716972351, 0.0], [0.6123762965202332, 0.05824828445911408, 0.7150348782539367, 0.12364704310894013, 0.5344389081001282, 0.0]]"}
================ pig_count: 22 ================

四、本章小结

本章我们介绍了如何使用ModelBox开发一个AI智能数猪的原创应用,我们只需要在之前的基础上重新训练一个猪只目标检测模型进行替换,之后修改配置文件和工程的流程图即可进行视频推理。同时我们可以了解到图片标注、数据处理和模型训练方法,以及对应的推理应用逻辑。

点击关注,第一时间了解华为云新鲜技术~

相关推荐
深度学习lover3 分钟前
<项目代码>YOLOv8 番茄识别<目标检测>
人工智能·python·yolo·目标检测·计算机视觉·番茄识别
IT古董3 分钟前
【机器学习】机器学习中用到的高等数学知识-1.线性代数 (Linear Algebra)
人工智能·python·线性代数·机器学习
飞腾开发者12 分钟前
飞腾平台Arm NN软件栈安装使用指南
linux·运维·人工智能·机器学习·计算机视觉
Watermelo61738 分钟前
通过MongoDB Atlas 实现语义搜索与 RAG——迈向AI的搜索机制
人工智能·深度学习·神经网络·mongodb·机器学习·自然语言处理·数据挖掘
AI算法-图哥1 小时前
pytorch量化训练
人工智能·pytorch·深度学习·文生图·模型压缩·量化
大山同学1 小时前
DPGO:异步和并行分布式位姿图优化 2020 RA-L best paper
人工智能·分布式·语言模型·去中心化·slam·感知定位
机器学习之心1 小时前
时序预测 | 改进图卷积+informer时间序列预测,pytorch架构
人工智能·pytorch·python·时间序列预测·informer·改进图卷积
天飓1 小时前
基于OpenCV的自制Python访客识别程序
人工智能·python·opencv
檀越剑指大厂1 小时前
开源AI大模型工作流神器Flowise本地部署与远程访问
人工智能·开源
声网1 小时前
「人眼视觉不再是视频消费的唯一形式」丨智能编解码和 AI 视频生成专场回顾@RTE2024
人工智能·音视频