Consider using one of the following signatures instead: nonzero(*, bool as_tuple) (Triggered internally at ..\torch\csrc\utils\python_arg_parser.cpp:882.) idx = (iou > iou_thresh).nonzero().squeeze()用中文回答
时间: 2024-02-09 20:08:11 浏览: 68
这个错误提示出现在使用 PyTorch 中的 `nonzero` 函数时。你的代码中使用了 `(iou > iou_thresh).nonzero().squeeze()` 这一行代码,它的作用是返回大于 `iou_thresh` 的 IOU 值的索引。
这个错误提示的意思是建议你不要使用已经弃用的 `nonzero()` 函数的签名,而是使用 `nonzero(*, bool as_tuple)` 的签名。这意味着你需要在调用 `nonzero()` 函数时通过命名参数 `as_tuple` 显式地指定一个布尔值参数。
你可以将代码修改为以下形式:
```
idx = (iou > iou_thresh).nonzero(as_tuple=False).squeeze()
```
这样代码就会显式地指定 `as_tuple` 参数为 `False`,以避免出现错误提示中提到的问题。
需要注意的是,`squeeze()` 函数的作用是去除维度为 1 的维度,如果在 `nonzero()` 函数的结果中只有一个维度是非 1 的,那么 `squeeze()` 函数可以去除该维度。如果 `nonzero()` 函数的结果中有多个维度都不为 1,那么需要根据实际情况选择是否使用 `squeeze()` 函数。
相关问题
W: http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg are ignored as the file is not readable by user '_apt' executing apt-key. W: http://archive.ubuntu.com/ubuntu/dists/jammy/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg are ignored as the file is not readable by user '_apt' executing apt-key. W: GPG error: http://archive.ubuntu.com/ubuntu jammy InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C E: The repository 'http://archive.ubuntu.com/ubuntu jammy InRelease' is not signed. W: http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg are ignored as the file is not readable by user '_apt' executing apt-key. W: http://security.ubuntu.com/ubuntu/dists/jammy-security/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg are ignored as the file is not readable by user '_apt' executing apt-key. W: GPG error: http://security.ubuntu.com/ubuntu jammy-security InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C E: The repository 'http://security.ubuntu.com/ubuntu jammy-security InRelease' is not signed. W: http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg are ignored as the file is not readable by user '_apt' executing apt-key. W: http://archive.ubuntu.com/ubuntu/dists/jammy-updates/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg are ignored as the file is not readable by user '_apt' executing apt-key. W: GPG error: http://archive.ubuntu.com/ubuntu jammy-updates InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C E: The repository 'http://archive.ubuntu.com/ubuntu jammy-updates InRelease' is not signed. W: http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/ubuntu-keyring-2012-cdimage.gpg are ignored as the file is not readable by user '_apt' executing apt-key. W: http://archive.ubuntu.com/ubuntu/dists/jammy-backports/InRelease: The key(s) in the keyring /etc/apt/trusted.gpg.d/ubuntu-keyring-2018-archive.gpg are ignored as the file is not readable by user '_apt' executing apt-key. W: GPG error: http://archive.ubuntu.com/ubuntu jammy-backports InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 871920D1991BC93C E: The repository 'http://archive.ubuntu.com/ubuntu jammy-backports InRelease' is not signed. E: Problem executing scripts APT::Update::Post-Invoke 'rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true' E: Sub-process returned an error code
这个错误是由于apt-key无法读取/etc/apt/trusted.gpg.d/目录下的文件,导致无法验证Ubuntu软件源的签名。解决这个问题的方法是:
1. 使用以下命令导入缺失的公钥:
```
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 871920D1991BC93C
```
注意替换上述命令中的871920D1991BC93C为您的错误中所提到的缺失的公钥。
2. 如果上述命令无效,可以尝试使用以下命令:
```
sudo apt-key adv --refresh-keys --keyserver keyserver.ubuntu.com
```
3. 如果上述命令仍然无效,可以尝试手动下载公钥并导入。首先,找到缺失的公钥的ID,例如871920D1991BC93C。然后,使用以下命令下载公钥:
```
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 871920D1991BC93C
```
最后,使用以下命令将公钥导入系统:
```
sudo apt-key add /path/to/downloaded/key
```
注意替换上述命令中的/path/to/downloaded/key为您下载的公钥文件的路径。
完成上述步骤后,再次运行apt-get update应该就不会出现上述错误了。
Fetched 1,027 kB in 5s (190 kB/s) Reading package lists... Done W: An error occurred during the signature verification. The repository is not updated and the previous index files will be used. GPG error: http://packages.ros.org/ros/ubuntu bionic InRelease: The following signatures were invalid: EXPKEYSIG F42ED6FBAB17C654 Open Robotics <info@osrfoundation.org> W: Failed to fetch http://packages.ros.org/ros/ubuntu/dists/bionic/InRelease The following signatures were invalid: EXPKEYSIG F42ED6FBAB17C654 Open Robotics <info@osrfoundation.org> W: Some index files failed to download. They have been ignored, or old ones used instead.
这是一个常见的错误,可能是由于 GPG 密钥过期或未正确安装所致。您可以尝试以下步骤来解决这个问题:
1. 打开终端,输入以下命令以删除旧的 GPG 密钥:
```
sudo apt-key del F42ED6FBAB17C654
```
2. 输入以下命令以获取新的 GPG 密钥:
```
sudo apt-key adv --keyserver 'hkp://keyserver.ubuntu.com:80' --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654
```
3. 输入以下命令以更新包列表:
```
sudo apt update
```
4. 如果仍然出现问题,则可以尝试更改软件源,将其更改为其他可行的软件源。
阅读全文