Ejemplo n.º 1
0
def main(opts):
    RECEIVED_PARAMS = nni.get_next_parameter()
    LOG.debug(RECEIVED_PARAMS)
    if 'onlyIncoming' == opts.mode:
        PARAMS = cnn.generate_default_onlyIncoming_params(opts.dataType)
    elif 'both' == opts.mode:
        PARAMS = cnn.generate_default_whole_params(opts.dataType)
    PARAMS.update(RECEIVED_PARAMS)
    try:
        X_train_raw, y_train, X_test_raw, y_test, labelMap = prepareData.loadTrainAndTestData(
            opts.input, PARAMS['data_dim'], opts.dataType, mode=opts.mode)
        NUM_CLASS = len(set(y_test))
        X_train = X_train_raw.reshape(X_train_raw.shape[0],
                                      X_train_raw.shape[1], 1)
        X_test = X_test_raw.reshape(X_test_raw.shape[0], X_test_raw.shape[1],
                                    1)
        y_train = np_utils.to_categorical(y_train, NUM_CLASS)
        y_test = np_utils.to_categorical(y_test, NUM_CLASS)

        cnn_model = CNN(opts, PARAMS)
        modelPath = cnn_model.train(PARAMS, X_train, y_train, NUM_CLASS)
        cnn_model.test(X_test, y_test, NUM_CLASS, modelPath)
    except Exception as e:
        LOG.exception(e)
        raise
Ejemplo n.º 2
0
def chooseModel(opts):
    print('selecting model to test...')
    if 'cnn' == opts.model:
        if 'onlyIncoming' == opts.mode:
            params = cnn.generate_default_onlyIncoming_params(opts.dataType)
        else:
            params = cnn.generate_default_whole_params(opts.dataType)
        modelObj = cnn.CNN(opts, params)
    elif 'cudnnLstm' == opts.model:
        if 'onlyIncoming' == opts.mode:
            params = cudnnLstm.generate_default_onlyIncoming_params(opts.dataType)
        else:
            params = cudnnLstm.generate_default_whole_params(opts.dataType)
        modelObj = cudnnLstm.LSTM(opts, params)
    elif 'sae' == opts.model:
        if 'onlyIncoming' == opts.mode:
            params = sae.generate_default_onlyIncoming_params(opts.dataType)
        else:
            params = sae.generate_default_whole_params(opts.dataType)
        modelObj = sae.SAE(opts, params)

    return params, modelObj
Ejemplo n.º 3
0
def chooseModel(opts, ifTest=True, NUM_CLASS=100, modelPath=''):
    if 'cnn' == opts.model:
        if 'onlyIncoming' == opts.mode:
            params = cnn.generate_default_onlyIncoming_params(opts.dataType)
        else:
            params = cnn.generate_default_whole_params(opts.dataType)
        modelObj = cnn.CNN(opts, params)
    elif 'cudnnLstm' == opts.model:
        if 'onlyIncoming' == opts.mode:
            params = cudnnLstm.generate_default_onlyIncoming_params(opts.dataType)
        else:
            params = cudnnLstm.generate_default_whole_params(opts.dataType)
        modelObj = cudnnLstm.LSTM(opts, params)
    elif 'sae' == opts.model:
        if 'onlyIncoming' == opts.mode:
            params = sae.generate_default_onlyIncoming_params(opts.dataType)
        else:
            params = sae.generate_default_whole_params(opts.dataType)
        modelObj = sae.SAE(opts, params)
    if ifTest:
        modelObj = modelObj.create_model(NUM_CLASS)
        modelObj.load_weights(modelPath)
    return modelObj, params