forked from apache/mxnet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[MERGE into v1.0.0 ONLY] Fix license for 1.0.0 (apache#8876)
* Remove ASF Licenses from some files * typo * typo 2 * whitelisting files for header check (cherry picked from commit 74be98b)
- Loading branch information
Showing
9 changed files
with
232 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 0 additions & 19 deletions
19
example/image-classification/predict-cpp/image-classification-predict.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2012-2013 Karel Vesely, Daniel Povey | ||
# 2015 Yu Zhang | ||
# Apache 2.0 | ||
|
||
# Begin configuration section. | ||
nnet= # Optionally pre-select network to use for getting state-likelihoods | ||
feature_transform= # Optionally pre-select feature transform (in front of nnet) | ||
model= # Optionally pre-select transition model | ||
class_frame_counts= # Optionally pre-select class-counts used to compute PDF priors | ||
|
||
stage=0 # stage=1 skips lattice generation | ||
nj=4 | ||
cmd=run.pl | ||
max_active=7000 # maximum of active tokens | ||
min_active=200 #minimum of active tokens | ||
max_mem=50000000 # limit the fst-size to 50MB (larger fsts are minimized) | ||
beam=13.0 # GMM:13.0 | ||
latbeam=8.0 # GMM:6.0 | ||
acwt=0.10 # GMM:0.0833, note: only really affects pruning (scoring is on lattices). | ||
scoring_opts="--min-lmwt 1 --max-lmwt 10" | ||
skip_scoring=false | ||
use_gpu_id=-1 # disable gpu | ||
#parallel_opts="-pe smp 2" # use 2 CPUs (1 DNN-forward, 1 decoder) | ||
parallel_opts= # use 2 CPUs (1 DNN-forward, 1 decoder) | ||
# End configuration section. | ||
|
||
echo "$0 $@" # Print the command line for logging | ||
|
||
[ -f ./path.sh ] && . ./path.sh; # source the path. | ||
. parse_options.sh || exit 1; | ||
|
||
graphdir=$1 | ||
data=$2 | ||
dir=$3 | ||
srcdir=`dirname $dir`; # The model directory is one level up from decoding directory. | ||
sdata=$data/split$nj; | ||
|
||
mxstring=$4 | ||
|
||
mkdir -p $dir/log | ||
[[ -d $sdata && $data/feats.scp -ot $sdata ]] || split_data.sh $data $nj || exit 1; | ||
echo $nj > $dir/num_jobs | ||
|
||
if [ -z "$model" ]; then # if --model <mdl> was not specified on the command line... | ||
if [ -z $iter ]; then model=$srcdir/final.mdl; | ||
else model=$srcdir/$iter.mdl; fi | ||
fi | ||
|
||
for f in $model $graphdir/HCLG.fst; do | ||
[ ! -f $f ] && echo "decode_mxnet.sh: no such file $f" && exit 1; | ||
done | ||
|
||
|
||
# check that files exist | ||
for f in $sdata/1/feats.scp $model $graphdir/HCLG.fst; do | ||
[ ! -f $f ] && echo "$0: no such file $f" && exit 1; | ||
done | ||
|
||
# PREPARE THE LOG-POSTERIOR COMPUTATION PIPELINE | ||
if [ -z "$class_frame_counts" ]; then | ||
class_frame_counts=$srcdir/ali_train_pdf.counts | ||
else | ||
echo "Overriding class_frame_counts by $class_frame_counts" | ||
fi | ||
|
||
# Create the feature stream: | ||
feats="scp:$sdata/JOB/feats.scp" | ||
inputfeats="$sdata/JOB/mxnetInput.scp" | ||
|
||
|
||
if [ -f $sdata/1/feats.scp ]; then | ||
$cmd JOB=1:$nj $dir/log/make_input.JOB.log \ | ||
echo NO_FEATURE_TRANSFORM scp:$sdata/JOB/feats.scp \> $inputfeats | ||
fi | ||
|
||
# Run the decoding in the queue | ||
if [ $stage -le 0 ]; then | ||
$cmd $parallel_opts JOB=1:$nj $dir/log/decode.JOB.log \ | ||
$mxstring --data_test $inputfeats \| \ | ||
latgen-faster-mapped --min-active=$min_active --max-active=$max_active --max-mem=$max_mem --beam=$beam --lattice-beam=$latbeam \ | ||
--acoustic-scale=$acwt --allow-partial=true --word-symbol-table=$graphdir/words.txt \ | ||
$model $graphdir/HCLG.fst ark:- "ark:|gzip -c > $dir/lat.JOB.gz" || exit 1; | ||
fi | ||
|
||
# Run the scoring | ||
if ! $skip_scoring ; then | ||
[ ! -x local/score.sh ] && \ | ||
echo "Not scoring because local/score.sh does not exist or not executable." && exit 1; | ||
local/score.sh $scoring_opts --cmd "$cmd" $data $graphdir $dir || exit 1; | ||
fi | ||
|
||
exit 0; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
|
||
# Copyright 2013 Yajie Miao Carnegie Mellon University | ||
|
||
|
||
import numpy as np | ||
import os | ||
import sys | ||
|
||
from StringIO import StringIO | ||
import json | ||
import utils.utils as utils | ||
from model_io import string_2_array | ||
|
||
# Various functions to convert models into Kaldi formats | ||
def _nnet2kaldi(nnet_spec, set_layer_num = -1, filein='nnet.in', | ||
fileout='nnet.out', activation='sigmoid', withfinal=True): | ||
_nnet2kaldi_main(nnet_spec, set_layer_num=set_layer_num, filein=filein, | ||
fileout=fileout, activation=activation, withfinal=withfinal, maxout=False) | ||
|
||
def _nnet2kaldi_maxout(nnet_spec, pool_size = 1, set_layer_num = -1, | ||
filein='nnet.in', fileout='nnet.out', activation='sigmoid', withfinal=True): | ||
_nnet2kaldi_main(nnet_spec, set_layer_num=set_layer_num, filein=filein, | ||
fileout=fileout, activation=activation, withfinal=withfinal, | ||
pool_size = 1, maxout=True) | ||
|
||
def _nnet2kaldi_main(nnet_spec, set_layer_num = -1, filein='nnet.in', | ||
fileout='nnet.out', activation='sigmoid', withfinal=True, maxout=False): | ||
elements = nnet_spec.split(':') | ||
layers = [] | ||
for x in elements: | ||
layers.append(int(x)) | ||
if set_layer_num == -1: | ||
layer_num = len(layers) - 1 | ||
else: | ||
layer_num = set_layer_num + 1 | ||
nnet_dict = {} | ||
nnet_dict = utils.pickle_load(filein) | ||
|
||
fout = open(fileout, 'wb') | ||
for i in xrange(layer_num - 1): | ||
input_size = int(layers[i]) | ||
if maxout: | ||
output_size = int(layers[i + 1]) * pool_size | ||
else: | ||
output_size = int(layers[i + 1]) | ||
W_layer = [] | ||
b_layer = '' | ||
for rowX in xrange(output_size): | ||
W_layer.append('') | ||
|
||
dict_key = str(i) + ' ' + activation + ' W' | ||
matrix = string_2_array(nnet_dict[dict_key]) | ||
|
||
for x in xrange(input_size): | ||
for t in xrange(output_size): | ||
W_layer[t] = W_layer[t] + str(matrix[x][t]) + ' ' | ||
|
||
dict_key = str(i) + ' ' + activation + ' b' | ||
vector = string_2_array(nnet_dict[dict_key]) | ||
for x in xrange(output_size): | ||
b_layer = b_layer + str(vector[x]) + ' ' | ||
|
||
fout.write('<affinetransform> ' + str(output_size) + ' ' + str(input_size) + '\n') | ||
fout.write('[' + '\n') | ||
for x in xrange(output_size): | ||
fout.write(W_layer[x].strip() + '\n') | ||
fout.write(']' + '\n') | ||
fout.write('[ ' + b_layer.strip() + ' ]' + '\n') | ||
if maxout: | ||
fout.write('<maxout> ' + str(int(layers[i + 1])) + ' ' + str(output_size) + '\n') | ||
else: | ||
fout.write('<sigmoid> ' + str(output_size) + ' ' + str(output_size) + '\n') | ||
|
||
if withfinal: | ||
input_size = int(layers[-2]) | ||
output_size = int(layers[-1]) | ||
W_layer = [] | ||
b_layer = '' | ||
for rowX in xrange(output_size): | ||
W_layer.append('') | ||
|
||
dict_key = 'logreg W' | ||
matrix = string_2_array(nnet_dict[dict_key]) | ||
for x in xrange(input_size): | ||
for t in xrange(output_size): | ||
W_layer[t] = W_layer[t] + str(matrix[x][t]) + ' ' | ||
|
||
|
||
dict_key = 'logreg b' | ||
vector = string_2_array(nnet_dict[dict_key]) | ||
for x in xrange(output_size): | ||
b_layer = b_layer + str(vector[x]) + ' ' | ||
|
||
fout.write('<affinetransform> ' + str(output_size) + ' ' + str(input_size) + '\n') | ||
fout.write('[' + '\n') | ||
for x in xrange(output_size): | ||
fout.write(W_layer[x].strip() + '\n') | ||
fout.write(']' + '\n') | ||
fout.write('[ ' + b_layer.strip() + ' ]' + '\n') | ||
fout.write('<softmax> ' + str(output_size) + ' ' + str(output_size) + '\n') | ||
|
||
fout.close(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters