开始使用免费开始使用

重塑张量

在课程后面,您将使用神经网络对手语字母的图像进行分类。有些情况下,网络会接收 1 维张量作为输入,但您的数据来源是图像。根据是灰度图还是彩色图,图像会对应 2 维或 3 维张量。

下图展示了手语字母 A 的灰度图和彩色图。这两张图已为您导入并转换为 numpy 数组 gray_tensorcolor_tensor。请使用已从 tensorflow 导入的 reshape 操作,将这些数组重塑为 1 维向量。注意,gray_tensor 的形状为 28x28,color_tensor 的形状为 28x28x3。

This figure shows grayscale and color images of the sign language letter "A".

本练习是课程的一部分

Python 中的 TensorFlow 入门

查看课程

练习说明

  • gray_tensor 从 28x28 矩阵重塑为 784x1 向量,命名为 gray_vector
  • color_tensor 从 28x28x3 张量重塑为 2352x1 向量,命名为 color_vector

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Reshape the grayscale image tensor into a vector
gray_vector = reshape(____, (____, 1))

# Reshape the color image tensor into a vector
color_vector = reshape(____, (____, ____))
编辑并运行代码