简体   繁体   中英

Deep learning: save and load a universal machine model through different libraries

My questions can be divided into two parts.

  • Is there a format of machine learning model file that can be used through different libraries? For example, I saved a model by pytorch, then load it using tensorflow?

  • If not, is there a library that can help transfer the formats so that a pytorch machine learning model can be used directly in keras?

The reason why I ask this question is that recently I need to adjust some of my previous trained models in tensorflow to pytorch.

An update for this question: Facebook and Microsoft are going to launch a model standard called ONNX, which is used for transferring models between different framworks, for example between Pytorch to Caffe2. Link in the following:

https://research.fb.com/facebook-and-microsoft-introduce-new-open-ecosystem-for-interchangeable-ai-frameworks/

An further update for this question: Tensorflow itself use Protocol Buffer format to store model file, which can be used for transfer between different models. Link in the following:

https://www.tensorflow.org/extend/tool_developers/

Very interesting question. A neural network is a mathematical abstraction consisting of a network of layers (convolution, recurrent, ...), operations (dot product, non-linearity, ...) and their respective parameters (weights, biases).

  1. AFAIK, there's not an universal model file. Nonetheless, different libraries allow users to save their models in a binary format.

  2. There's no library for conversion but there's effort on github repo that addresses this question.

Predictive Markup Modeling Language (PMML) is an XML-based representation language for many machine learning models. It's an open standard that's used by many companies for serializing and deserializing models. I've used libraries that support PMML for machine learning models like SVM and decision trees but have not used it for deep learning models. However, there are open source projects that will work with Tensorflow and Keras , but these libraries seem to be for serializing and deserializing for use with the same library. You might want to check if PMML is making progress for serializing and deserializing between libraries.

If not, is there a library that can help transfer the formats so that a pytorch machine learning model can be used directly in keras?

You can try a Pytorch2Keras converter.

In that moment, it supports base layers like Conv2d, Linear, Activations, Element-wise operations. So, I converted ResNet50 with error 1e-6.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM