hollance / Forge

A neural network toolkit for Metal
MIT License
1.27k stars 172 forks source link

Supported weights file for Forge #2

Closed ankghost0912 closed 6 years ago

ankghost0912 commented 7 years ago

Hi,

I wanted to know if .bin or .dat are the only file types supported, for interacting with the Forge framework. Can Forge work with files like .caffemodel or .pb or with files which do not specify weights and biases for every layer?

If .bin or .dat are the only supported file types, are you aware of any conversion tools to convert from other binary weight file types?

Thanks

hollance commented 7 years ago

In theory Forge can support any file type because you can write your own implementation of ParameterData, which is used to load the weights.

Using the built-in ParameterLoaderBundle object, the weights are expected to be binary files with raw 32-bit floats inside them. Metal also expects the weights to be in a specific order.

Using a caffemodel file would require loading the weights, transposing them in memory, and then giving them to Metal. It's possible but not as efficient as converting the weights once beforehand storing them in a .bin file.

(By the way, .bin and .dat are the same file format: just binary float values.)

I have a few conversion scripts from caffemodel, h5, TensorFlow graph defs etc, but these need to be tweaked for each model. (You can see and example in the MNIST/Training folder.) It would be useful to have robust conversion scripts that will work for any possible model, but that's something for the future.

craigomac commented 7 years ago

Could you share the script for splitting the Inception weights file? It would be particularly useful for those of us who've used a retrained Inception model.

hollance commented 7 years ago

I actually used the weights from the Apple Inception demo project. However, there is this script that you can use to convert Inception to Metal (assuming your model is in TensorFlow format, which it looks like it is).

etown commented 7 years ago

that script needs to be tweaked for the retrained inception model. has anybody got that the work?