<s> import cPickle <EOL> import gzip <EOL> import os <EOL> import sys <EOL> import time <EOL> import numpy <EOL> import json <EOL> import theano <EOL> import theano . tensor as T <EOL> from theano . tensor . shared_randomstreams import RandomStreams <EOL> from io_func import smart_open <EOL> from io_func . model_io import _file2nnet , log <EOL> from io_func . kaldi_feat import KaldiReadIn , KaldiWriteOut <EOL> from models . cnn import CNN_Forward <EOL> from utils . utils import parse_arguments , string2bool <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> arg_elements = [ sys . argv [ i ] for i in range ( <NUM_LIT:1> , len ( sys . argv ) ) ] <EOL> arguments = parse_arguments ( arg_elements ) <EOL> required_arguments = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> for arg in required_arguments : <EOL> if arguments . has_key ( arg ) == False : <EOL> print "<STR_LIT>" % ( arg ) ; exit ( <NUM_LIT:1> ) <EOL> in_scp_file = arguments [ '<STR_LIT>' ] <EOL> out_ark_file = arguments [ '<STR_LIT>' ] <EOL> cnn_param_file = arguments [ '<STR_LIT>' ] <EOL> cnn_cfg_file = arguments [ '<STR_LIT>' ] <EOL> cfg = cPickle . load ( smart_open ( cnn_cfg_file , '<STR_LIT:r>' ) ) <EOL> conv_configs = cfg . conv_layer_configs <EOL> conv_layer_number = len ( conv_configs ) <EOL> for i in xrange ( conv_layer_number ) : <EOL> conv_configs [ i ] [ '<STR_LIT>' ] = cfg . conv_activation <EOL> use_fast = cfg . use_fast <EOL> if arguments . has_key ( '<STR_LIT>' ) : <EOL> use_fast = string2bool ( arguments [ '<STR_LIT>' ] ) <EOL> kaldiread = KaldiReadIn ( in_scp_file ) <EOL> kaldiwrite = KaldiWriteOut ( out_ark_file ) <EOL> log ( '<STR_LIT>' ) <EOL> input_shape_train = conv_configs [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> input_shape_1 = ( input_shape_train [ <NUM_LIT:1> ] , input_shape_train [ <NUM_LIT:2> ] , input_shape_train [ <NUM_LIT:3> ] ) <EOL> rng = numpy . random . RandomState ( <NUM_LIT> ) <EOL> theano_rng = RandomStreams ( rng . randint ( <NUM_LIT:2> ** <NUM_LIT:30> ) ) <EOL> cnn = CNN_Forward ( numpy_rng = rng , theano_rng = theano_rng , conv_layer_configs = conv_configs , use_fast = use_fast ) <EOL> _file2nnet ( cnn . conv_layers , set_layer_num = len ( conv_configs ) , filename = cnn_param_file ) <EOL> out_function = cnn . build_out_function ( ) <EOL> log ( '<STR_LIT>' ) <EOL> while True : <EOL> uttid , in_matrix = kaldiread . read_next_utt ( ) <EOL> if uttid == '<STR_LIT>' : <EOL> break <EOL> in_matrix = numpy . reshape ( in_matrix , ( in_matrix . shape [ <NUM_LIT:0> ] , ) + input_shape_1 ) <EOL> out_matrix = out_function ( in_matrix ) <EOL> kaldiwrite . write_kaldi_mat ( uttid , out_matrix ) <EOL> kaldiwrite . close ( ) <EOL> log ( '<STR_LIT>' % ( out_ark_file ) ) </s>
