Python 将Keras与留兰香相结合的问题

Python 将Keras与留兰香相结合的问题,python,optimization,keras,hyperparameters,spearmint,Python,Optimization,Keras,Hyperparameters,Spearmint,当我使用spearmint优化Keras模型的超参数时,它第一次运行良好。但是第二个作业继续执行时,它总是抛出以下错误 <type 'exceptions.TypeError'>, TypeError('An update must have the same type as the original shared variable (shared_var=<TensorType(float32, matrix)>, shared_var.type=TensorType(

当我使用spearmint优化Keras模型的超参数时,它第一次运行良好。但是第二个作业继续执行时,它总是抛出以下错误

<type 'exceptions.TypeError'>, TypeError('An update must have the same type as the original shared variable (shared_var=<TensorType(float32, matrix)>, shared_var.type=TensorType(float32, matrix), update_val=Elemwise{add,no_inplace}.0, update_val.type=TensorType(float64, matrix)).', 'If the difference is related to the broadcast pattern, you can call the tensor.unbroadcast(var, axis_to_unbroadcast[, ...]) function to remove broadcastable dimensions.'), <traceback object at 0x18a5c5710>)

我用spearmint设置的变量必须使用float(),int()显式转换为基本python数据类型。这有助于解决这个问题

异常发生在哪一行?问题发生在组合的_model()中,model.compile称为model.compile('adam',{'output':'categorical_crossentropy'})
def load_train_data(arg_type, params=None):

    X_train1 = pickle.load(open(arg_type+"_train1","rb"))

    X_train2 = pickle.load(open(arg_type+"_train2","rb"))

    Y_train = pickle.load(open(arg_type+"_train_labels","rb"))



    model=combined_model(X_train1,X_train2,Y_train,params)



    X_test1 = pickle.load(open(arg_type+"_test1","rb"))

    X_test2 = pickle.load(open(arg_type+"_test2","rb"))

    Y_test = pickle.load(open(arg_type+"_test_labels","rb"))



    loss = model.evaluate({'input1': X_test1,'input2': X_test2,'output':Y_test},batch_size=450)

    return loss