VGA视频质量评估模型-2-环境配置

环境部署

前期准备

机器环境 :python 3.7 仅使用cpu 无Anaconda虚拟环境

  1. 使用git命令
git clone https://github.com/QualityAssessment/DOVER.git
  1. 进入项目,终端输入
pip install -r requirements.txt
  1. 其中,由于电脑只能使用cpu并且版本为3.7,需要安装特定的torch和torchvision版本。
pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html

否则会出现以下环境问题:

# 安装时会出现:
ERROR: torch has an invalid wheel, torch has an invalid wheel, .dist-info directory not found
# 跑测试时会出现:
OSError: [WinError 126] 找不到指定的模块。 Error loading "D:\AppData\Python\Ins\lib\site-packages\torch\lib\asmjit.dll" or one of its dependencies.
  1. 在根目录中创建pretrained_weights文件夹
mkdir pretrained_weights
  1. 在pretrained_weights文件夹中,按需求放入DOVER.pth或DOVER-Mobile.pth,下载地址为
https://github.com/QualityAssessment/DOVER/releases

或是可以使用以下命令(但可能像我一样无法下载成功)

wget https://github.com/QualityAssessment/DOVER/releases/download/v0.1.0/DOVER.pth 
wget https://github.com/QualityAssessment/DOVER/releases/download/v0.5.0/DOVER-Mobile.pth
  1. 运行程序
python evaluate_one_video.py -v ./demo/17734.mp4
# or
python evaluate_one_video.py -v ./demo/1724.mp4
# 或者选择自己的视频
python evaluate_one_video.py -v $YOUR_SPECIFIED_VIDEO_PATH$

运行时会出现的问题

TypeError: Expected maxsize to be an integer or None

运行评估函数时发现的问题:

  File "D:\AppData\Python\Code\DOVER\dover\datasets\fusion_datasets.py", line 125, in <module>
    def get_resize_function(size_h, size_w, target_ratio=1, random_crop=False):
  File "D:\AppData\Python\Ins\lib\functools.py", line 474, in lru_cache
    raise TypeError('Expected maxsize to be an integer or None')
TypeError: Expected maxsize to be an integer or None

这个问题的出现在于代码中使用了@lru_cache装饰器,而没有设置maxsize大小:

@lru_cache # 这里没有设置默认的maxsize大小,应设置为@lru_cache(maxsize=128)或@lru_cache(maxsize=None)
def get_resize_function(size_h, size_w, target_ratio=1, random_crop=False):
    if random_crop:
        return torchvision.transforms.RandomResizedCrop(
            (size_h, size_w), scale=(0.40, 1.0)
        )
    if target_ratio > 1:
        size_h = int(target_ratio * size_w)
        assert size_h > size_w
    elif target_ratio < 1:
        size_w = int(size_h / target_ratio)
        assert size_w > size_h
    return torchvision.transforms.Resize((size_h, size_w))

ImportError: cannot import name ‘OrderedDict’ from ‘typing’

import torchvision官方包出现引用问题,python版本是3.7,typing这个文件里面并没有OrderedDict这个模块,但是pytoch的1.13.0版本的torchvision模块里面需要从typing中导入OrderedDict。

  File "D:\AppData\Python\Code\DOVER\dover\datasets\basic_datasets.py", line 9, in <module>
    import torchvision
  File "D:\AppData\Python\Code\DOVER\venv\lib\site-packages\torchvision\__init__.py", line 5, in <module>
    from torchvision import datasets, io, models, ops, transforms, utils
  File "D:\AppData\Python\Code\DOVER\venv\lib\site-packages\torchvision\models\__init__.py", line 16, in <module>
    from .maxvit import *
  File "D:\AppData\Python\Code\DOVER\venv\lib\site-packages\torchvision\models\maxvit.py", line 3, in <module>
    from typing import Any, Callable, List, Optional, OrderedDict, Sequence, Tuple
ImportError: cannot import name 'OrderedDict' from 'typing' (D:\AppData\Python\Ins\lib\typing.py)

解决方法
我们可以安装typing_extensions(这是针对python3.8版本以下的使用方法),相当于是对typing的一个补丁文件,里面会增加一些typing里面没有的东西。安装代码如下:

pip install typing_extensions

然后修改上文提及的maxvit.py文件,不从typing中导入OrderedDict模块,而是从typing_extensions中导入,即可解决问题。

# 将
from typing import Any, Callable, List, Optional, OrderedDict, Sequence, Tuple
# 改为
from typing import Any, Callable, List, Optional, Sequence, Tuple
from typing_extensions import OrderedDict

AssertionError: Torch not compiled with CUDA enabled

  File "D:\AppData\Python\Code\DOVER\venv\lib\site-packages\torch\cuda\__init__.py", line 221, in _lazy_init
    raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

报错原因因为在只使用cpu的torch版本上的调用了cuda命令,这时只能把所有使用cuda的代码都修改掉

# 1.例如
device=torch.device("cuda" if torch.cuda.is_available() else "cpu")
# 改为
device=('cpu')
# 2.例如
torch.nn.function().to(device)
torch.nn.function().cuda()
# 改为
torch.nn.function().cpu()
# 3.注释所有
torch.cuda.empty_cache() #就会直接使用cpu
# 4.例如
torch.load(ckpt_dir)
# 改为
torch.load(ckpt_dir,map_location = ‘cpu’)
# 5.模型中一切设置模型为device与cuda的地方
def fragment_infos(D, H, W, fragments=7, device="cuda"):
def fragment_infos(D, H, W, fragments=7, device="device"):
# 改为
def fragment_infos(D, H, W, fragments=7, device="cpu"):

之后就成功运行了。

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值