Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/tensorflow/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么包装一个层会删除Keras中另一个层的内核属性?_Python_Tensorflow_Machine Learning_Keras - Fatal编程技术网

Python 为什么包装一个层会删除Keras中另一个层的内核属性?

Python 为什么包装一个层会删除Keras中另一个层的内核属性?,python,tensorflow,machine-learning,keras,Python,Tensorflow,Machine Learning,Keras,我目前正在创建一个基于LSTM的时间序列预测网络,我想尝试使用Keras的双向包装器,看看它是否能提高我的准确性 但是,添加包装器会导致我的输出层丢失其kernel属性,这在优化器试图访问它时是有问题的,导致编译时崩溃 也就是说,当我这样做时: model = Sequential() model.add(LSTM( 100, batch_input_shape=(batch_size, look_back, features), )) model.add(Dense(1))

我目前正在创建一个基于LSTM的时间序列预测网络,我想尝试使用Keras的双向包装器,看看它是否能提高我的准确性

但是,添加包装器会导致我的输出层丢失其
kernel
属性,这在优化器试图访问它时是有问题的,导致编译时崩溃

也就是说,当我这样做时:

model = Sequential()
model.add(LSTM(
    100,
    batch_input_shape=(batch_size, look_back, features),
))
model.add(Dense(1))

print(hasattr(model.layers[-1], 'kernel'))
真的

但在这样包装LSTM时:

model = Sequential()
model.add(Bidirectional(LSTM(
    100,
    batch_input_shape=(batch_size, look_back, features),
)))
model.add(Dense(1))

print(hasattr(model.layers[-1], 'kernel'))
假的


解决方案是让您的网络预测某些内容,然后使用您的自定义优化器进行编译:

model = Sequential()
model.add(Bidirectional(LSTM(
    100,
    batch_input_shape=(batch_size, look_back, features),
)))
model.add(Dense(1))

model.predict(np.zeros((batch_size, look_back, features)))
print(hasattr(model.layers[-1], 'kernel'))
model.compile(optimizer=CustomOptimizer(), loss='mse')
真的


不需要为预测而编译