linux与win版本不兼容,Windows与Linux的Python-Keras兼容性

我在Windows10、Python3.5、Keras2.0.6中训练并保存了一个Keras模型。在

在Windows中,我可以加载模型并重用它。但是,当我尝试在Linux(Ubuntu)Keras 2.0.5中加载模型时,我得到了以下错误:ValueError: Optimizer weight shape (90,) not compatible with provided weight shape (31, 90)

我尝试过卸载Keras并使用Pip重新安装,然后用Conda做同样的事情。这是与Windows和Linux的兼容性问题,还是其他问题?在

非常感谢

用于训练和保存模型的代码:from keras.models import Sequential

from keras.layers import Dense

import keras.backend as K

def inRange(y_true, y_pred):

return K.sum(K.cast(K.less_equal(K.abs(y_true-y_pred), 8), "int32")) / K.shape(y_true)[0]

# create model

model = Sequential()

model.add(Dense(n1, input_dim=X_train.shape[1], activation='relu'))

model.add(Dense(n2, activation='relu'))

model.add(Dense(1, activation='linear'))

# Compile model

model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy', inRange])

# Fit the model

history = model.fit(X_train, y_train, epochs=maxEpoch, batch_size=10)

# evaluate the model

scores = model.evaluate(X_train, y_train)

print("\n%s: %.2f%%" % (model.metrics_names[1], scores[1]*100))

# save the model

model.save('length_predict.h5', overwrite=True, include_optimizer=True)

加载保存模型的代码:

^{pr2}$

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值