我正在为我的深度学习项目编写一个管道,作为一个好的实践,我尝试做一些断言以确保数据类型匹配,以便以后更容易调试!但是,我不知道如何使用isinstance
来断言torch.Tensor's
{
例如:
assert isinstance(image, torch.Tensor) and isinstance(target['boxes'], torch.Tensor)
assert isinstance(image.dtype, (torch.float32, torch.float64)) and isinstance(target['boxes'].dtype, (torch.float32, torch.float64))
使用assert image.dtype in [torch.float32, torch.float64]
是这里唯一的方法吗?有没有一种优雅的方式可以做到这一点
您可以使用^{}
如果输入不是张量,该函数将引发异常。因此,没有必要对
torch.Tensor
进行独立检查相关问题 更多 >
编程相关推荐