I have tried converting a tensorflow mobilenetv2 model to tflite model from a very long time but I am facing a lot of issues in kaggle. I think by the time the model runs all its epochs i run out of time ans its hard to then save model and convert to tflite model. So for now ive downloaded the model to my local machine. Is there any way i can convert the file locally to tflite model in the command line?
Ive tried the following codes but to no avail
tflite_convert = --saved_model_dir=/Users/ns/Downloads/Mobilenet/Mobilenet_V2_LR.h5 --output_file=/Users/ns/Downloads/Mobilenetet/mobilenet.tflite
This is my model btw–
#import lines
# Load the CSV with pandas to get the image paths and targets
# Split the data into a training and validation set
# Convert the image paths and targets into TensorFlow Datasets
# Define the model architecture using MobileNetV2 as base
base_model = MobileNetV2(input_shape=(224, 224, 3), include_top=False, weights='imagenet')
base_model.trainable = True # Fine-tune all layers
x = base_model.output
x = GlobalAveragePooling2D()(x)
x = Dense(512, activation='relu')(x)
x = Dense(256, activation='relu')(x) # Adjusted dense layer
speed_output = Dense(1, name='speed')(x)
angle_norm_output = Dense(1, name='angle_norm')(x)
model = Model(inputs=base_model.input, outputs=[speed_output, angle_norm_output])
# Compile the model with RMSprop optimizer
# Define a learning rate scheduler callback
# Define callbacks
# Train the model with callbacks
history = model.fit(train_dataset, epochs=30, validation_data=val_dataset, callbacks=callbacks)
# Convert the trained model to TensorFlow Lite format
converter = tf.lite.TFLiteConverter.from_keras_model(model)
tflite_model = converter.convert()
# Save the TensorFlow Lite model to a file
with open('trained_mobilenetv2.tflite', 'wb') as f:
f.write(tflite_model)
print("Trained TensorFlow Lite model saved successfully.")