简体   繁体   中英

OSError: SavedModel file does not exist tflite

I am trying to convert my saved model to a tflite model, the saved model is saved on my desktop, however when I try and run this code: I gen an error -

OSError: SavedModel file does not exist at: C:/Users/Omar/Desktop/model00000014.h5/{saved_model.pbtxt|saved_model.pb}. 

Not sure what the problem is.


import tensorflow as tf

saved_model_dir = "r"C:/Users/Omar/Desktop/model00000014.h5""
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)
tflite_model = converter.convert()
open("converted_model.tflite", "wb").write(tflite_model)


If you're trying to convert a .h5 Keras model to a TFLite model, make sure you use TFLiteConverter.from_keras_model() method, as described in the docs ,

model = tf.keras.models.load( "C:/Users/Omar/Desktop/model00000014.h5" )
converter = tf.lite.TFLiteConverter.from_keras_model( model )
open( 'model.tflite' , 'wb' ).write( converter.convert() )

In case of a SavedModel , use TFLiteConverter.from_saved_model() and mention the file path of the directory of the SavedModel,

saved_model_dir = 'path/to/savedModelDir'
converter = tf.lite.TFLiteConverter.from_saved_model(saved_model_dir)

You're providing a Keras Model to the TFLiteConverter.from_saved_model() method, which might be causing an error.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM