I am running notebook on sagemaker instance with ml.g4dn.xlarge instance.
I am trying to create tflite model as given below
Save the model
model.save(os.path.join(model_dir, 'model.h5'))
# Convert and save the model as TensorFlow Lite
converter = tf.lite.TFLiteConverter.from_keras_model(model)
converter.experimental_new_converter = True # Enable MLIR-based conversion flow
converter.debug_info = True # Enable the generation of a debug .mlir file
tflite_model = converter.convert()
with open(os.path.join(model_dir, 'model.tflite'), 'wb') as f:
f.write(tflite_model)
I am getting an error
Kernel Restarting
The kernel for Untitled2.ipynb appears to have died. It will restart automatically.
I check few so link where it is asking to upgrade the instance type. I upgraded it to ml.g4dn.xlarge but still its giving same error. Any suggestion what can be the cause?
Based on the information provided, it looks like the instance is running out of memory during the conversion process.
You can monitor the current memory consumption via the JupyterLab UI (see example here) or by running
free -min a terminal.Apart from using an instance with more memory attached (e.g. ml.g4dn.2xlarge), you can also try to run the conversion without debug information enabled, or you can look into post-training quantization to reduce the model size.