uncomplicate / deep-diamond

A fast Clojure Tensor & Deep Learning library
https://aiprobook.com
Eclipse Public License 1.0
428 stars 17 forks source link

read/write trained network, access layer weights? #13

Closed xlfe closed 1 year ago

xlfe commented 2 years ago

@blueberry thank you for all your work on this libary, and the other uncomplicate projects!

I'm wondering if it is missing, or if I have missed how, but once I have a trained network, there doesn't seem to be a way to save the trained network and to load it back later?

Also, for a word2vec style use case, one needs access to the trained weights (rather than the trained network). But save poking around the "uncomplicate.diamond.internal" ns, you don't seem to expose access to those either?

Appreciate your thoughts!

blueberry commented 2 years ago

Both cases are covered (and I'm interested in feedback and ideas how to make it even better).

  1. Simply transfer! your network to a (any Java) FileChannel object. Please look at ...internal.dnnl.file-channel. just map-channel and then (transfer! my-network that-channel) and (transfer! that-channel my-network). This works with raw bytes, so it assumes that you'll only transfer data that fits your network's structure.
  2. There's Parameters and ParameterSeq protocols in ...internal.protocols, with methods weights, bias, and parameters. It's not public, because why would anyone want to look at millions of floating point numbers, other than debugging (and even then, it's difficult for a human to do). Mind you, the saving/loading works on the network as a whole.
xlfe commented 2 years ago

thanks @blueberry - I will have a go and provide some feedback