python - 将 Keras 与 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(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

最佳答案

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

关于python - 将 Keras 与 Spearmint 集成的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36561423/

相关文章:

python - 我的 SDK 有自己的 python 解释器。如何为其安装模块?

python - 通过 "for"循环拆分 pandas 数据帧会导致错误 : KeyError: 'the label [1] is not in the [index]'

python - Pycharm 更新到 2016.2 后导入 RuntimeWarning

python - TypeError : If class_mode ="categorical", y_col 列值必须是字符串、列表或元组类型

python - 神经网络不学习乘法(玩具示例)

python - python AI 的数据集预处理

optimization - ARM NEON : How to implement a 256bytes Look Up table

c++ - 内联函数指针以避免 if 语句

c - 一种计算 1 到 2 之间数字的对数底数 2 的有效方法

python - 当输入的 dtype 为 uint8 时,tf.keras.Model.save 抛出 Not JSON Serialized