1
我正在讀下面的代碼段,這個函數曾經被調用爲generator = image_gen.get_image_gen_rgb(nx, ny, cnt=20)
。我不太清楚**kwargs
在get_image_gen_rgb
的功能中的用法。確實cnt=20
被用來設置的n_image
參數在create_batch
關於使用** kwargs傳遞參數
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
您好摩西,在此代碼段的上下文,哪一個用於設置n_image。我添加了一個打印輸出函數,並發現n_image = 19。但是,您的意思是Y的最後一個軸的第二個片段是什麼?謝謝 – user288609
'n_image'沒有在該代碼中設置。你正在返回函數'create_batch',它在被調用時傳遞'n_image';你應該循環使用Python中的閉包。最後一個軸的第一片:'Y [i,:,:,0]'和第二片'Y [i,:,:,1]';一個numpy的東西 –
感謝您的回覆。如果n_image沒有設置,它從哪裏來?我在原始代碼中添加了一個打印函數,並發現它保留了輸出19.但是我無法找到它來自哪裏。 – user288609