我正在尝试使用Keras Tuner测试我的神经网络的不同配置和超参数
我有在调谐器外部运行的代码可以运行(但是必须在禁用急切执行的情况下运行它),
但是在调谐器内部,会抛出异常。我是使用更复杂的神经网络的新手,所以我试图浏览文档,但有时会迷路。
她的custom_loss和模型以及调谐器代码
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
这是模特
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
这是调谐器代码
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
...
再次看起来很奇怪,因为它是在我加载没有调谐器的模型时运行的