Python Keras调谐器抛出无效arguminterror
我正在尝试使用Keras Tuner测试我的神经网络的不同配置和超参数Python Keras调谐器抛出无效arguminterror,python,tensorflow,keras,neural-network,loss,Python,Tensorflow,Keras,Neural Network,Loss,我正在尝试使用Keras Tuner测试我的神经网络的不同配置和超参数 我有在调谐器外部运行的代码(但我必须在禁用“急切执行”的情况下运行),但在调谐器内部,我会抛出一个异常。我对使用更复杂的神经网络还不熟悉,所以我试图涉猎文档,但有时会迷路。她的《自定义损耗和模型加调谐器代码》 def custom_loss(yardline): yardline=K.cumsum(yardline) def loss(y_true, y_pred): y_true=K.cumsum(y_true)
我有在调谐器外部运行的代码(但我必须在禁用“急切执行”的情况下运行),
但在调谐器内部,我会抛出一个异常。我对使用更复杂的神经网络还不熟悉,所以我试图涉猎文档,但有时会迷路。
她的《自定义损耗和模型加调谐器代码》
def custom_loss(yardline):
yardline=K.cumsum(yardline)
def loss(y_true, y_pred):
y_true=K.cumsum(y_true)
y_pred= y_pred*yardline
new_total_prob= K.sum(y_pred)
inverse_prob=K.pow(new_total_prob+K.epsilon(), -1)
y_pred= y_pred*inverse_prob
cdf_pred= K.cumsum(y_pred)
return K.mean(K.square(y_true-cdf_pred))
return loss
tuner = kt.Hyperband(
hypermodel=build_model,
objective='val_accuracy',
max_epochs=5,
factor=2,
hyperband_iterations=3,
distribution_strategy=tf.distribute.MirroredStrategy(),
directory='.',
project_name='project')
tuner.search([X_train,yardline_train],y_train,
epochs=5, batch_size=43,
validation_data=([X_val, yardline_val],y_val))
这是模型
def build_model(hp):
input_layer= Input(179,)
yardline=Input(199,)
x=Dense(32)(input_layer)
for i in range(hp.Int('num_layers', 2,4, default=4)):
x= Dense(units=hp.Int('units_' + str(i),
min_value=32,
max_value=512,
step=32),
activation='relu')(x)
if (i==3 or i==5):
x=Dropout(hp.Choice('dropout_'+ str(i),[0.15,0.25]))(x)
output_layer = Dense(199, activation='softmax')(x)
model=Model(inputs=[input_layer, yardline], outputs=output_layer)
model.compile(optimizer='adam',loss=custom_loss(yardline), metrics=['accuracy'])
return model
这是调谐器代码
def custom_loss(yardline):
yardline=K.cumsum(yardline)
def loss(y_true, y_pred):
y_true=K.cumsum(y_true)
y_pred= y_pred*yardline
new_total_prob= K.sum(y_pred)
inverse_prob=K.pow(new_total_prob+K.epsilon(), -1)
y_pred= y_pred*inverse_prob
cdf_pred= K.cumsum(y_pred)
return K.mean(K.square(y_true-cdf_pred))
return loss
tuner = kt.Hyperband(
hypermodel=build_model,
objective='val_accuracy',
max_epochs=5,
factor=2,
hyperband_iterations=3,
distribution_strategy=tf.distribute.MirroredStrategy(),
directory='.',
project_name='project')
tuner.search([X_train,yardline_train],y_train,
epochs=5, batch_size=43,
validation_data=([X_val, yardline_val],y_val))
谢谢你的帮助
该错误特别指出无效参数错误:并期望数据进入input_2
。。。
再次看起来很奇怪,因为当我加载没有调谐器的模型时,它运行了我相信问题来自于您有两个输入的事实。您的
yardline=Input(199,)
未在您的模型中使用,但您仍然将其提供给了损失函数,这是有问题的。为什么有两个不同的输入?我把它添加为输入,这样我就可以把它传递给loss函数,它必须在模型内部才能传递到loss中,或者有其他方法吗?@JamiePickett有什么更新吗?我有一个类似的问题,使用两个输入自定义丢失。谢谢@hhh我有点把它放在一边,一段时间没有看它,但没有,我从来没有真正通过keras tuner得到我所希望的结果。。。我将尝试再次翻阅文档并重试soon@JamiePickett谢谢我认为问题出现在不止一个输入的情况下:我认为问题来自于您有两个输入的事实。您的yardline=Input(199,)
未在您的模型中使用,但您仍然将其提供给了损失函数,这是有问题的。为什么有两个不同的输入?我把它添加为输入,这样我就可以把它传递给loss函数,它必须在模型内部才能传递到loss中,或者有其他方法吗?@JamiePickett有什么更新吗?我有一个类似的问题,使用两个输入自定义丢失。谢谢@hhh我有点把它放在一边,一段时间没有看它,但没有,我从来没有真正通过keras tuner得到我所希望的结果。。。我将尝试再次翻阅文档并重试soon@JamiePickett谢谢我认为当存在不止一个输入时,问题就会出现: