使用talos进行网格搜索:传递输入错误列表

时间:2019-03-11 22:00:30

标签: machine-learning keras data-science grid-search talos

我正在使用keras功能API。
我正在尝试传递输入列表。
我尝试遵循此issue

但是我仍然遇到错误:

AttributeError: 'list' object has no attribute 'max'

这是我当前的模型:

def create_model(x_train,y_train, parameters): 

# Multiple Inputs


# 1st input model
frame1 = Input(shape=(9216,))
hidden1 = Dense(30, activation='relu')(frame1)
hidden1= Dropout(0.2)(hidden1)
hidden1 = Dense(50, activation='relu')(hidden1)
#hidden1 = Dense(30, activation='relu')(hidden1)
output1 = Dense(10, activation='softmax')(hidden1) 

# 2nd input model
frame2 = Input(shape=(9216,))
hidden2 = Dense(30, activation='relu')(frame2)
hidden1= Dropout(0.2)(hidden2)
hidden2 = Dense(50, activation='relu')(hidden2)
#hidden2 = Dense(30, activation='relu')(hidden2)
output2 = Dense(10, activation='softmax')(hidden2) 

model = Model(inputs=[x1, x2], 
              outputs=[output1, output2])

#Compile the model
model.compile(optimizer='adam', loss='mse', metrics=['mse'])

history = model.fit(model.fit(x=x_train,y=y_train, 
                              validation_split=0.2,
                              batch_size=parameters['batch_size'],
                              shuffle=False,
                              epochs=20,
                              verbose=1))

return history, model 

# summarize layers
print(model.summary())

我用于网格搜索的参数是:

parameters = {'batch_size': [10,20]}

运行此命令时出现错误:

import talos as ta
t = ta.Scan([train1,train2], 
            [y1,y2],
            params=p,
            model=model)  

AttributeError: 'list' object has no attribute 'max'

请注意,我的train1,train2是具有9216个值的numpy数组。 (96x96图片)

1 个答案:

答案 0 :(得分:0)

我认为您解决了这个问题?如果不是,则是因为talos期望xy是numpy数组。如果它们是numpy数组,则意味着talos可以在它们上调用max(),而您不能在列表中调用max(),而列表是您提供给.Scan()的。