Skip to content
This repository has been archived by the owner on Jul 10, 2023. It is now read-only.

Commit

Permalink
Add LVA client (#42)
Browse files Browse the repository at this point in the history
Add LVA test client
  • Loading branch information
Henry Bruce committed Oct 29, 2020
1 parent 01223b0 commit 37a10aa
Show file tree
Hide file tree
Showing 5 changed files with 407 additions and 7 deletions.
5 changes: 1 addition & 4 deletions samples/lva_ai_extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,7 @@ $ docker logs video-analytics-serving-lva-ai-extension_latest -f
```

## Test Client
The test client script `run_client.sh` sends frames(s) to the extension server.
> The above mentioned test client script is not available in GitHub at this time. We may include it in future. If you try to use it, you will get this error:
>> python3: can't open file '/home/video-analytics-serving/samples/lva_ai_extension/client': [Errno 2] No such file or directory
The test client script `run_client.sh` sends frames(s) to the extension server and prints inference results.
Use the --help option to see how to use the script. All arguments are optional.

```
Expand Down
83 changes: 83 additions & 0 deletions samples/lva_ai_extension/client/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
'''
* Copyright (C) 2019-2020 Intel Corporation.
*
* SPDX-License-Identifier: MIT License
'''

'''
* MIT License
*
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
'''

import sys

import logging
import os
from media_stream_processor import MediaStreamProcessor
from arguments import parse_args
from samples.lva_ai_extension.common.exception_handler import log_exception

def _log_options(args):
heading = "Options for {}".format(os.path.basename(__file__))
banner = "="*len(heading)
logging.info(banner)
logging.info(heading)
logging.info(banner)
for arg in vars(args):
logging.info("{} == {}".format(arg, getattr(args, arg)))
logging.info(banner)


def main():
try:
# Get application arguments
args = parse_args()

_log_options(args)

# Run stream processer loop
msp = MediaStreamProcessor(args.grpc_server_address,
args.sample_file,
args.loop_count,
args.use_shared_memory)
msp.start()

except:
log_exception()
exit(-1)

if __name__ == "__main__":
# Set logging parameters
logging.basicConfig(
level=logging.INFO,
format='[AIXC] [%(asctime)-15s] [%(threadName)-12.12s] [%(levelname)s]: %(message)s',
handlers=[
#logging.FileHandler(LOG_FILE_NAME), # write in a log file
logging.StreamHandler(sys.stdout) # write in stdout
]
)

# Call Main logic
main()

logging.info('Client finished execution')

70 changes: 70 additions & 0 deletions samples/lva_ai_extension/client/arguments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
'''
* Copyright (C) 2019-2020 Intel Corporation.
*
* SPDX-License-Identifier: MIT License
'''

'''
* MIT License
*
* Copyright (c) Microsoft Corporation.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE
'''

import argparse
from enum import Enum

def parse_args(args=None, program_name="AI Extension Sample Client"):
parser = argparse.ArgumentParser(prog=program_name,fromfile_prefix_chars='@',
formatter_class=argparse.ArgumentDefaultsHelpFormatter)


parser.add_argument('-s', metavar=('grpc_server_address'),
dest = "grpc_server_address",
help='gRPC server address.',
default="localhost:5001")

parser.add_argument('-f', metavar=('sample_file'),
dest = "sample_file",
help='Name of the sample video frame.',
default="/home/video-analytics-serving/samples/lva_ai_extension/sampleframes/sample01.png"
)

parser.add_argument('-l', metavar=('loop_count'),
dest = "loop_count",
help='How many times to send sample video frame.',
type=int,
default = 1)

parser.add_argument('-m', action='store_const',
dest='use_shared_memory',
const=True,
default=False,
help='set to use shared memory')

parser.add_argument('--version', action='version', version='%(prog)s 1.0')

if (isinstance(args, dict)):
args = ["--{}={}".format(key, value)
for key, value in args.items() if value]

return parser.parse_args(args)


Loading

0 comments on commit 37a10aa

Please sign in to comment.