E:\Anaconda\envs\pytorch\python.exe C:/Users/15492/PycharmProjects/pythonProject2/test-2.py Traceback (most recent call last): File "C:\Users\15492\PycharmProjects\pythonProject2\test-2.py", line 41, in <module> batch_x, batch_y = get_batch_data(batch_size) File "C:\Users\15492\PycharmProjects\pythonProject2\test-2.py", line 19, in get_batch_data batch_x = torch.random(batch_size) TypeError: 'module' object is not callable
时间: 2023-07-21 17:05:17 浏览: 336
这个错误提示说明你调用了 torch.random,但是 torch 模块中并没有名为 random 的函数或方法。你可能是想使用 torch.randn 函数来生成随机数,可以把调用 torch.random 改为 torch.randn:
``` python
batch_x = torch.randn(batch_size, input_size)
```
这样就可以生成一个大小为 batch_size x input_size 的随机张量。
相关问题
PackagesNotFoundError: The following packages are not available from current channels: - pytorch3d Current channels: - https://conda.anaconda.org/conda-forge/win-64 - https://conda.anaconda.org/conda-forge/noarch - https://repo.anaconda.com/pkgs/main/win-64 - https://repo.anaconda.com/pkgs/main/noarch - https://repo.anaconda.com/pkgs/r/win-64 - https://repo.anaconda.com/pkgs/r/noarch - https://repo.anaconda.com/pkgs/msys2/win-64 - https://repo.anaconda.com/pkgs/msys2/noarch To search for alternate channels that may provide the conda package you're looking for, navigate to https://anaconda.org and use the search bar at the top of the page.
根据您提供的错误信息,看起来 PyTorch3D 并未在的 conda 渠道中找到。您可以尝试使用 `pip` 命令来安装 PyTorch3D,而不是使用 `conda`。
在安装 PyTorch3D 之前,确保已经按照上述步骤安装了 Visual Studio C++ Build Tools(如果尚未安装)和 CUDA Toolkit(如果需要 GPU 加速)。然后,请按照以下步骤执行:
1. 打开命令提示符或终端窗口。
2. 输入以下命令来安装 PyTorch3D:
```
pip install pytorch3d
```
如果您的系统具有多个 Python 版本,请确保使用与您希望安装 PyTorch3D 的 Python 版本关联的 pip。
这应该会使用 pip 来安装 PyTorch3D。如果一切顺利,您应该能够成功安装 PyTorch3D,并在您的项目中使用它。如果仍然遇到问题,请提供更详细的错误信息,以便我们更好地帮助您解决问题。
PackagesNotFoundError: The following packages are not available from current channels: - python=3.1 Current channels: - https://conda.anaconda.org/pytorch/linux-64 - https://conda.anaconda.org/pytorch/noarch - https://conda.anaconda.org/nvidia/linux-64 - https://conda.anaconda.org/nvidia/noarch - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/linux-64 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main/noarch - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/linux-64 - https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/noarch To search for alternate channels that may provide the conda package you're looking for, navigate to https://anaconda.org and use the search bar at the top of the page.
这是一个包无法找到的错误提示信息,可能是因为你的conda环境中没有安装python=3.1的版本,或者是该版本在当前的渠道中无法找到。你可以尝试在其他渠道或者Anaconda.org中搜索该版本的安装包。同时,你也可以尝试更新conda以获取最新的渠道信息,执行以下命令:conda update conda。
阅读全文