Giter Club home page Giter Club logo

Comments (6)

nnshah1 avatar nnshah1 commented on July 28, 2024

@vtimofeev01,

Most likely there is an exception being thrown in your gvapython code either on initialization or when saving data.

Before starting VA Serving, you can increase the GST_DEBUG level to 3 (you can do this via environment variable) which in most cases will give you more information on the error in the python script.

If possible - if you can share the:

  1. pipeline
  2. gvapython script

We might be able to see more easily what might be the issue - but I suspect a python exception.

I've added here a simple example of the gvapython code for dumping the caps from a pipeline to a file.

'''
* Copyright (C) 2019-2020 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
'''
import os
import json

class FrameInfo:

    def __init__(self):
        self._output_path = "/tmp"
        self._initialized = False
        self._source = "example"

    def write_caps(self, frame):
        path = "{}/caps.json".format(self._output_path)
        try:
            os.makedirs(self._output_path,exist_ok=True)
            os.remove(path)
        except Exception as e:
            pass
        
        with open(path,"w") as file:
            value = {'caps':str(frame.video_info().to_caps()),
                     'source':self._source}
            file.write(json.dumps(value))
            file.flush()

    @staticmethod
    def read_caps(input_path):
        path = "{}/caps.json".format(input_path)
        caps = None
        with open(path,"r") as file:
            caps = json.load(file)
            
        return caps
        
    
    def process_frame(self,frame):
        if (not self._initialized):
            self.write_caps(frame)
            self._initialized = True
        return True

from pipeline-server.

vtimofeev01 avatar vtimofeev01 commented on July 28, 2024

Sorry that was my fault, storing is working well
but I can`t send kwarg argument to gvapython (by starting the script via sh all works well)

i tried something like this:

{
  "name": "main_settings",
  "version": 2,
  "type": "GStreamer",
  "template": [
    "urisourcebin buffer-size=4096 name=source ! decodebin ! videoconvert ! video/x-raw,format=BGR ! queue ! ",
    "gvadetect model-instance-id=inf0 model={models[person-detection-retail-0013][1][network]} model-proc={models[person-detection-retail-0013][1][proc]} name=detection ! queue ! ",
    "gvapython module=\"/home/openvino/gst/main/py_modules/test_area.py\" class=FrameInfo name=main ! ",
    "appsink name=appsink"
  ],
  "description": "persons detection w.o. face recognition",
  "parameters": {
    "type": "object",
    "properties": {
      "kwarg": {
          "element": "main",
          "type": "string",
          "default": "{\"config\":\"/home/openvino/gst/main/model_proc/filter_detections.json\",\"cam_name\":\"CAM_00\"}"
      }
    }
  }
}

from pipeline-server.

nnshah1 avatar nnshah1 commented on July 28, 2024

https://github.com/OpenVisualCloud/Smart-City-Sample/blob/master/analytics/crowd/Xeon/gst/pipeline/2/pipeline.json

Please add a "format":"json" property to the parameter. You can see the example above from smart city. Apologies as we haven't documented this requirement yet.

"element": {
"name": "crowdcounting",
"property": "kwarg",
"format": "json"
},

from pipeline-server.

vtimofeev01 avatar vtimofeev01 commented on July 28, 2024

I tried, but the script doesn't got kwarg...

{
"name": "main_settings",
"version": 2,
"type": "GStreamer",
"template": [
"urisourcebin buffer-size=4096 name=source ! decodebin ! videoconvert ! video/x-raw,format=BGR ! queue ! ",
"gvadetect model-instance-id=inf0 model={models[person-detection-retail-0013][1][network]} model-proc={models[person-detection-retail-0013][1][proc]} name=detection ! queue ! ",
"gvapython module="/home/openvino/gst/main/py_modules/test_area.py" class=FrameInfo name=main ! ",
"appsink name=appsink"
],
"description": "persons detection w.o. face recognition",
"parameters": {
"type": "object",
"properties": {
"main": {
"element": {
"name": "main",
"property": "kwarg",
"format": "json"
},
"type": "object",
"properties": {
"width": {
"type": "integer",
"default": 100
},
"height": {
"type": "integer",
"default": 200
},
"zonemap": {
"type": "array",
"items": {
"type": "object"
}
}
}
}
}
}
}

py:
`import os
import json
import cv2
from datetime import datetime
class FrameInfo:

def __init__(self, height=1, width=1, zonemap=[]):
    self._output_path = "/home/openvino/area"
    self._initialized = False
    self._source = "example"
    self.k = {'h': height, 'w': width}

def write_caps(self, frame):
    path = "{}/caps2.json".format(self._output_path)
    try:
        os.makedirs(self._output_path, exist_ok=True)
        os.remove(path)
    except Exception as e:
        pass

    with open(path, "w") as file:
        file.write(json.dumps(self.k))
        file.flush()
    with frame.data() as mat:
        cv2.imwrite(os.path.join(self._output_path, 'im.jpg'), img=mat)

@staticmethod
def read_caps(input_path):
    path = "{}/caps2.json".format(input_path)
    caps = None
    with open(path, "r") as file:
        caps = json.load(file)

    return caps

def process_frame(self, frame):
    if (not self._initialized):
        self.write_caps(frame)
        self._initialized = True
    return True`

but in json I get:
{"h": 1, "w": 1}

PS Image is stored well
Thank U

from pipeline-server.

nnshah1 avatar nnshah1 commented on July 28, 2024

The default value for the object needs to be specified at the parameter level and not in the individual properties (due to a quirk in how default values are applied).

Pipeline Definition:

{
	"type": "GStreamer",
	"template": ["videotestsrc ! gvapython name=main module=temp.py class=Test ! fakesink"],
	"description": "Test Pipeline",
	"parameters": {
	    "type": "object",
	    "properties": {
		"main":{
		    "element": {
			"name":"main",
			"format":"json",
			"property":"kwarg"
		    },
		    "type":"object",
		    "properties": {
			"height": {
			    "type":"integer",
			    "minimum":1,
			    "maximum":200
			},
			"width": {
			    "type":"integer",
			    "minimum":1,
			    "maximum":100
			}
		    },
		    "default": {
			"height":100,
			"width":100
		    }
		}
	    }
	}
}

gvapython code

class Test:
    def __init__(self,height,width):
        print(height,width)

    def process_frame(self,frame):
        pass

Simple va serving code example:

'''
* Copyright (C) 2019 Intel Corporation.
*
* SPDX-License-Identifier: BSD-3-Clause
'''

import os
import json

from vaserving.vaserving import VAServing


request = {
    "source": {
        "uri": "file:///example",
        "type": "uri"
    },
    "destination": {
        "type":"file",
        "path":"/dev/stdout"
    }
}


if __name__=="__main__":

    
    VAServing.start({'log_level': 'DEBUG',
                     "ignore_init_errors":True})


    pipeline = VAServing.pipeline("test", 1)

    parameters = {}
    # uncomment to change default
    # parameters = {"main":{"height":50,"width":6}}
    
    pipeline.start(request,
                   parameters=parameters)
    
    
    VAServing.stop()

from pipeline-server.

vtimofeev01 avatar vtimofeev01 commented on July 28, 2024

Thank U
It s great
please put it into your documentation (how to make a json)! all python-zombi will be glad about josinifying of args and kwargs

from pipeline-server.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.