python - torch.rand(1, 3, 64, 64) 是什么意思?

标签 python pytorch

我是 PyTorch 的初学者。在一个教程中,我看到:torch.rand(1, 3, 64, 64),我知道它创建了一个具有遵循标准正态分布的随机数的张量。

输出如下:

tensor([[[[0.1352, 0.5110, 0.7585,  ..., 0.9067, 0.4730, 0.8077],
          [0.2471, 0.8726, 0.3580,  ..., 0.4983, 0.9747, 0.5219],
          [0.8554, 0.4266, 0.0718,  ..., 0.6734, 0.8739, 0.6137],
          ...,
          [0.2132, 0.9319, 0.5361,  ..., 0.3981, 0.2057, 0.7032],
          [0.3347, 0.5330, 0.7019,  ..., 0.6713, 0.0936, 0.4706],
          [0.6257, 0.6656, 0.3322,  ..., 0.6664, 0.8149, 0.1887]],

         [[0.3210, 0.6469, 0.7772,  ..., 0.3175, 0.5102, 0.9079],
          [0.3054, 0.2940, 0.6611,  ..., 0.0941, 0.3826, 0.3103],
          [0.7484, 0.3442, 0.1034,  ..., 0.8028, 0.4643, 0.2800],
          ...,
          [0.9946, 0.5868, 0.8709,  ..., 0.4837, 0.6691, 0.5303],
          [0.1770, 0.5355, 0.8048,  ..., 0.1843, 0.0658, 0.3817],
          [0.9612, 0.0122, 0.5012,  ..., 0.4198, 0.3294, 0.2106]],

         [[0.5800, 0.5174, 0.5454,  ..., 0.3881, 0.3277, 0.5470],
          [0.8871, 0.7536, 0.9928,  ..., 0.8455, 0.8071, 0.0062],
          [0.2199, 0.0449, 0.2999,  ..., 0.3570, 0.7996, 0.3253],
          ...,
          [0.8238, 0.1100, 0.1489,  ..., 0.0265, 0.2165, 0.2919],
          [0.4074, 0.5817, 0.8021,  ..., 0.3417, 0.1280, 0.9279],
          [0.0047, 0.1796, 0.4522,  ..., 0.3257, 0.2657, 0.4405]]]])

但这 4 个参数(1, 3, 64, 64) 到底是什么意思呢?谢谢!

最佳答案

这是输出张量的形状。具体来说,这意味着你的输出张量有

  • (1, 3, 64, 64):维度 0 中形状 (3, 64, 64) 的 1 个元素

  • (1, 3, 64, 64):对于给定维度 0,维度 1 中形状 (64, 64) 的 3 个元素

  • (1, 3, 64, 64):对于给定维度 1 和维度 0,维度 2 中的 64 个形状 (64,) 元素

  • (1, 3, 64, 64):对于给定维度 2、维度 1 和维度 0,维度 3 中有 64 个标量

您可以通过将元素数量与张量的“容量”进行比较来确认这一点:

>>> torch.rand(1,3,64,64).numel()
12288
>>> 1 * 3 * 64 * 64
12288

关于python - torch.rand(1, 3, 64, 64) 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70973324/

相关文章:

用于在 3 个进程之间写入(+锁定)/读取文件的 Python 脚本

python - Flask-WTF - validate_on_submit() 永远不会执行

python - 仅使用适用于 Apple 机器和 Linux 的 pip 安装 Pytorch CPU

python - pytorch DataLoader 第一个时代非常慢

Python:按数字对列表列表进行排序

python - exec() 在遇到 : character 时引发 'unexpected EOF' 错误

python - 将多重处理应用于 pandas 数据框中独特条目类别的最有效方法是什么?

pytorch - 输入类型(MPSFloatType)和权重类型(torch.FloatTensor)应该相同

CUDA 内核失败 : no kernel image is available for execution on the device, 在 Google Compute VM 内运行 PyTorch 模型时出错

deep-learning - 使用 KL 散度时,变分自动编码器为每个输入 mnist 图像提供相同的输出图像