我试图在dl4j中使用预训练的keras模型,并且可以正确加载(不是真的,但这是不同的问题),但是当我删除卷积层时,会出现空指针异常。
正在正确加载的模型:
aa
奇怪的是,该模型根本无法加载:
model = Sequential([
Conv1D(filters = filter_size, kernel_size = filter_size , input_shape = X.shape[1:], activation = 'relu'),
Conv1D(filters = filter_size, kernel_size = filter_size , input_shape = X.shape[1:], activation = 'relu'),
Flatten(),
Dense(128, activation='relu'),
Dense(128, activation='relu'),
Dense(128, activation='relu'),
Dropout(0.1),
Dense(Y.shape[1])
])
使用Python保存模型
model = Sequential([
Flatten(),
Dense(128, activation='relu'),
Dense(128, activation='relu'),
Dense(128, activation='relu'),
Dropout(0.1),
Dense(Y.shape[1])
])
以Java加载
model.save('radius_position_nn.h5')
堆栈跟踪:
try {
String modelPatch = new ClassPathResource(modelName).getFile().getPath();
model = KerasModelImport.importKerasSequentialModelAndWeights(modelPatch);
} catch (IOException | UnsupportedKerasConfigurationException | InvalidKerasConfigurationException e) {
e.printStackTrace();
}
在我看来,这完全是倒退,我甚至不知道问题可能在哪里。