使用TensorFlow检查点在C 中还原模型
Using Tensorflow checkpoint to restore model in C++
我已经训练了我使用python使用TensorFlow实现的网络。最后,我用tf.train.saver((保存了模型。现在,我想使用C 使用此预训练的网络进行预测。
我该怎么做?有没有办法转换检查点,因此我可以将其与Tiny-DNN或Tensorflow C ?
一起使用欢迎任何想法:)谢谢!
您可能应该以SavedModel格式导出该模型,该格式封装了计算图和保存变量(tf.train.Saver
仅保存变量,因此无论如何您都必须保存图形(。
然后,您可以使用LoadSavedModel
加载保存的模型。
确切的调用将取决于模型的输入和输出。但是Python代码看起来像这样:
# You'd adjust the arguments here according to your model
signature = tf.saved_model.signature_def_utils.predict_signature_def(
inputs={'image': input_tensor}, outputs={'scores': output_tensor})
builder = tf.saved_model.builder.SavedModelBuilder('/tmp/my_saved_model')
builder.add_meta_graph_and_variables(
sess=sess,
tags=[tf.saved_model.tag_constants.SERVING],
signature_def_map={
tf.saved_model.signature_constants.DEFAULT_SERVING_SIGNATURE_DEF_KEY:
signature
})
builder.save()
然后在C 中您会做这样的事情:
tensorflow::SavedModelBundle model;
auto status = tensorflow::LoadSavedModel(session_options, run_options, "/tmp/my_saved_model", {tensorflow::kSavedModelTagServe}, &model);
if (!status.ok()) {
std::cerr << "Failed: " << status;
return;
}
// At this point you can use model.session
(请注意,使用SavedModel格式也将允许您使用TensorFlow服务使用模型,如果对您的应用程序有意义(
希望会有所帮助。
相关文章:
- QTableView:endMoveRows在模型中重置水平页眉大小
- 将IBM Rhapsody模型集成到VS 2019中
- 旋转模型矩阵时的形状失真
- 成员函数调用和C++对象模型
- 连接 dockerized 模型和 dockerized 数据库时出现"无法 SQLConnect"错误
- 打印 ONNXRUNTIME::图形没有模型
- C++内存模型和位字段的最大序列
- 使用SIR模型的疾病爆发模拟
- Qt - QVector 和模型视图 - 从列表视图获取自定义类的最佳方法是什么?
- 如何在 ECS 模型中组织实体?
- 在官方张量流 resnet50 模型上运行 tflite 精度工具
- Libtorch:如何加载ONNX模型?
- 使用 assimp 加载模型 - 不需要提升?
- 如何将经过训练的机器学习模型保存在python中并将其加载到C++中进行预测?
- 为什么 g++ 使用 movabs 和一个奇怪的常数来简单还原?
- C++内存模型中的确切规则阻止在获取操作之前重新排序
- 如何更改古罗比C++模型中的目标值系数
- 如何在 openGL 中围绕全局轴旋转模型?
- 我们可以将阈值应用于色彩空间模型的单个组件(如 RGB 和 LAB)吗?
- 使用TensorFlow检查点在C 中还原模型