关于使用** kwargs传递参数

时间:2016-09-26 21:52:22

标签: python python-2.7 python-3.x

我正在阅读以下代码段,此函数曾被调用为generator = image_gen.get_image_gen_rgb(nx, ny, cnt=20)。我不清楚**kwargsget_image_gen_rgb函数中的使用情况。 cnt=20是否用于在n_image

中设置create_batch的参数
def get_image_gen_rgb(nx, ny, **kwargs):
    def create_batch(n_image):
        print("n_image: ",n_image)
        X = np.zeros((n_image, nx, ny, 3))
        Y = np.zeros((n_image, nx, ny,2))

        for i in range(n_image):
            x, Y[i,:,:,1] = create_image_and_label(nx,ny, **kwargs)
            X[i] = to_rgb(x)
            Y[i,:,:,0] = 1-Y[i,:,:,1]

        return X, Y
  create_batch.channels = 3
  create_batch.n_class = 2
  return create_batch

1 个答案:

答案 0 :(得分:0)

cnt=20用于通过x推导Ycreate_image_and_label的最后一个轴的第二个切片:

x, Y[i,:,:,1] = create_image_and_label(nx,ny, **kwargs) # kwargs = {'cnt': 20}