Tensorflow 对象检测微调模型的正确保存和加载方法

我在使用这个来自colabs教程的示例来微调模型,训练完成后,我想保存模型并在本地计算机上使用以下代码加载:

ckpt_manager = tf.train.CheckpointManager(ckpt, directory="test_data/checkpoint/", max_to_keep=5)......print('Done fine-tuning!')ckpt_manager.save()print('Checkpoint saved!')

但是在本地计算机上使用检查点文件恢复后,模型无法检测到任何对象(得分太低)

我还尝试了以下方法:

tf.saved_model.save(detection_model, '/content/new_model/')

并使用以下代码加载:

detection_model = tf.saved_model.load('/saved_model_20201226/')input_tensor = tf.convert_to_tensor(image, dtype=tf.float32)detections = detection_model(input_tensor)

结果出现了这个错误:TypeError: ‘_UserObject’ object is not callable

微调模型的正确保存和加载方法是什么?

编辑 1:我忘记保存新的管道配置,之后终于工作了!这是我的答案:

# Save new pipeline confignew_pipeline_proto = config_util.create_pipeline_proto_from_configs(configs)config_util.save_pipeline_config(new_pipeline_proto, '/content/new_config')exported_ckpt = tf.compat.v2.train.Checkpoint(model=detection_model)ckpt_manager = tf.train.CheckpointManager(exported_ckpt, directory="test_data/checkpoint/", max_to_keep=5)......print('Done fine-tuning!')ckpt_manager.save()print('Checkpoint saved!')

回答:

我忘记保存新的管道配置,之后终于工作了!这是我的答案:

# Save new pipeline confignew_pipeline_proto = config_util.create_pipeline_proto_from_configs(configs)config_util.save_pipeline_config(new_pipeline_proto, '/content/new_config')exported_ckpt = tf.compat.v2.train.Checkpoint(model=detection_model)ckpt_manager = tf.train.CheckpointManager(exported_ckpt, directory="test_data/checkpoint/", max_to_keep=5)......print('Done fine-tuning!')ckpt_manager.save()print('Checkpoint saved!')

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注