如何在 keras CNN 模型中调整 3D 图像的大小?

发布于 2025-01-20 15:25:56 字数 128 浏览 5 评论 0原文

我进行了 3D PET 扫描(无、128、128、60、1)。我想将其大小调整为(无、64、64、30、1)。有时我需要它更小。我想在 keras 模型中执行此操作。我正在考虑类似 tf.image.resize 的东西,但用于 3D 图像。

I have a 3D PET scan (None, 128, 128, 60, 1). I want to resize it to be (None, 64, 64, 30, 1). Sometimes I need it to be even smaller. I want to do this inside a keras model. I was thinking of something like tf.image.resize but for 3D images.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冬天的雪花 2025-01-27 15:25:56

我们可以删除3D图像的最后一个维度(无,128、128、60、1),以便转换后的张量的形状为(无,128、128、60)< /code>与代码> (高度,宽度,频道)。 (注意:所需的形状也可以是(batch_size,高度,宽度,num_channels)

我们将使用 tf.squeeze 为此目的。

import tensorflow as tf

# Some random image
image = tf.random.normal( shape=( 128 , 128 , 60 , 1 ) )
# Remove dimensions of size 1 from `image`
image = tf.squeeze( image )
# Resize the image
resized_image = tf.image.resize( image , size=( 100 , 100 ) )
print( tf.shape( resized_image ) )

输出

tf.Tensor([100 100  60], shape=(3,), dtype=int32)

恢复大小1的删除维度的

resized_image = tf.expand_dims( resized_image , axis=3 )
print( tf.shape( resized_image ))

,您可以使用tf.expand_dims,输出,

tf.Tensor([100 100  60   1], shape=(4,), dtype=int32)

We can remove the last dimension of the 3D image ( None , 128 , 128 , 60 , 1) so that the shape of the transformed tensor is ( None , 128 , 128 , 60 ) that matches with the required shape for tf.image which is ( height , width , channels ). ( Note: the required shape can also be ( batch_size , height, width, num_channels ) )

We will use tf.squeeze for this purpose.

import tensorflow as tf

# Some random image
image = tf.random.normal( shape=( 128 , 128 , 60 , 1 ) )
# Remove dimensions of size 1 from `image`
image = tf.squeeze( image )
# Resize the image
resized_image = tf.image.resize( image , size=( 100 , 100 ) )
print( tf.shape( resized_image ) )

The output

tf.Tensor([100 100  60], shape=(3,), dtype=int32)

To restore the deleted dimension of size 1, you may use tf.expand_dims,

resized_image = tf.expand_dims( resized_image , axis=3 )
print( tf.shape( resized_image ))

The output,

tf.Tensor([100 100  60   1], shape=(4,), dtype=int32)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文