Set the parameters of LSTM based on predefined values
(lstm_pblobs, param_values)
| 1669 | |
| 1670 | |
| 1671 | def InitFromLSTMParams(lstm_pblobs, param_values): |
| 1672 | ''' |
| 1673 | Set the parameters of LSTM based on predefined values |
| 1674 | ''' |
| 1675 | weight_params = GetLSTMParamNames()['weights'] |
| 1676 | bias_params = GetLSTMParamNames()['biases'] |
| 1677 | for input_type in param_values.keys(): |
| 1678 | weight_values = [ |
| 1679 | param_values[input_type][w].flatten() |
| 1680 | for w in weight_params |
| 1681 | ] |
| 1682 | wmat = np.array([]) |
| 1683 | for w in weight_values: |
| 1684 | wmat = np.append(wmat, w) |
| 1685 | bias_values = [ |
| 1686 | param_values[input_type][b].flatten() |
| 1687 | for b in bias_params |
| 1688 | ] |
| 1689 | bm = np.array([]) |
| 1690 | for b in bias_values: |
| 1691 | bm = np.append(bm, b) |
| 1692 | |
| 1693 | weights_blob = lstm_pblobs[input_type]['weights'] |
| 1694 | bias_blob = lstm_pblobs[input_type]['biases'] |
| 1695 | cur_weight = workspace.FetchBlob(weights_blob) |
| 1696 | cur_biases = workspace.FetchBlob(bias_blob) |
| 1697 | |
| 1698 | workspace.FeedBlob( |
| 1699 | weights_blob, |
| 1700 | wmat.reshape(cur_weight.shape).astype(np.float32)) |
| 1701 | workspace.FeedBlob( |
| 1702 | bias_blob, |
| 1703 | bm.reshape(cur_biases.shape).astype(np.float32)) |
| 1704 | |
| 1705 | |
| 1706 | def cudnn_LSTM(model, input_blob, initial_states, dim_in, dim_out, |