将Keras与Spearmint整合的问题

时间:2016-04-12 00:09:41

标签: python optimization keras hyperparameters 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>)

我使用以下代码加载预先创建的列车数据和测试数据的numpy数组。以下参数由优化python脚本传递。但是如果在没有留兰香的情况下运行,那么参数集就可以正常工作。

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

1 个答案:

答案 0 :(得分:0)

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