Skip to content

Commit 76eb58a

Browse files
Merge pull request #207 from hchiam:tf_df_in_tf_js.md-fix-205
PiperOrigin-RevId: 602981273
2 parents 06007e6 + 48102a4 commit 76eb58a

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

documentation/tf_df_in_tf_js.md

+5-8
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ import pandas as pd
2525
dataset_df = pd.read_csv("/tmp/penguins.csv")
2626
train_ds = tfdf.keras.pd_dataframe_to_tf_dataset(dataset_df, label="species")
2727

28-
# Create, train and save the model
28+
# Create and train the model
2929
model_1 = tfdf.keras.GradientBoostedTreesModel()
3030
model_1.fit(train_ds)
31-
model_1.save("/tmp/my_saved_model")
3231
```
3332

3433
### Convert the model
@@ -43,16 +42,14 @@ to TensorFlow.js.
4342

4443
# Prepare and load the model with TensorFlow
4544
import tensorflow as tf
46-
import tensorflow_decision_forests as tfdf
4745
import tensorflowjs as tfjs
4846
from google.colab import files
49-
import tf_keras
5047

51-
# Load the model with Keras
52-
model = tf_keras.models.load_model("/tmp/my_saved_model/")
48+
# Save the model in the SavedModel format
49+
tf.saved_model.save(model_1, "/tmp/my_saved_model")
5350

54-
# Convert the keras model to TensorFlow.js
55-
tfjs.converters.tf_saved_model_conversion_v2.convert_keras_model_to_graph_model(model, "./tfjs_model")
51+
# Convert the SavedModel to TensorFlow.js and save as a zip file
52+
tfjs.converters.tf_saved_model_conversion_v2.convert_tf_saved_model("/tmp/my_saved_model", "./tfjs_model")
5653

5754
# Download the converted TFJS model
5855
!zip -r tfjs_model.zip tfjs_model/

0 commit comments

Comments
 (0)