-
Notifications
You must be signed in to change notification settings - Fork 1
/
readkaldiNNet.m
41 lines (34 loc) · 1.39 KB
/
readkaldiNNet.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
function [nnet]=readkaldiNNet(nnetBin)
% [nnet]=readkaldiNNet(nnetBin) transforms neural netwrok in kaldi format
% to matlab cell array containing the neural network parameters
% Input arguments:
% nnetBin --> path to the neural network stored in Kaldi format
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Written by Ahmed Hussen Abdelaziz and Shinji Watanabe
% Copyright(c) MERL 2014
% Permission is granted for anyone to copy, use, or modify
% this program for purposes of research or education. This program
% is distributed without any warranty express or implied.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Store an ASCII version of the neural network in the same folder of the
% binary one
nnetASCI=[fileparts(nnetBin) '/final.txt'];
% Convert the binary network to an ASCII version
system(['nnet-copy'...
' --binary=false'...
' ' nnetBin ...
' ' nnetASCI]);
fid=fopen(nnetASCI);
nnetChar=fscanf(fid,'%c');
fclose(fid);
starts=strfind( nnetChar , '[' );
ends=strfind( nnetChar , ']' );
% store the weights and the bias parameters of each layer in separate cell
nnet=cell([ 1 length(starts) ]);
for i=1:length(starts)
fid=fopen('tmpNNet.txt','w');
fwrite(fid,nnetChar(starts(i)+1:ends(i)-1));
fclose(fid);
nnet{i}=dlmread('tmpNNet.txt');
end