karpathy / convnetjs

Deep Learning in Javascript. Train Convolutional Neural Networks (or ordinary ones) in your browser.
MIT License
10.8k stars 2.04k forks source link

conv layer json file weight ordering (filt, d, sx, sy) #84

Open malcolmregan opened 7 years ago

malcolmregan commented 7 years ago

I need to produce a JSON file convnetjs can read from a saved theano model. The model ive produced so far "works" (as in it is valid) but doesn't make the expected predictions.

This is likely due to the fact that the ordering of the weights in the JSON file is wrong as I can't find any info on how they are stored.

As a specific example of my question, The layer I'm trying to convert from theano to json consists of 50 filters each with depth=20, sx=5, sy=5 Accordingly, The theano weight matrix has shape (filt=50, d=20, sx=5, sy=5). In what order should I loop over the dimensions of the theano matrix? That is, in what order should the weight values be stored in the JSON file? right now I have:


num=0
for filt from 1 to 50:
     for sx from 1 to 5:
          for sy from 1 to 5: 
               for d from 1 to 20:        
                    add the line to json file: "num":   weights[filt, d, sx, sy]
                    num=num+1