1

我目前正在使用 Keras 调谐器 RandomSearch 为我的模型搜索最佳超参数。我的调优代码如下:

# fix random seed for reproducibility
numpy.random.seed(7)

# normalize the dataset
scaler = MinMaxScaler(feature_range=(0, 1))
dataset = scaler.fit_transform(Data)

X_train,X_test,Y_train,Y_test=train_test_split(Data.drop(labels=['SOC'],axis=1),Data['SOC'],
test_size=0.35,random_state=0)



from tensorflow.keras import layers
from kerastuner.tuners import RandomSearch

def build_model(hp):
    model=Sequential()
    for i in range(hp.Int('num_layers',1,17)):
        model.add(Dense(units=hp.Int('units_' + str(i), min_value=1, max_value=17,step=1),
            activation='relu'))
    model.add(layers.Dense(1,activation='linear'))
    model.compile(optimizer='adam',loss='mean_squared_error',metrics=['mean_squared_error','mae'])
    return model

tuner = RandomSearch(build_model,objective='mean_squared_error',max_trials=290,executions_per_trial=3,
    directory='ANN_Layeranzahl',project_name='Model1')

tuner.search(X_train,Y_train,epochs=100,validation_data=(X_test,Y_test), verbose=1)

tuner.search_space_summary()

tuner.results_summary()

但是,经过 18 次试验后,我收到了此错误消息。

File "C:\Users\bunch\Desktop\Masterarbeit\Python\.venv\lib\site-packages\keras_tuner\engine\base_tuner.py", line  File "C:\Users\bunch\Desktop\Masterarbeit\Python\.venv\lib\site-packages\keras_tuner\engine\base_tuner.py", line 179, in search
    results = self.run_trial(trial, *fit_args, **fit_kwargs)
  File "C:\Users\bunch\Desktop\Masterarbeit\Python\.venv\lib\site-packages\keras_tuner\engine\tuner.py", line 304, in run_trial
    obj_value = self._build_and_fit_model(trial, *args, **copied_kwargs)
  File "C:\Users\bunch\Desktop\Masterarbeit\Python\.venv\lib\site-packages\keras_tuner\engine\tuner.py", line 234, in _build_and_fit_model
    return self.hypermodel.fit(hp, model, *args, **kwargs)
  File "C:\Users\bunch\Desktop\Masterarbeit\Python\.venv\lib\site-packages\keras_tuner\engine\hypermodel.py", line 137, in fit
    return model.fit(*args, **kwargs)
  File "C:\Users\bunch\Desktop\Masterarbeit\Python\.venv\lib\site-packages\keras\utils\traceback_utils.py", line 67, in error_handler
    raise e.with_traceback(filtered_tb) from None
  File "C:\Users\bunch\Desktop\Masterarbeit\Python\.venv\lib\site-packages\tensorflow\python\eager\function.py", line 3294, in _cache_key
    input_signature = pywrap_tfe.TFE_Py_EncodeArg(
tensorflow.python.eager.core._NotOkStatusException: InvalidArgumentError: PyLong_AsSize_t failure

有谁知道这个错误是什么意思以及为什么我得到它?

我很感激任何帮助或建议:)

4

0 回答 0