出现上述bug是在第一次查看pytorchhub可用模型的时候发生的
>>torch.hub.list('pytorch/vision')
没有记录下来,所以没办法重现
解决方法是:
定位到hub.py文件的_remove_if_exists(path)方法,pycharm定位方式是直接点击bug最后一行显示bug提示
例如:
该方法原代码如下:
def _remove_if_exists(path): if os.path.exists(path): if os.path.isfile(path): os.remove(path) else: shutil.rmtree(path)
修改为:
def _remove_if_exists(path): if os.path.exists(path): if os.path.isfile(path): # os.remove(path) pass else: shutil.rmtree(path)
然后执行
>>torch.hub.list('pytorch/vision'),发现能够成功获取所有模型
最后再将hub.py修改回来即可。