我使用TensorFlow制作一个生成对抗网络来生成面部图像。我正在使用面积的灰度图像,这些图像都缩小到128x128大小。在第一个纪元的末尾,我收到了这个错误:
2018-06-04 11:42:38 PST Traceback (most recent call last):
2018-06-04 11:42:38 PST File "gan.py", line 319, in <module>
2018-06-04 11:42:38 PST train_network()
2018-06-04 11:42:38 PST File "gan.py", line 286, in train_network
2018-06-04 11:42:38 PST save_images(imgtest, [8,8] ,new_image_path + '/epoch' + str(i) + '.png')
2018-06-04 11:42:38 PST File "/code/utils.py", line 34, in save_images
2018-06-04 11:42:38 PST return imsave(inverse_transform(images), size, image_path)
2018-06-04 11:42:38 PST File "/code/utils.py", line 67, in imsave
2018-06-04 11:42:38 PST image = np.squeeze(merge(images, size))
2018-06-04 11:42:38 PST File "/code/utils.py", line 53, in merge
2018-06-04 11:42:38 PST img[j * h:j * h + h, i * w:i * w + w, :] = image
2018-06-04 11:42:38 PST ValueError: could not broadcast input array from shape (128,128,3) into shape (0,128,3)
当我在save_images()
中调用utils.py
时调用以下函数,我认为它正在发生:
def merge(images, size):
h, w = images.shape[1], images.shape[2]
if (images.shape[3] in (3,4)):
c = images.shape[3]
img = np.zeros((h * size[0], w * size[1], c))
for idx, image in enumerate(images):
i = idx % size[1]
j = idx // size[1]
img[j * h:j * h + h, i * w:i * w + w, :] = image
return img
elif images.shape[3]==1:
img = np.zeros((h * size[0], w * size[1]))
for idx, image in enumerate(images):
i = idx % size[1]
j = idx // size[1]
img[j * h:j * h + h, i * w:i * w + w] = image[:,:,0]
return img
else:
raise ValueError('in merge(images,size) images parameter '
'must have dimensions: HxW or HxWx3 or HxWx4')
以下是日志 https://www.floydhub.com/arse123/projects/gan/22/
这是gan.py文件 https://www.floydhub.com/arse123/projects/gan/22/code/gan.py
,这是utils.py文件 https://www.floydhub.com/arse123/projects/gan/22/code/utils.py
此外,这是Siraj Raval对我自己的用例的一个例子的变更:https://www.youtube.com/watch?v=yz6dNf7X7SA
对此的任何帮助都将非常感激