Настройка гиперпараметров LSTM с использованием Talos: ошибка индекса? - PullRequest
0 голосов
/ 01 августа 2020

У меня есть рабочая модель LSTM, к которой я пытаюсь применить Talos для настройки и определения гиперпараметров. Данные представляют собой временной ряд одной переменной. Мой код, включая определение модели, список параметров и вызов сканирования, приведен ниже - я старательно старался следовать примерам талоса и документации. Когда я запускаю это, я получаю сообщение об ошибке. Приветствуется любая помощь или понимание.

Файл "", строка 8, в create_model_talos model.add (LSTM (params ['cells'], input_shape = (time_steps, num_features))) # один слой LSTM IndexError: только целые числа, фрагменты (:), многоточие (...), numpy .newaxis (None) и целочисленные или логические массивы являются допустимыми индексами

def create_model_talos(params, time_steps, num_features, input_loss='mae', input_optimizer='adam',
                 patience=3, monitor='val_loss', mode='min', epochs=100, validation_split=0.1):
    """Uses sequential model class from keras. Adds LSTM layer. Input samples, timesteps, features.
    Hyperparameters include number of cells, dropout rate. Output is encoded feature vector of the input data.
    Uses autoencoder by mirroring/reversing encoder to be a decoder."""
    model = Sequential()
    model.add(LSTM(params['cells'], input_shape=(time_steps, num_features)))  # one LSTM layer
    model.add(Dropout(params['dropout']))  
    model.add(RepeatVector(time_steps))  
    model.add(LSTM(params['cells'], return_sequences=True))  # mirror the encoder in the reverse fashion to create the decoder
    model.add(Dropout(params['dropout']))
    model.add(TimeDistributed(Dense(num_features)))

    print(model.optimizer)
    model.compile(loss=input_loss, optimizer=input_optimizer)

    es = tf.keras.callbacks.EarlyStopping(monitor=monitor, patience=patience, mode=mode)
    history = model.fit(
        X_train, y_train,
        epochs=epochs,  # early stopping will monitor.
        batch_size=params['batch_size'],  
        validation_split=validation_split,  
        callbacks=[es],  
        shuffle=False  
    )

    return history, model


p = {'cells': [4, 8, 16, 32, 64, 128],
     'dropout': (0, 0.4, 10),
     'batch_size': [5, 10, 25, 50]}

scan_object = talos.Scan(X_train, y_train, params=p, model=create_model_talos, experiment_name='test')
...