@@ -25,10 +25,9 @@ import pandas as pd
25
25
dataset_df = pd.read_csv(" /tmp/penguins.csv" )
26
26
train_ds = tfdf.keras.pd_dataframe_to_tf_dataset(dataset_df, label = " species" )
27
27
28
- # Create, train and save the model
28
+ # Create and train the model
29
29
model_1 = tfdf.keras.GradientBoostedTreesModel()
30
30
model_1.fit(train_ds)
31
- model_1.save(" /tmp/my_saved_model" )
32
31
```
33
32
34
33
### Convert the model
@@ -43,16 +42,14 @@ to TensorFlow.js.
43
42
44
43
# Prepare and load the model with TensorFlow
45
44
import tensorflow as tf
46
- import tensorflow_decision_forests as tfdf
47
45
import tensorflowjs as tfjs
48
46
from google.colab import files
49
- import tf_keras
50
47
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" )
53
50
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" )
56
53
57
54
# Download the converted TFJS model
58
55
! zip - r tfjs_model.zip tfjs_model/
0 commit comments