1 Answer
- Newest
- Most votes
- Most comments
0
It is hard to say if the input tensor name is wrong without having access to the notebook and the other artifacts but I guess the name of the input tensor might be wrong. TF uses dynamic names for the tensors when you don't specify and the sequence is incremented each time you load the model using the same runtime session. It starts with input_1 then input_2 and so on. Another point is that you're using the estimator to invoke Neo. This library is sometimes outdated. I prefer to use boto3 instead. I wrote a sample code to test the compilation. The following code is working perfectly with your model:
## Load a pre-trained Keras model and export in Tensorflow format
import tensorflow as tf
from tensorflow.keras.applications import nasnet
import numpy as np
model = tf.keras.applications.nasnet.NASNetMobile(weights='imagenet')
x = tf.random.uniform((1, 224, 224, 3))
y = model(x)
export_dir = 'export/1'
tf.saved_model.save(model, export_dir)
## Put the model into a tar ball and send to S3
import sagemaker
import tarfile
import io
model_archive = 'model.tar.gz'
model_name='nasnet-mobile'
img_size=224
sagemaker_session = sagemaker.Session()
default_bucket = sagemaker_session.default_bucket()
with io.BytesIO() as f:
with tarfile.open(fileobj=f, mode="w:gz") as tar:
tar.add('export')
tar.list()
f.seek(0)
s3_uri = sagemaker_session.upload_string_as_file_body(f.read(), default_bucket, f"models/{model_name}/model.tar.gz")
print(s3_uri)
## Now kick-off a compilation job
import time
import boto3
import sagemaker
role = sagemaker.get_execution_role()
sm_client = boto3.client('sagemaker')
framework='tensorflow'
img_size=224
input_shape=f"1,{img_size},{img_size},3"
compilation_job_name = f'{model_name}-{framework}-{int(time.time()*1000)}'
sm_client.create_compilation_job(
CompilationJobName=compilation_job_name,
RoleArn=role,
InputConfig={
'S3Uri': s3_uri,
'DataInputConfig': f'{{"{model.layers[0].name}": [{input_shape}]}}',
'Framework': framework.upper(),
'FrameworkVersion': '2.4'
},
OutputConfig={
'S3OutputLocation': f's3://{default_bucket}/{model_name}-{framework}/optimized/',
'TargetDevice': 'ml_c5',
# Comment or change the following line depending on your edge device
# Jetson Xavier: sm_72; Jetson Nano: sm_53
#'CompilerOptions': '{"trt-ver": "7.1.3", "cuda-ver": "10.2", "gpu-code": "sm_72"}' # Jetpack 4.4.1
},
StoppingCondition={ 'MaxRuntimeInSeconds': 18000 }
)
while True:
resp = sm_client.describe_compilation_job(CompilationJobName=compilation_job_name)
if resp['CompilationJobStatus'] in ['STARTING', 'INPROGRESS']:
print('Running...')
else:
print(resp['CompilationJobStatus'], compilation_job_name)
break
time.sleep(5)
Just notice that I'm using FrameworkVersion = 2.4. There is not information about that in your sample.
answered 2 years ago
Relevant content
- asked a year ago
- asked 2 years ago
- AWS OFFICIALUpdated 3 years ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 3 years ago