# TensorFlow

Export your trained model and zip the model directory. An example is shown below (here is the complete example):

`import tensorflow as tfimport shutilimport os​...​classifier = tf.estimator.Estimator(    model_fn=my_model, model_dir="iris", params={"hidden_units": [10, 10], "n_classes": 3})​exporter = tf.estimator.FinalExporter("estimator", serving_input_fn, as_text=False)train_spec = tf.estimator.TrainSpec(train_input_fn, max_steps=1000)eval_spec = tf.estimator.EvalSpec(eval_input_fn, exporters=[exporter], name="estimator-eval")​tf.estimator.train_and_evaluate(classifier, train_spec, eval_spec)​# zip the estimator export dir (the exported path looks like iris/export/estimator/1562353043/)shutil.make_archive("tensorflow", "zip", os.path.join("iris/export/estimator"))`

Upload the zipped file to Amazon S3 using the AWS web console or CLI:

`\$ aws s3 cp model.zip s3://my-bucket/model.zip`

Reference your model in an `api`:

`- kind: api  name: my-api  model: s3://my-bucket/model.zip`

# ONNX

Export your trained model to an ONNX model format. An example of an sklearn model being exported to ONNX is shown below:

`from sklearn.linear_model import LogisticRegressionfrom onnxmltools import convert_sklearnfrom onnxconverter_common.data_types import FloatTensorType​...​logreg_model = LogisticRegression(solver="lbfgs", multi_class="multinomial")logreg_model.fit(X_train, y_train)​# Convert to ONNX model formatonnx_model = convert_sklearn(logreg_model, initial_types=[("input", FloatTensorType([1, 4]))])with open("sklearn.onnx", "wb") as f:    f.write(onnx_model.SerializeToString())`

Here are complete examples of converting models from some of the common ML frameworks to ONNX:

Upload your trained model in ONNX format to Amazon S3 using the AWS web console or CLI:

`\$ aws s3 cp model.onnx s3://my-bucket/model.onnx`

Reference your model in an `api`:

`- kind: api  name: my-api  model: s3://my-bucket/model.onnx`
{"ft_lang_label":"__label__en","ft_lang_prob":0.5013891,"math_prob":0.92097706,"size":1877,"snap":"2019-35-2019-39","text_gpt3_token_len":472,"char_repetition_ratio":0.13828084,"word_repetition_ratio":0.18085106,"special_character_ratio":0.23601492,"punctuation_ratio":0.21818182,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9816479,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-09-21T16:03:35Z\",\"WARC-Record-ID\":\"<urn:uuid:56628431-81ed-4d67-a00a-55b7404ba69b>\",\"Content-Length\":\"248791\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:abe56ec2-e774-4756-9378-5e13c166e2e2>\",\"WARC-Concurrent-To\":\"<urn:uuid:46adc3dc-5712-4223-b773-369ff5038a62>\",\"WARC-IP-Address\":\"45.55.238.214\",\"WARC-Target-URI\":\"https://docs.cortex.dev/model-deployments/packaging-models\",\"WARC-Payload-Digest\":\"sha1:IXO3FALJVZXDP66JP5JOJKSLTLQ3MNEO\",\"WARC-Block-Digest\":\"sha1:FWFUTQUBLEWG3UGPY4Z5I3YBKETRNR4W\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-39/CC-MAIN-2019-39_segments_1568514574532.44_warc_CC-MAIN-20190921145904-20190921171904-00365.warc.gz\"}"}