gpt4 book ai didi

python - 在 for 循环中并行执行模型预测

转载 作者:行者123 更新时间:2023-12-04 09:43:46 26 4
gpt4 key购买 nike

我想在 for 循环中多次对我的输入运行 keras 模型的预测。有没有办法并行化这个 for 循环,因为循环的每次迭代都是独立的?我只想将每次迭代的预测存储在 mc_predictions 中大批。

mc_predictions = []
for i in range(100):
y_p = model.predict(x)
mc_predictions.append(y_p)

我在模型中使用了 dropout 层,而我已将训练属性设置为 True。因此,每次我都会得到不同的结果,因为每次迭代都会停用不同的神经元。我在这里使用蒙特卡罗估计。

最佳答案

Q : "Is there a way to parallelize this for loop as each iteration of the loop is independent of the other?"



好吧,如果没有深入了解实际的 model 实例,则不会。

The model-instance could easily be a state-full-system and changing some part of its internal state by each call to the .predict()-method ... so one cannot be sure a-priori, without re-inspecting the model's implementation, could one?
– user3666197 6 min ago



正如预告片中的 was 补充说的那样“......在每次迭代中不同的神经元将被停用。”风景变了。

没有办法使定义纯 [SERIAL] 过程“发生”成为 True- [PARALLEL]

Q.E.D.

But is this really a pure serial process? I mean, each iteration is independent. What neurons get deactivated in an iteration does not matter as long as random neurons are getting deactivated.
Crazzay1903 4 hours ago



最可能的 情况 中,它是一个纯 [SERIAL] 过程(除非也以某种方式和彻底证明)落入不保持可重复和重新验证就绪科学的陷阱(人们可能会争辩说它可以合法地成为一个主要的非确定性随机过程 - 公平,好的 - 然而,即使如此,证明已经实现这样一个稳健的非确定性随机过程,以便能够证明它在某些 True- [PARALLEL] 过程实现(如果有任何这样的在经过尝试和证明是这样之后)但是, .predict() - 方法必须并且不能以其他方式变得更具有洞察力,而不是任何严格的,定量支持的公平科学方法,不是吗? ) 这不是目标,是吗?)。

Q.E.D.

关于python - 在 for 循环中并行执行模型预测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62211686/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com