具有多个 returns 并调用 ray.get() 的 Ray python 示例
Ray python example with multiple returns and calling ray.get()
下面的代码完成了所需的行为。是否可以从前两个函数传递第二个参数而不必过早调用 ray.get
?
@ray.remote
def color():
image=cv2.imread("frame30.png", flags=0)
argument= "Hello"
return image,argument
@ray.remote
def black():
image=cv2.imread("frame30.png", flags=0)
argument= "world"
return image,argument
@ray.remote
def concate_two_args(a,b):
return a + " " + b
col= color.remote()
blk= black.remote()
#Do I have to "ray.get" in order to pass the results to concate_two_args?
temp1= ray.get(col)[1]
temp2= ray.get(blk)[1]
results= concate_two_args.remote(temp1,temp2)
ray.get(results)
直接这样做
col, string= color.remote()
ray.get(string)
returns
TypeError: cannot unpack non-iterable ray._raylet.ObjectRef object
您可以尝试将 num_returns
添加到 @ray.remote
吗?例如,
@ray.remote(num_returns=2)
def color():
image=cv2.imread("frame30.png", flags=0)
argument= "Hello"
return image,argument
@ray.remote(num_returns=2)
def black():
image=cv2.imread("frame30.png", flags=0)
argument= "world"
return image,argument
下面的代码完成了所需的行为。是否可以从前两个函数传递第二个参数而不必过早调用 ray.get
?
@ray.remote
def color():
image=cv2.imread("frame30.png", flags=0)
argument= "Hello"
return image,argument
@ray.remote
def black():
image=cv2.imread("frame30.png", flags=0)
argument= "world"
return image,argument
@ray.remote
def concate_two_args(a,b):
return a + " " + b
col= color.remote()
blk= black.remote()
#Do I have to "ray.get" in order to pass the results to concate_two_args?
temp1= ray.get(col)[1]
temp2= ray.get(blk)[1]
results= concate_two_args.remote(temp1,temp2)
ray.get(results)
直接这样做
col, string= color.remote()
ray.get(string)
returns
TypeError: cannot unpack non-iterable ray._raylet.ObjectRef object
您可以尝试将 num_returns
添加到 @ray.remote
吗?例如,
@ray.remote(num_returns=2)
def color():
image=cv2.imread("frame30.png", flags=0)
argument= "Hello"
return image,argument
@ray.remote(num_returns=2)
def black():
image=cv2.imread("frame30.png", flags=0)
argument= "world"
return image,argument