jpuigcerver / Laia

Laia: A deep learning toolkit for HTR based on Torch
MIT License
144 stars 57 forks source link

Transfer weights of lua model to pytorch model #37

Closed rafikg closed 5 years ago

rafikg commented 5 years ago

@jpuigcerver Thanks for your answer. Actually, I build your model using pytorch and I try to extract the weights form your lua pretrained model and transfer them to my pytorch model. I do the convolution parts correctly but I have a problem about the cudnn.BLSTM in lua and nn.lstm() in pytorch. It seems that in lua, all the parameters are flatten but not in nn.lstm() see my post https://stackoverflow.com/questions/55507905/cudnn-blstm-weight-and-biaises. How to reflatten the Lua weights and put them in the right order and place in pytroch model.

mauvilsa commented 5 years ago

@Gouiaa the parameters are ordered as follows (extracted from https://github.com/tensorflow/tensorflow/blob/r1.10/tensorflow/contrib/cudnn_rnn/python/ops/cudnn_rnn_ops.py#L381):

------------------------------------------------------------
| weights                    | biases                      |
------------------------------------------------------------
\                             \
  \                             \
  -------------------------------
  | layer1     |layer2     |... |
  -------------------------------
  \             \
    ---------------
    |fwd   |bak   |
    ---------------