Beispiel #1
0
        cfg.init_activation()
        model = None
        if cfg.model_type == 'DNN':
            model = DNN(numpy_rng=numpy_rng, theano_rng = theano_rng, cfg = cfg)
        elif cfg.model_type == 'CNN':
            model = CNN(numpy_rng=numpy_rng, theano_rng = theano_rng, cfg = cfg, testing = True)

        # load model parameters
        _file2nnet(model.layers, path = nnet_param)

        # initialize data reading
        cfg.init_data_reading_test(data_spec)

        model.dumpLayerSize()

        initialDim = model.getNeuronsForLayer(i)
        for p in perplexity:
            files.append(createDataFile(output_path,'Layer'+str(layer_index),countItems,2,initialDim,p))

        # get the function for feature extraction
        log('> ... getting the feat-extraction function')
        extract_func = model.build_extract_feat_function(layer_index)

        output_mats = []    # store the features for all the data in memory. TODO: output the features in a streaming mode
        log('> ... generating features from the specified layer')
        while (not cfg.test_sets.is_finish()):  # loop over the data
            cfg.test_sets.load_next_partition(cfg.test_xy)
            batch_num = int(math.ceil(1.0 * cfg.test_sets.cur_frame_num / batch_size))

            for batch_index in range(batch_num):  # loop over mini-batches
                    start_index = int(batch_index * batch_size)