def main(opts): RECEIVED_PARAMS = nni.get_next_parameter() LOG.debug(RECEIVED_PARAMS) if 'onlyIncoming' == opts.mode: PARAMS = sae.generate_default_onlyIncoming_params(opts.dataType) elif 'both' == opts.mode: PARAMS = sae.generate_default_whole_params(opts.dataType) PARAMS.update(RECEIVED_PARAMS) try: X_train, y_train, X_test, y_test, labelMap = prepareData.loadTrainAndTestData(opts.input, PARAMS['data_dim'], opts.dataType, opts.mode) NUM_CLASS = len(set(y_test)) y_train = np_utils.to_categorical(y_train, NUM_CLASS) y_test = np_utils.to_categorical(y_test, NUM_CLASS) sae_model = SAE(opts, PARAMS) modelPath = sae_model.train(PARAMS, X_train, y_train, NUM_CLASS) sae_model.test(X_test, y_test, NUM_CLASS, modelPath) except Exception as e: LOG.exception(e) raise
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
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