lukelike1001 commited on
Commit
da999fb
1 Parent(s): a97ca88

TFSM converted to keras

Browse files
Files changed (2) hide show
  1. ConvertToKeras.py +22 -0
  2. leaf_model.keras +3 -0
ConvertToKeras.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import tensorflow as tf
2
+ import keras
3
+
4
+ # Originally TensorFlow 2.13.0 Keras 2.13.1
5
+ print(tf.__version__)
6
+ print(keras.__version__)
7
+
8
+ # Load the old model using the folder
9
+ inference_layer = keras.layers.TFSMLayer('saved_model/', call_endpoint='serving_default')
10
+
11
+ # Specify the model architecture using an inference layer
12
+ model = tf.keras.Sequential([
13
+ inference_layer,
14
+ ])
15
+
16
+ # compile the model using the same parameters when first training the model
17
+ model.compile(optimizer="adam",
18
+ loss=tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True),
19
+ metrics=["accuracy"])
20
+
21
+ # save the model as a .keras file (in line with Keras 3 specifications)
22
+ model.save("leaf_model.keras")
leaf_model.keras ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:58ff288ea82cfc752f5aad9b0b7a3011c74547d2d8a93a7c483eb258d4568674
3
+ size 16273237