[英]How to stack tensors (from images) to train a CNN?
我已将图像转换为张量。 我应该如何堆叠它们以训练 keras 中的卷积神经网络。
mask_tensor = tf.Variable([])
for img in mask_img:
image = tf.io.read_file(img)
tensor = tf.io.decode_jpeg(image, channels=3)
tensor = tf.image.resize(tensor, [128,128])
if mask_tensor.shape == 0:
mask_tensor = tf.stack([tensor])
else:
tf.reshape(tensor, [1,128,128,3])
mask_tensor = tf.stack([mask_tensor, tensor])
InvalidArgumentError: Input to reshape is a tensor with 49152 values, but the requested shape has 98304 [Op:Reshape]
如果您的张量基于此,请尝试:
mask_tensor = tf.TensorArray(dtype=tf.float32, size=0, dynamic_size=True)
for img in mask_img:
image = tf.io.read_file(img)
tensor = tf.io.decode_jpeg(image, channels=3)
tensor = tf.image.resize(tensor, [128,128])
mask_tensor = mask_tensor.write(mask_tensor.size(), tensor)
images = mask_tensor.stack()
images.shape
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.