python出现如下错误:UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument.如何更改?
时间: 2023-05-18 16:03:05 浏览: 1036
可以在调用 torch.meshgrid() 函数时,加上 indexing='ij' 参数,即可避免这个警告。例如:
x, y = torch.meshgrid(torch.arange(3), torch.arange(4), indexing='ij')
相关问题
UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument.
这个警告是因为在未来的版本中,torch.meshgrid函数将要求传递索引参数。在当前版本中,如果不传递索引参数,函数仍然可以正常工作,但是在未来的版本中,如果不传递索引参数,函数将会报错。为了解决这个问题,可以在调用torch.meshgrid函数时传递索引参数,例如使用return _VF.meshgrid(tensors, **kwargs, indexing='ij')来解除警告。同时,根据传递的索引参数不同,函数返回的结果也会有所不同。
model UserWarning: torch.meshgrid: in an upcoming release, it will be required to pass the indexing argument. return forward_c
The `UserWarning` message you're seeing is related to a change that will be introduced in a future version of PyTorch, specifically when using the `torch.meshgrid` function. This function is used for creating a grid of coordinates for multidimensional arrays, often in the context of tensor operations like convolutions or broadcasting.
The warning suggests that starting from a certain version, the indexing argument will be mandatory when calling `torch.meshgrid`. This is likely to enforce more explicit control over how the indexing is handled. The `forward_c` in the warning might refer to some custom or internal function within your code that uses this function.
Here's what you can do to address this warning:
1. Check the documentation for the specific version you're using and see if there's a recommended way to update your code.
2. Add the indexing argument explicitly when calling `torch.meshgrid`. The syntax usually looks like this: `meshgrid = torch.meshgrid(*arrays, indexing='ij')`, where 'ij' is the default indexing mode (row-major order).
3. If you're not using any indexing customization, you can suppress the warning by wrapping the call with `torch.no_grad()` or `warnings.filterwarnings('ignore', category=UserWarning)` but it's generally better to fix the code.
阅读全文