|
| 1 | +# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"). You |
| 4 | +# may not use this file except in compliance with the License. A copy of |
| 5 | +# the License is located at |
| 6 | +# |
| 7 | +# http://aws.amazon.com/apache2.0/ |
| 8 | +# |
| 9 | +# or in the "license" file accompanying this file. This file is |
| 10 | +# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF |
| 11 | +# ANY KIND, either express or implied. See the License for the specific |
| 12 | +# language governing permissions and limitations under the License. |
| 13 | + |
| 14 | +"""Exports a toy TensorFlow model. |
| 15 | +Exports a TensorFlow model to /opt/ml/model/ |
| 16 | +This graph calculates, |
| 17 | + y = a*x + b |
| 18 | +where a and b are variables with a=0.5 and b=2. |
| 19 | +""" |
| 20 | +import json |
| 21 | +import shutil |
| 22 | + |
| 23 | + |
| 24 | +def save_model(): |
| 25 | + shutil.copytree('/opt/ml/code/123', '/opt/ml/model/123') |
| 26 | + |
| 27 | + |
| 28 | +def input_handler(data, context): |
| 29 | + data = json.loads(data.read().decode('utf-8')) |
| 30 | + new_values = [x + 1 for x in data['instances']] |
| 31 | + dumps = json.dumps({'instances': new_values}) |
| 32 | + return dumps |
| 33 | + |
| 34 | + |
| 35 | +def output_handler(data, context): |
| 36 | + response_content_type = context.accept_header |
| 37 | + prediction = data.content |
| 38 | + return prediction, response_content_type |
| 39 | + |
| 40 | + |
| 41 | +if __name__ == "__main__": |
| 42 | + save_model() |
| 43 | + |
0 commit comments