小编cyb*_*oth的帖子

使用rpy2将.RData文件读入python

我正在尝试使用rpy2模块将.RData文件读入python.下面是代码

>>> from  rpy2.robjects import r
>>> r.load("path to .rdata file")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\dell\WinPython-32bit-2.7.6.3\python-2.7.6\lib\site-packages\rpy2\robjects\functions.py", line 170, in __call__
return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
File "C:\Users\dell\WinPython-32bit-2.7.6.3\python-2.7.6\lib\site-packages\rpy2\robjects\functions.py", line 100, in __call__
res = super(Function, self).__call__(*new_args, **new_kwargs)
rpy2.rinterface.RRuntimeError: Error in readChar(con, 5L, useBytes = TRUE) : cannot open the connection
Run Code Online (Sandbox Code Playgroud)

我目前正在使用Windows 7,64位机器.请帮忙.

python r rpy2 pandas rdata

5
推荐指数
1
解决办法
1966
查看次数

保存后 Keras 加载模型在新的 python 会话中进行随机预测

我正在使用tensorflow版本“2.0.0”和keras版本“2.3.0”来开发模型。这是我保存模型的方法:

seed = 1234
random.seed(seed)
np.random.seed(seed)
tf.compat.v1.random.set_random_seed(seed)
Run Code Online (Sandbox Code Playgroud)

然后,我按照此处的说明保存整个模型:

model.save('some_model_name.h5')
Run Code Online (Sandbox Code Playgroud)

我在训练期间获得了大约 95% 的准确率。当我从不同的 python 会话加载模型时,例如:

# Recreate the exact same model
new_model = load_model('some_model_name.h5', custom_objects={'SeqSelfAttention': SeqSelfAttention})
score = new_model.evaluate([x_img_train, x_txt_train], y_train, verbose=2)
print("%s: %.2f%%" % (new_model.metrics_names[1], score[1]*100))
Run Code Online (Sandbox Code Playgroud)

现在的准确率约为4%。请注意,我有批量归一化层和丢失层。如何使模型的预测在不同会话中保持一致?

python keras tensorflow

5
推荐指数
1
解决办法
1445
查看次数

标签 统计

python ×2

keras ×1

pandas ×1

r ×1

rdata ×1

rpy2 ×1

tensorflow ×1