There is a trained neural network (Object Detection Model) that is saved as a Checkpoint, that is, there are 4 files:
- labels.pbtxt
- ckpt-1.data-00000-of-00001
- ckpt-1.index
- pipeline.config
Is it possible to convert and save this neural network in Keras *.h5 format?
Maybe I’m wrong, but it seems it is possible to restore the specified model as follows:
PATH_TO_MODEL_DIR = “/content/saved_model”
PATH_TO_CFG = PATH_TO_MODEL_DIR + “/pipeline.config”
PATH_TO_CKPT = PATH_TO_MODEL_DIR + “/checkpoint”
where dir “checkpoint” include:
- labels.pbtxt
- ckpt-1.data-00000-of-00001
- ckpt-1.index
we pre-install the Object Detection API and then
#Load pipeline config and build a detection model:
configs = config_util.get_configs_from_pipeline_file(PATH_TO_CFG)
model_config = configs[‘model’]
detection_model = model_builder.build(model_config=model_config, is_training=False)
Restore checkpoint
ckpt = tf.compat.v2.train.Checkpoint(model=detection_model)
ckpt.restore(os.path.join(PATH_TO_CKPT, ‘ckpt-1’)).expect_partial()
tf.saved_model.save(ckpt, export_dir=‘/content/model’)
but I can’t save it later as model.save()==>
ckpt.save(‘myModel.h5’, save_format=‘h5’)
I get: “TypeError:Checkpoint.save() got an unexpected keyword argument ‘save_format’”, but I can save as:
tf.saved_model.save(ckpt, path_to_saved_dir)
is it possible to somehow convert the model into a single *.h5 file after that?
Simply put, how can I get a model from these four files so that I can save it as:
model = … # Get model ()
model.save(‘path/to/model’)