def load_data(dataset): ''' Loads the dataset :type dataset: string :param dataset: the path to the dataset (here mfcc_sid.pkl) ''' ############# # LOAD DATA # ############# print "load dataset into three part set : train, valid, test " train_set, valid_set, test_set = load_dataset(dataset) #train_set, valid_set, test_set format: tuple(input, target) #input is an numpy.ndarray of 2 dimensions (a matrix) #witch row's correspond to an example. target is a #numpy.ndarray of 1 dimensions (vector)) that have the same length as #the number of rows in the input. It should give the target #target to the example with the same index in the input. def shared_dataset(data_xy, borrow=True): """ Function that loads the dataset into shared variables The reason we store our dataset in shared variables is to allow Theano to copy it into the GPU memory (when code is run on GPU). Since copying data into the GPU is slow, copying a minibatch everytime is needed (the default behaviour if the data is not in a shared variable) would lead to a large decrease in performance. """ data_x, data_y = data_xy shared_x = theano.shared(numpy.asarray(data_x, dtype=theano.config.floatX), borrow=borrow) shared_y = theano.shared(numpy.asarray(data_y, dtype=theano.config.floatX), borrow=borrow) # When storing data on the GPU it has to be stored as floats # therefore we will store the labels as ``floatX`` as well # (``shared_y`` does exactly that). But during our computations # we need them as ints (we use labels as index, and if they are # floats it doesn't make sense) therefore instead of returning # ``shared_y`` we will have to cast it to int. This little hack # lets ous get around this issue return shared_x, T.cast(shared_y, 'int32') test_set_x, test_set_y = shared_dataset(test_set) valid_set_x, valid_set_y = shared_dataset(valid_set) train_set_x, train_set_y = shared_dataset(train_set) rval = [(train_set_x, train_set_y), (valid_set_x, valid_set_y), (test_set_x, test_set_y)] return rval
""" Root Mean Squared Error Accepts a list of predictions and a list of targets """ def rmse(preds, targets): dif = [((p - targets[i])**2) for i, p in enumerate(preds)] mean = float(sum(dif)) / len(targets) root = math.sqrt(mean) return root # time_start timestart = time.time() # trainset, validset, testset = music_preprocess.load_dataset("sid.pkl") trainset, validset, testset = load_dataset("mfcc_sid.pkl") # train train_data = trainset[0] train_target = trainset[1] valid_data = validset[0] valid_target = validset[1] # set the layers parm,and the max is 8 now layers = [10, 20, 10, 20] # first 10 is the 95mfcc's first 10 dim # run the dnn ,first autoencoder and then DNNRegressor autoencoder = dnn.AutoEncoder(valid_data, train_data, valid_target, layers, hidden_layer="SigmoidLayer", final_layer="SoftmaxLayer", compression_epochs=1,
""" Root Mean Squared Error Accepts a list of predictions and a list of targets """ def rmse(preds, targets): dif = [((p - targets[i]) ** 2) for i, p in enumerate(preds)] mean = float(sum(dif)) / len(targets) root = math.sqrt(mean) return root # time_start timestart = time.time() # trainset, validset, testset = music_preprocess.load_dataset("sid.pkl") trainset, validset, testset = load_dataset("mfcc_sid.pkl") # train train_data = trainset[0] train_target = trainset[1] valid_data = validset[0] valid_target = validset[1] # set the layers parm,and the max is 8 now layers = [10, 20, 10, 20] # first 10 is the 95mfcc's first 10 dim # run the dnn ,first autoencoder and then DNNRegressor autoencoder = dnn.AutoEncoder(valid_data, train_data, valid_target, layers, hidden_layer="SigmoidLayer", final_layer="SoftmaxLayer", compression_epochs=1, bias=True, autoencoding_only=False, dropout_on=True) print("1here is okay") # ============================================================ autoencoder.fit() # time end timeend = time.time()