コード例 #1
0
    def test_create_instance(self):
        PipelineManager.pipeline_types = {
            "GStreamer": lambda id, config, models: "Instance"
        }

        PipelineManager.pipelines = {
            "object_detection": {
                "1": {
                    "name": "object_detection",
                    "version": 1,
                    "type": "GStreamer",
                    "template": "",
                    "description": "Object Detection Pipeline",
                    "parameters": {
                        "send-empty": {
                            "element": "jsonmetaconvert"
                        },
                        "every-nth-frame": {
                            "element": "detection"
                        }
                    }
                }
            }
        }

        expected_result = "Instance"
        result = PipelineManager.create_instance("object_detection", 1)

        self.assertEqual(result, expected_result)
コード例 #2
0
def pipelines_name_version_post(name, version):  # noqa: E501
    """pipelines_name_version_post

    Start new instance of pipeline. Specify the source and destination parameters as URIs # noqa: E501

    :param name: 
    :type name: str
    :param version: 
    :type version: int
    :param pipeline_request: 
    :type pipeline_request: dict | bytes

    :rtype: None
    """

    logger.debug("POST on /pipelines/{name}/{version}".format(name=name, version=version))
    if connexion.request.is_json:
        try:
            pipeline_id, err = PipelineManager.create_instance(name, version, connexion.request.get_json())
            if pipeline_id is not None:
                return pipeline_id
            return (err, HTTPStatus.BAD_REQUEST)
        except Exception as e:
            logger.error('pipelines_name_version_post ' +str(e))
            return ('Unexpected error', HTTPStatus.INTERNAL_SERVER_ERROR)
コード例 #3
0
    def loop(self, reqs, pipeline, version="1"):
        print(reqs, flush=True)
        pid, msg = PipelineManager.create_instance(pipeline, version, reqs)
        if pid is None:
            print("Exception: " + str(msg), flush=True)
            return -1
        fps = 0
        while True:
            self._maincontext.iteration()
            pinfo = PipelineManager.get_instance_status(pipeline, version, pid)
            print(pinfo, flush=True)
            if pinfo is not None:
                state = pinfo["state"]
                if state == "COMPLETED":
                    fps = pinfo["avg_fps"]
                    print("Status analysis: Timing {0} {1} {2} {3} {4}".format(
                        reqs["start_time"], pinfo["start_time"],
                        pinfo["elapsed_time"], reqs["user"],
                        reqs["source"]["uri"]),
                          flush=True)
                    break
                if state == "ABORTED" or state == "ERROR": return -1

        PipelineManager.stop_instance(pipeline, version, pid)
        return fps
コード例 #4
0
ファイル: runva.py プロジェクト: yimm0815/Ad-Insertion-Sample
    def loop(self, reqs, pipeline, version="1"):
        print(reqs, flush=True)
        pid, msg = PipelineManager.create_instance(pipeline, version, reqs)
        if pid is None:
            print("Exception: " + str(msg), flush=True)
            return -1
        fps = 0
        while True:
            self._maincontext.iteration()
            pinfo = PipelineManager.get_instance_status(pipeline, version, pid)
            print(pinfo, flush=True)
            if pinfo is not None:
                state = pinfo["state"]
                if state == "COMPLETED": break
                if state == "ABORTED" or state == "ERROR": return -1
                fps = pinfo["avg_fps"]

        PipelineManager.stop_instance(pipeline, version, pid)
        return fps
コード例 #5
0
    def test_create_instance(self):
        mock_pipeline = type("MockPipeline", (object,), dict(start=lambda : "started"))
        PipelineManager.pipeline_types = {
            "GStreamer": lambda id, config, models, request: mock_pipeline
        }

        PipelineManager.pipelines = {
            "object_detection": {
                "1": {
                    "name": "object_detection",
                    "version": 1,
                    "type": "GStreamer",
                    "template": "",
                    "description": "Object Detection Pipeline",
                    "parameters": {
                        "send-empty": {
                            "element":"jsonmetaconvert"
                        },
                        "every-nth-frame": {
                            "element":"detection"
                        }
                    }
                }
            }
        }

        request_to_send = {
            'source': {
                'uri': 'path_to_source', 
                'type': 'uri'
            }, 
            'destination': {
                'uri': 'path_to_destination', 
                'type': 'file'
            }
        }
        expected_result = 1
        result = PipelineManager.create_instance("object_detection", 1, request_to_send)

        self.assertEqual(result, expected_result)
コード例 #6
0
def pipelines_name_version_post(name, version):  # noqa: E501
    """pipelines_name_version_post

    Start new instance of pipeline. Specify the source and destination parameters as URIs # noqa: E501

    :param name: 
    :type name: str
    :param version: 
    :type version: int
    :param pipeline_request: 
    :type pipeline_request: dict | bytes

    :rtype: None
    """

    logger.debug("POST on /pipelines/{name}/{version}".format(name=name,
                                                              version=version))
    if connexion.request.is_json:
        pipeline = PipelineManager.create_instance(name, version)
        pipeline.start(connexion.request.get_json())

    return pipeline.id
コード例 #7
0
ファイル: runva.py プロジェクト: UBSTR/Smart-City
    def loop(self,
             sensor,
             location,
             uri,
             algorithm,
             algorithmName,
             resolution={
                 "width": 0,
                 "height": 0
             },
             zonemap=[],
             topic="analytics"):

        pid, msg = PipelineManager.create_instance(
            self._pipeline,
            self._version,
            {
                "source": {
                    "uri": uri,
                    "type": "uri"
                },
                "destination": {
                    "type": "mqtt",
                    "host": mqtthost,
                    "clientid": algorithm,
                    "topic": topic,
                },
                "tags": {
                    "sensor": sensor,
                    "location": location,
                    "algorithm": algorithm,
                    "office": {
                        "lat": office[0],
                        "lon": office[1],
                    },
                },
                "parameters": {
                    "crowd_count": {  # crowd-counting only
                        "width": resolution["width"],
                        "height": resolution["height"],
                        "zonemap": zonemap
                    },
                    "every-nth-frame": every_nth_frame,
                    "recording_prefix": "/tmp/" + sensor,
                },
            })

        if pid is None:
            print("Exception: " + str(msg), flush=True)
            return

        while not self._stop:
            self._maincontext.iteration()
            pinfo = PipelineManager.get_instance_status(
                self._pipeline, self._version, pid)
            if pinfo is not None:
                print(pinfo, flush=True)
                state = pinfo["state"]
                if state == "COMPLETED" or state == "ABORTED" or state == "ERROR":
                    print("pineline ended with " + str(state), flush=True)
                    break

                if pinfo["avg_fps"] > 0 and state == "RUNNING":
                    if "avg_pipeline_latency" not in pinfo:
                        pinfo["avg_pipeline_latency"] = 0
                    self._db.update(
                        algorithm, {
                            "sensor": sensor,
                            "performance": pinfo["avg_fps"],
                            "latency": pinfo["avg_pipeline_latency"] * 1000,
                        })

        print("exiting va pipeline", flush=True)
        PipelineManager.stop_instance(self._pipeline, self._version, pid)