Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Can't use powershell to run config with my own code #4452

@DoveEchoing

Description

@DoveEchoing

Describe the issue:
I can use the source code to run nni on my computer,but when I was trying to modify the code to meet my needs,it occurred some mistakes. I referred some examples to modify my code(like regression/classification of sklearn,mnist-keras),because the framework is different,when I first try to modify my code and use powershell to run it,it occurred a lot mistakes.
Today I modified my code once again,it could run successfully in pycharm,but it failed in powershell.
crying,I think I need some help.

Environment:

  • NNI version:2.5
  • Training service (local|remote|pai|aml|etc):local
  • Client OS:Windows 10
  • Server OS (for remote mode only):None
  • Python version:3.6
  • PyTorch/TensorFlow version:1.10.1/2.6.2
  • Is conda/virtualenv/venv used?:conda
  • Is running in Docker?:no

code

LOG = logging.getLogger('ANN Example')

def load_data(train_path='./data/data712pc_train.csv', test_path='./data/data712pc_test.csv'):
    InputIndex = ['X1', 'X2', 'X3', 'X4', 'X5', 'X6', 'X7', 'X8', 'X9', 'X10',
                  'X11', 'X12', 'X13', 'X14', 'X15']
    OutputIndex = ['Y']
    data_train = pd.read_csv(train_path)
    train_X = data_train[InputIndex]
    train_Y = data_train[OutputIndex]
    data_test = pd.read_csv(test_path)
    test_X = data_test[InputIndex]
    test_Y = data_test[OutputIndex]
    minmax = MinMaxScaler(feature_range=(0, 1))
    X_train = minmax.fit_transform(train_X)
    X_test = minmax.transform(test_X)
    Y_train = minmax.fit_transform(train_Y)
    Y_test = minmax.transform(test_Y)
    return X_train, X_test, Y_train, Y_test

def default_params():
    params = {
        'activation': 'relu',
        'optimizer': 'Adam',
        'learning_rate': 0.001,
        'momentum': 0.9
    }
    return params

def create_model(PARAMS):
    layers = [
        Dense(8, activation=PARAMS.get('activation')),
        Dense(4, activation=PARAMS.get('activation')),
        Dense(1, activation=PARAMS.get('activation'))
    ]
    model = Sequential(layers)

    if PARAMS.get('optimizer') == 'Adam':
        optimizer = Adam(lr = PARAMS.get('learning_rate'))
    elif PARAMS.get('optimizer') == 'SGD':
        optimizer = SGD(lr = PARAMS.get('learning_rate'), momentum = PARAMS.get('momentum'))
    else:
        optimizer = RMSprop(lr = PARAMS.get('learning_rate'), momentum = PARAMS.get('momentum'))

    model.compile(loss=keras.losses.mean_squared_error, optimizer=optimizer)

    return model

def run(X_train, X_test, Y_train, Y_test, model):
    model.fit(X_train, Y_train, batch_size=64, epochs=100, verbose=1)
    loss = model.evaluate(X_test, Y_test, verbose=0)
    y_pred = model.predict(X_test)
    rmse = mean_squared_error(Y_test, y_pred) ** 0.5
    print('The rmse of prediction is:', rmse)
    nni.report_final_result(rmse)

if __name__ == '__main__':
    X_train, X_test, Y_train, Y_test = load_data()

    try:
        # get parameters from tuner
        RECEIVED_PARAMS = nni.get_next_parameter()
        LOG.debug(RECEIVED_PARAMS)
        PARAMS = default_params()
        PARAMS.update(RECEIVED_PARAMS)
        LOG.debug(PARAMS)
        model = create_model(PARAMS)
        run(X_train, X_test, Y_train, Y_test, model)
    except Exception as exception:
        LOG.exception(exception)
        raise

search space
search space

config
config_windows

some files
file

error
error

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions