0
votes

I want to train a convolutional neural network in one language, but use it in another one (for various technical/performance related reasons). Is there a programmatic way of doing this by saving weights?

For example, I can train a multilayer perceptron in Python, then save all the weights in a CSV file, then make a new MLP in Java and use the file to set the weights. However, I'm unsure of how I can do something similar with a convolutional neural network because I don't know how to treat the convolutional layer. I think my main problem is understanding how to export/save the convolution part of the network and then load them elsewhere.

2
If you save the weight matrices, I recommend HDF5 (e.g. for python)Martin Thoma
There is no single data format. However, Caffe's prototxt format is pretty good. I wanted to write a standard for this for quite a while, but it is a difficult task which I would do completely in my free-time. And I'm not sure if the main frameworks would be willing to add import / export scripts. And it would only work for very standard architectures.Martin Thoma

2 Answers

1
votes

In short - there is no general way and it rather won't be, as it is highly specialized type of data, with no one, common idea of how they should look like.

In other words you have to export it yourself to .txt, .csv, database, or any other storage system of your choice. CNNs do not differ that much from MLP, they also have layers and weights, the only difference is that their structure is a bit more complex - and this structure is additional few numbers that you need to save, for example for spatial convolution you need to know the size of the layer, size of kernels and their movement/padding thus you can reconstruct the entire object in the new language.

0
votes

If I am getting you right, you want to train a CNN with one language and then save it's weights and after that you want to use these weights with other language.
If that is the case then answer will totally depend on the languages you want to use. I have seen people training CNN with C++/Python with the use of caffe and save weights as .caffemodel. You can then use this ".caffemodel" with lua language with the use of loadcaffe interface. So higher level answer is; Yes, you can find a way to share between python/C++ and lua. You can also share weights between lua and matlab with the use of mattorch/matio.