Skip to content

Instantly share code, notes, and snippets.

@hariby
Created July 2, 2019 01:56
Show Gist options
  • Save hariby/83679900c49b1c0e735c5c7f1051ffce to your computer and use it in GitHub Desktop.
Save hariby/83679900c49b1c0e735c5c7f1051ffce to your computer and use it in GitHub Desktop.
Simple example for pre-trained model deployment with Amazon SageMaker.
# Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License").
# You may not use this file except in compliance with the License.
# A copy of the License is located at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
import os
import mxnet as mx
def model_fn(model_dir):
ctx = mx.cpu()
sym, arg_params, aux_params = mx.model.load_checkpoint(os.path.join(model_dir, 'resnet-18'), 0)
mod = mx.mod.Module(symbol=sym, context=ctx, label_names=None)
mod.bind(for_training=False, data_shapes=[('data', (1,3,224,224))],
label_shapes=mod._label_shapes)
mod.set_params(arg_params, aux_params, allow_missing=True)
return mod
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment