首页 > 解决方案 > 使用 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)

标签: pythontensorflow

解决方案


推荐阅读