AttributeError: module 'torch.onnx' has no attribute 'import_graph'
时间: 2023-10-19 15:06:15 浏览: 55
This error message indicates that you are trying to use the `import_graph` function from the `torch.onnx` module, but the module does not have that attribute. This could be due to a version mismatch or an incorrect installation of PyTorch.
To resolve this issue, you can try updating your PyTorch installation to the latest version by running `pip install torch --upgrade`. If you are already on the latest version, you can try reinstalling PyTorch by running `pip uninstall torch` followed by `pip install torch`.
If the issue persists, you can try using a different version of PyTorch or contacting the PyTorch support team for further assistance.
相关问题
torch_graph = torch.onnx._optimize_trace(trace, torch.onnx.OperatorExportTypes.ONNX) AttributeError: module 'torch.onnx' has no attribute '_optimize_trace'
这个错误通常是因为你使用的 torch 版本过低。在旧版本的 torch 中,确实没有 `_optimize_trace` 这个属性。你可以尝试升级 torch 到最新版本来解决这个问题。你可以使用下面的命令来升级 torch:
```
pip install --upgrade torch
```
如果你已经安装了最新版本的 torch,但仍然遇到这个错误,请确保你的代码没有其他问题,并且按照正确的方式导入和使用 `torch.onnx` 中的函数。
AttributeError: 'DGLGraph' object has no attribute 'is_directed'
根据提供的引用内容,出现 'AttributeError: 'DGLGraph' object has no attribute 'is_directed'' 的原因是DGLGraph对象没有is_directed属性。这可能是因为您使用的是DGLHeteroGraph对象而不是DGLGraph对象。DGLHeteroGraph是DGLGraph的子类,但是它没有is_directed属性。如果您想检查DGLHeteroGraph对象是否有向,可以使用以下代码:
```python
# 创建一个DGLHeteroGraph对象
g = dgl.heterograph({
('user', 'follow', 'user'): (torch.tensor([0, 1]), torch.tensor([1, 2]))
})
# 检查DGLHeteroGraph对象是否有向
print(g.is_block)
```
如果您想检查DGLGraph对象是否有向,可以使用以下代码:
```python
# 创建一个DGLGraph对象
g = dgl.graph((torch.tensor([0, 1]), torch.tensor([1, 2])))
# 检查DGLGraph对象是否有向
print(g.is_directed())
```
相关推荐
![py](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)