Skip to content

Commit b0d7a7f

Browse files
committed
Update packaging-models.md (#285)
(cherry picked from commit ec7d74e)
1 parent fc321e4 commit b0d7a7f

File tree

1 file changed

+24
-10
lines changed

1 file changed

+24
-10
lines changed

docs/apis/packaging-models.md

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,36 @@
22

33
## TensorFlow
44

5-
Zip the exported estimator output in your checkpoint directory:
5+
Export your trained model and zip the model directory. An example is shown below (here is the [complete example](https://github.com/cortexlabs/cortex/blob/master/examples/iris/models/tensorflow_model.py)):
66

7-
```text
8-
$ ls export/estimator/1560263597/
9-
saved_model.pb variables/
7+
```Python
8+
import tensorflow as tf
9+
import shutil
10+
import os
11+
12+
...
13+
14+
classifier = tf.estimator.Estimator(
15+
model_fn=my_model, model_dir="iris", params={"hidden_units": [10, 10], "n_classes": 3}
16+
)
17+
18+
exporter = tf.estimator.FinalExporter("estimator", serving_input_fn, as_text=False)
19+
train_spec = tf.estimator.TrainSpec(train_input_fn, max_steps=1000)
20+
eval_spec = tf.estimator.EvalSpec(eval_input_fn, exporters=[exporter], name="estimator-eval")
21+
22+
tf.estimator.train_and_evaluate(classifier, train_spec, eval_spec)
1023

11-
$ zip -r model.zip export/estimator
24+
# zip the estimator export dir (the exported path looks like iris/export/estimator/1562353043/)
25+
shutil.make_archive("tensorflow", "zip", os.path.join("iris/export/estimator"))
1226
```
1327

14-
Upload the zipped file to Amazon S3:
28+
Upload the zipped file to Amazon S3 using the AWS web console or CLI:
1529

1630
```text
1731
$ aws s3 cp model.zip s3://my-bucket/model.zip
1832
```
1933

20-
Reference your `model` in an API:
34+
Reference your model in an `api`:
2135

2236
```yaml
2337
- kind: api
@@ -45,20 +59,20 @@ with open("sklearn.onnx", "wb") as f:
4559
f.write(onnx_model.SerializeToString())
4660
```
4761
48-
Here are examples of converting models from some of the common ML frameworks to ONNX:
62+
Here are complete examples of converting models from some of the common ML frameworks to ONNX:
4963
5064
* [PyTorch](https://github.com/cortexlabs/cortex/blob/master/examples/iris/models/pytorch_model.py)
5165
* [Sklearn](https://github.com/cortexlabs/cortex/blob/master/examples/iris/models/sklearn_model.py)
5266
* [XGBoost](https://github.com/cortexlabs/cortex/blob/master/examples/iris/models/xgboost_model.py)
5367
* [Keras](https://github.com/cortexlabs/cortex/blob/master/examples/iris/models/keras_model.py)
5468
55-
Upload your trained model in ONNX format to Amazon S3:
69+
Upload your trained model in ONNX format to Amazon S3 using the AWS web console or CLI:
5670
5771
```text
5872
$ aws s3 cp model.onnx s3://my-bucket/model.onnx
5973
```
6074

61-
Reference your `model` in an API:
75+
Reference your model in an `api`:
6276

6377
```yaml
6478
- kind: api

0 commit comments

Comments
 (0)