python - 在哪里使用光线 Actor 导入 tensorflow ?

标签 python tensorflow import python-import ray

使用光线 Actor 并行运行多个 tensorflow 模型,我问自己在哪里导入 tensorflow :

# [1] maybe import tensorflow here?

@ray.remote(num_cpus=1)
class Remote_Runner:
    # [2] maybe import tensorflow here?
    def __init__(self, weights):
        # [3] maybe import tensorflow here?
        self.model=My_model()
        self.model.set_weights(wegihts)

    def do_something_with_model:
        self.model.do_something()

文档中给出的示例提到了由于“导入 TensorFlow 和设置全局状态的副作用”而在 Actor 中导入 Tensorflow,但仅给出了射线远程函数的示例。那么我应该在 [1]、[2] 或 [3] 甚至其他地方运行“import tensorflow as tf”?这里是否有可以遵循的最佳实践,[1]、[2]和[3]之间有什么区别,即在每种情况下如何访问 tensorflow 以及它们何时执行?

最佳答案

这个问题现在可能已经修复,但最安全的选择是在 [3] 处导入 tensorflow 。

关于python - 在哪里使用光线 Actor 导入 tensorflow ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59921142/

相关文章:

python - Django UUIDField modelfield 在 Django admin : badly formed hexadecimal UUID string 中导致错误

Python 错误 : missing 'mdb-schema' when using python_access package

Python 从同步函数运行非阻塞异步函数

machine-learning - tf.cond 降低训练速度

python - TensorFlow 中图像分类的输入/输出形状错误

tensorflow - 在使用 per_image_standardization 之前我是否还应该标准化图像数据(除以 255)?

python - 一般来说,在 python 代码中使用语句 "from module import *"是一个不好的做法吗?

python - 在屏幕上显示 PyGame Mask

sql-server - 将accdb格式的Access数据库导入SQL Server 2014(Express版)

javascript - 在vue组件中导入并使用three.js库