Python ValueError:参数必须是稠密张量…得到了[80,3,8,8]的形状,但需要[80]和估计器。预测
我正在尝试使用TPUEstimator.predict方法生成一些图像。 这是我的密码Python ValueError:参数必须是稠密张量…得到了[80,3,8,8]的形状,但需要[80]和估计器。预测,python,python-3.x,tensorflow,Python,Python 3.x,Tensorflow,我正在尝试使用TPUEstimator.predict方法生成一些图像。 这是我的密码 generated_iter = model.predict(input_fn=noise_input_fn) #generating images images = [p['fake_images'][:, :, :] for p in generated_iter] #writing to array assert len(
generated_iter = model.predict(input_fn=noise_input_fn) #generating images
images = [p['fake_images'][:, :, :] for p in generated_iter] #writing to array
assert len(images) == 80 #asserting number of images
rgb_images = convert_to_rgb_images(images) #transposing and converting
image_rows = [np.concatenate(rgb_images[i:i + 10], axis=0) #making a 8x10 matrix of images
for i in range(0, 80, 10)]
tiled_image = np.concatenate(image_rows, axis=1)
img = Image.fromarray(tiled_image)
它在标题中给了我一个错误,然后又出现了一些类似这样的例外:
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/content/stylegan-reproduced/train.py", line 326, in <module>
main()
File "/content/stylegan-reproduced/train.py", line 321, in main
train(model_dir, n_images_to_show, batch_size, estimator_params, estimator_ws=ws)
File "/content/stylegan-reproduced/train.py", line 157, in train
rgb_images = convert_to_rgb_images(images)
File "/content/stylegan-reproduced/network/model_fn.py", line 113, in convert_to_rgb_images
output = tf.transpose(images, perm=[0, 2, 3, 1])
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/array_ops.py", line 1738, in transpose
ret = transpose_fn(a, perm, name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/ops/gen_array_ops.py", line 11046, in transpose
"Transpose", x=x, perm=perm, name=name)
File "/usr/local/lib/python3.6/dist-packages/tensorflow/python/framework/op_def_library.py", line 545, in _apply_op_helper
(input_name, err))
ValueError: Tried to convert 'x' to a tensor and failed. Error: Argument must be a dense tensor:
在model_fn内部调用它可以很好地工作,但在model.predict之后会出现错误。我错过了什么
def convert_to_rgb_images(images):
drange_min, drange_max = -1.0, 1.0
scale = 255.0 / (drange_max - drange_min)
output = tf.transpose(images, perm=[0, 2, 3, 1])
output = output * scale + (0.5 - drange_min * scale)
output = tf.clip_by_value(output, 0.0, 255.0)
output = tf.cast(output, dtype=tf.uint8)
return output