python - 使用 tf.py_function() 运行 tf.distribute.Server 的示例
问题描述
直接从 Tensorflowtf.py_function
文档页面引用:
该操作必须与调用 tf.py_function() 的 Python 程序在同一地址空间中运行。如果您使用分布式 TensorFlow,则必须在与调用 tf.py_function() 的程序相同的进程中运行 tf.distribute.Server,并且必须将创建的操作固定到该服务器中的设备(例如,使用 tf.device ():)
因此,我的问题是:如何使用一个示例,例如此处使用的示例tf.distribute.Server
。
这个例子:
import scipy.ndimage as ndimage
def random_rotate_image(image):
image = ndimage.rotate(image, np.random.uniform(-30, 30), reshape=False)
return image
def tf_random_rotate_image(image, label):
im_shape = image.shape
[image,] = tf.py_function(random_rotate_image, [image], [tf.float32])
image.set_shape(im_shape)
return image, label
rot_ds = images_ds.map(tf_random_rotate_image)
解决方案
推荐阅读
- mysql - 如何使用 MySQL 作为构建组件(如 EC2 Image builder Golden AMI)来构建 Docker Image Builder?
- monitoring - 如何从活动检查中获取 mysql 监控值
- python - 在 Google Colab 上运行 Darknet YOLOv4 时出现 CUDA 错误
- arrays - Excel数组在问题开始处不断添加'符号
- node.js - HTTP 请求数据到 JSON
- php - 对于每个嵌套数组,我都遇到了问题
- python - 使用 keras .h5 模型进行预测时出错?
- c++ - 带有宏的可变参数模板
- kubernetes - 在 kubernetes 中创建一个 JWK 服务器来服务密钥
- arrays - 如何过滤与字符串匹配的数组中的数据?