forked from konny0311/amazon-sagemaker-visual-search
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest.py
More file actions
54 lines (47 loc) · 1.34 KB
/
test.py
File metadata and controls
54 lines (47 loc) · 1.34 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
54
# locally
# docker run -v -d -p 8080:8080 image-embedding
import requests
import json
url='http://localhost:8080/invocations'
bucket = 'sagemaker-cn-northwest-1-343958593302'
image_uri = 'image-embedding/1.jpg'
test_data = {
'bucket' : bucket,
'image_uri' : image_uri,
'content_type': "application/json",
}
payload = json.dumps(test_data)
r = requests.post(url,data=payload)
print(r.json())
# on sagemaker
# python create_endpoint
import boto3
from botocore.config import Config
from boto3.session import Session
import json
config = Config(
read_timeout=120,
retries={
'max_attempts': 0
}
)
def infer(input_image):
bucket = 'sagemaker-cn-northwest-1-343958593302'
image_uri = input_image
test_data = {
'bucket' : bucket,
'image_uri' : image_uri,
'content_type': "application/json",
}
payload = json.dumps(test_data)
print(payload)
sagemaker_runtime_client = boto3.client('sagemaker-runtime', config=config)
session = Session(sagemaker_runtime_client)
# runtime = session.client("runtime.sagemaker",config=config)
response = sagemaker_runtime_client.invoke_endpoint(
EndpointName='image-embedding',
ContentType="application/json",
Body=payload)
result = json.loads(response["Body"].read())
print (result)
infer('image-embedding/1.jpg')