-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathservice.py
More file actions
53 lines (43 loc) · 1.43 KB
/
Copy pathservice.py
File metadata and controls
53 lines (43 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from __future__ import print_function
import urllib.request
import os
import subprocess
import boto3
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
LIB_DIR = os.path.join(SCRIPT_DIR, 'lib')
def downloadFromS3(strBucket,strKey,strFile):
s3_client = boto3.client('s3')
s3_client.download_file(strBucket, strKey, strFile)
def handler(event, context):
try:
imgfilepath = '/tmp/inputimage.jpg'
if ('imagelink' in event):
urllib.request.urlretrieve(event['imagelink'], imgfilepath)
else:
strBucket = 'myqueuecounter'
strKey = 'darknet/street.jpg'
downloadFromS3(strBucket,strKey,imgfilepath)
print(imgfilepath)
strBucket = 'myqueuecounter'
strKey = 'darknet/yolov3.weights'
strWeightFile = '/tmp/yolov3.weights'
downloadFromS3(strBucket,strKey,strWeightFile)
print(strWeightFile)
command = './darknet detect cfg/yolov3.cfg {} {}'.format(
strWeightFile,
imgfilepath
)
print(command)
try:
print('Start')
output = subprocess.check_output(command, shell=True, stderr=subprocess.STDOUT)
print('Finish')
print(output)
except subprocess.CalledProcessError as e:
print('Error')
print(e.output)
except Exception as e:
print('Error e')
print(e)
raise e
return 0