2022.11组队学习——跨模态视频搜索VCED

项目地址《datawhalechina/vced》

一、环境配置(1.2章节可跳过)

这部分环境配置参考《[datawhale202211]跨模态神经搜索实践:环境配置》

1.1 docker启动本项目

1.1.1 win10下安装docker

参考文章:

  下载docker的windows安装包,直接安装就行(默认勾选的WSL不要改),安装完后重启。我是装过centos的,中间有些步骤就省了(看上面帖子)。

  • 报错1:
    在这里插入图片描述
    这是WSL2需要更新,最新版WSL2点击下载安装就行,安装完后点restart。
  • 报错2:无法启动
Docker.Core.DockerException:
Failed to start
   在 Docker.Engines.LinuxkitDaemonStartup.<WaitAsync>d__5.MoveNext() 位置 C:\workspaces\main-merge\src\github.com\docker\pinata\win\src\Docker.Engines\LinuxkitDaemonStartup.cs:行号 54
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 Docker.Engines.WSL2.LinuxWSL2Engine.<DoStartAsync>d__26.MoveNext() 位置 C:\workspaces\main-merge\src\github.com\docker\pinata\win\src\Docker.Engines\WSL2\LinuxWSL2Engine.cs:行号 170
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 Docker.ApiServices.StateMachines.TaskExtensions.<WrapAsyncInCancellationException>d__0.MoveNext() 位置 C:\workspaces\main-merge\src\github.com\docker\pinata\win\src\Docker.ApiServices\StateMachines\TaskExtensions.cs:行号 29
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   在 Docker.ApiServices.StateMachines.StartTransition.<DoRunAsync>d__5.MoveNext() 位置 C:\workspaces\main-merge\src\github.com\docker\pinata\win\src\Docker.ApiServices\StateMachines\StartTransition.cs:行号 67
--- 引发异常的上一位置中堆栈跟踪的末尾 ---
   在 System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   在 Docker.ApiServices.StateMachines.StartTransition.<DoRunAsync>d__5.MoveNext() 位置 C:\workspaces\main-merge\src\github.com\docker\pinata\win\src\Docker.ApiServices\StateMachines\StartTransition.cs:行号 92

以管理员权限运行docker就行。
安装完后,在cmd命令行输入docker run hello-world会显示:

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
  1. 安装docker compose,升级pip(pip不升级一会会安装失败)
pip install docker compose
python.exe -m pip install --upgrade pip
1.1.2 配置容器

下载本项目
使用代码git clone https://github.com/datawhalechina/vced.git下载项目源码时报错warning: Clone succeeded, but checkout failed,原因是有个文件名的路径过长。解决办法是进入文件夹的目录中,执行:

git config core.longpaths true
git status
git restore --staged .
git restore .

开始安装

在刚刚克隆的vced项目文件夹下,运行bush命令:

docker-compose build

安装完成后显示:(pip要升级到22.3.1)

LS@DESKTOP-OHLNREI MINGW64 /e/Git Bash/vced (main)
$ docker-compose build
[+] Building 1893.0s (12/12) FINISHED
 => [internal] load build definition from Dockerfile                       1.1s
 => => transferring dockerfile: 505B                                       0.0s
 => [internal] load .dockerignore                                          1.5s
 => => transferring context: 2B                                            0.0s
 => [internal] load metadata for docker.io/richardbst/container4vced:late  1.7s
 => [internal] load build context                                          0.6s
 => => transferring context: 2.73kB                                        0.0s
 => [1/7] FROM docker.io/richardbst/container4vced@sha256:a0eec5084bb4615  0.0s
 => CACHED [2/7] WORKDIR /code                                             0.0s
 => CACHED [3/7] COPY requirements.txt requirements.txt                    0.0s
 => CACHED [4/7] RUN pip config set global.index-url https://pypi.tuna.ts  0.0s
 => [5/7] RUN pip install torch==1.11.0 -i  https://pypi.douban.com/sim  672.6s
 => [6/7] RUN pip install -r requirements.txt     && pip install git+h  1155.3s
 => [7/7] COPY . .                                                         3.2s
 => exporting to image                                                    54.2s
 => => exporting layers                                                   49.2s
 => => writing image sha256:62818884495f70b99644f4616f6b3893757804dd06a17  0.4s
 => => naming to docker.io/library/vced-vced                               0.2s

Use 'docker scan' to run Snyk tests against images to find vulnerabilities and l
earn how to fix them
(base)
LS@DESKTOP-OHLNREI MINGW64 /e/Git Bash/vced (main)

然后运行docker-compose up -d,成功之后,在docker desktop中可以看到配置好的vced容器:
在这里插入图片描述

1.1.3 启动项目

运行vced容器,需要稍微等一会会儿,等到显示web启动完成。
在这里插入图片描述
通过port可以进入项目
在这里插入图片描述
打开后显示
在这里插入图片描述
上传视频之后点击搜索,可能会报错:
在这里插入图片描述这是因为第一次要下载编码文件,运行docker-compose restart 就可以了。

1.2 使用vmware下的liunx启动本项目

  安装docker之后无法启动VMware,报错不兼容。解决办法参考《解决VMware Workstation 与 Device/Credential Guard不兼容》。这部分我之前的centos估计被我玩坏了,出现各种问题难以解决,我放弃了,在1.3 中重装ubuntu20。

1.2.1 升级python3.9
  1. 下载python3.9
    本人已安装centos8,这里就不写了。下面是升级python3.9。进入usr/local文件夹,下载安装包:
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
tar xzf Python-3.9.0.tgz
cd Python-3.9.0
  1. 在Python-3.9.0目录下生成安装配置文件:
./configure --prefix=/usr/local/Python3.9.0
"""(可选)If you want a release build with all stable optimizations active 就运行:"""
./configure --enable-optimizations # 可选,gcc版本4.8.5太低会出错,就不要运行这一行

"""altinstall 不自动创建链接,需要手动创建,建议使用,保障多个版本共存:"""
make && make  altinstall
  1. 正确安装之后运行/usr/local/python3.9/bin/python3.9显示:
[root@localhost Python-3.9.0]# /usr/local/python3.9.0/bin/python3.9
Python 3.9.0 (default, Dec 18 2021, 21:47:55) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)] on linux
Type "help", "copyright", "credits" or "license" for more information.
  1. 配置环境变量和建立软连接:
export PYTHON_HOME=/usr/local/python3.9.0 # 少写了一个0,后面出了一堆错误
export PATH=${PYTHON_HOME}/bin:$PATH
source /root/.bashrc # 刷新使上面命令生效
ln -s /usr/local/python3.9.0/bin/python3.9 /usr/bin/python3
python3 -V
Python 3.9.0

5 .踩坑
我之前安装完报错,就是gcc太低还运行了上面第二步

SystemError: <built-in function compile> returned NULL without setting an error
generate-posix-vars failed
make: *** [pybuilddir.txt] 错误 1

参考《python 3.8.0 编译报错 Could not import runpy module 解决方案》,这是因为在低版本的gcc版本(我的是gcc 4.8.5 )中带有 --enable-optimizations 参数时会出现上面问题,解决办法是:

  • 升级gcc至8.1.0【不推荐】
  • ./configure参数中去掉 --enable-optimizations(liunx还原后执行上面步骤,只是去掉./configure --enable-optimizations就行)

  我一开始运行yum update -y等等升级没用,后来只找到是要升级gcc,于是下载升级gcc 11.2(参考帖子《Centos 8安装gcc的方法》,下载gcc源码包)。结果make编译4小时后make install失败了,报错/libcc1/findcomp.cc:21:10: 致命错误:string:没有那个文件或目录,我疯了,参考参考《切换编译器》,貌似是只能在opt里面编译,我将gcc下在了usr/local,所以编译前需要运行以下代码:

#新建gcc-bulid目录(与gcc-10.2.0同级)并进入该目录中:
mkdir gcc-build
cd gcc-build/
# 生成Makefile文件
../gcc-11.2.0/configure -prefix=/usr/local --enable-checking=release --enable-languages=c,c++ --disable-multilib
1.2.2 安装其他包
pip install rust -i http://pypi.douban.com/simple --trusted-host pypi.douban.com

不知道为啥直接安装总报错,感觉我的centos已经废了

1.3 使用WSL下的linux启动本项目

参考《WSL官方文档》《颠覆虚拟机的神器——WSL来了》《Microsoft Learn:WSL 入门》
WSL2与VMware不兼容问题解决:

  • 将WSL2降级成WSL1(WSL1可以兼容VMware)
  • 启用VMware时cmd管理员模式输入命令bcdedit /set hypervisorlaunchtype off,启用WSL2时输入bcdedit /set hypervisorlaunchtype auto。输入bcdedit /enum可以查看是否修改成功,之后可能要重启生效。
1.3.1 安装WSL

  WSL是windows10的一个子系统(windows subsystem for linux),其作用是在windows下运行GNU/linux操作系统 (包括大多数命令行工具、实用工具和应用程序),且不会产生传统虚拟机或双启动设置开销。

  在从使用者的角度看,wsl和虚拟机软件是类似的,都可以装linux操作系统,使用其各种功能;但底层实现不一样,wsl运行linux的资源开销没有在虚拟机软件中运行linux的资源开销大。

  1. 打开wsl子系统
    1.0安装的时候需要打开windows可选功能中的“适用于Linux的Windows子系统”,2.0安装的时候不仅要打开可选功能中的“适用于Linux的Windows子系统”,还要打开“虚拟机平台”这个可选功能。
    在这里插入图片描述
1.3. 2安装Ubuntu

以管理员运行cmd,可输入以下命令

命令功能
wsl --list --online查看在线商店获 Linux 版本列表
wsl --list --verbose列出已安装的 Linux 发行版
wsl-cd dir更换工作目录
wsl --distribution <Distribution Name> --user <User Name>通过特定用户运行特定 Linux 发行版
wsl --import <Distribution Name> <InstallLocation> <FileName>导入指定的 tar 文件作为新的分发版
wsl --unregister <DistributionName>注销或卸载 Linux 发行版
wsl --help查看帮助
wsl --export Ubuntu G:\WSL\myUbuntu.tar备份Ubuntu成tar文件,也可以改别的linux系统名
wsl --import Ubuntu install_location file_name.tarwsl迁移
wsl --unregister distro_name删除wsl

我使用的默认安装wsl --install -d Ubuntu,安装后提示输入用户名和密码,之后显示

Welcome to Ubuntu 20.04 LTS (GNU/Linux 4.4.0-19041-Microsoft x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

此时ubuntu已经在开始菜单栏了,点击就可以打开ubuntu20.04的命令行界面:
在这里插入图片描述
建议此时马上备份,然后迁移到别的盘

wsl --export Ubuntu D:\WSL\Ubuntu20.tar # 导出
wsl --unregister Ubuntu # 注销原版本
wsl --set-version2 # 设置默认使用wsl2版本
wsl --import Ubuntu-20.04 D:\Ubuntu D:\WSL\Ubuntu20.tar # 导入

Ubuntu设置

这部分内容参考《设置 WSL 开发环境》

  • 在资源管理器输入\\wsl$,会列出所有安装的linux系统,点击进入就可以看到文件:(如果你指定迁移到别的盘,比如上面就装在D:\Ubuntu,文件就在这里)
    在这里插入图片描述

下面都是一些介绍功能,我git在windows上都装了,跳过

  • 建议使用 Visual Studio Code 或 Visual Studio,因为它们直接支持使用 WSL 进行远程开发和调试。Visual Studio Code 使你能够将 WSL 用作功能完备的开发环境。 Visual Studio 提供了对 C++ 跨平台开发的本机 WSL 支持。

  • 使用 Git 设置版本管理:参考git分布指南。将项目连接到 Git 版本控制系统,同时使用凭据管理器进行身份验证(,使用 Git Ignore 文件,了解 Git 行尾,以及使用内置到 VS Code 的 Git 命令(可使用Git for Windows在 WSL 和 Windows 主机之间共享凭据&设置,之前装过Git就不用再装了)

  • 使用 Docker 设置远程开发容器:参考《WSL 2 上的 Docker 远程容器入门》,使用 Docker Desktop for Windows 将项目连接到远程开发容器。

  • 设置数据库:按照此分步指南开始使用 WSL 上的数据库,并将项目连接到 WSL 环境中的数据库。(MySQL、PostgreSQL、MongoDB、Redis、Microsoft SQL Server 或 SQLite。)
    在这里插入图片描述

  • 设置 GPU 加速以提高性能

1.3.3 运行项目
  1. apt换源更新
    首先apt换源,不然下载太慢。参考《Ubuntu更换国内源(apt更换源)》
# 修改sources.list配置文件:
sudo vim /etc/apt/sources.list
# 在文件最前面添加以下条目来更新源,保险起见,的操作之前做好备份
# 阿里源
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

# 清华源:
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

sudo apt-get update # 更新源
sudo apt install python3.9
su - # 进入root环境
su username # user用户登录

2.安装miniconda(pip没配好,可跳过)

# 下载安装miniconda
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
# 给安装文件添加执行指令
sudo chmod +x Miniconda3-latest-Linux-x86_64.sh
# 安装
sudo ./Miniconda3-latest-Linux-x86_64.sh

中间两次yes(同意条款和初始化),然后选择路径:

Miniconda3 will now be installed into this location:
/root/miniconda3

  - Press ENTER to confirm the location
  - Press CTRL-C to abort the installation
  - Or specify a different location below

[/root/miniconda3] >>> 这里可以输入路径,例如:/opt/miniconda

我这里直接选择默认,装在/root/miniconda3,然后设置环境变量:

vim ~/.bashrc
# 最后一行添加下面路径
export PATH="/root/miniconda3/bin:$PATH"
alias python='/usr/bin/python3.9' # 配置python3.9
source ~/.bashrc	# 生效环境变量
python # 显示python3.9说明配置成功
conda create -n vced python==3.9 # 创建虚拟环境,配置python3.9,环境名叫做vced

报错CondaHTTPError: HTTP 000 CONNECTION FAILED for url,此时退出ubantu,cmd输入wsl --shutdown关闭之后再重启ubantu,输入su -进入root模式。再创建环境,如果还是不行就 conda换源:

vim ~/.condarc #编辑配置文件,加入以下代码

channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/conda-forge/
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud/msys2/free/
  - https://mirrors.ustc.edu.cn/anaconda/pkgs/free/

show_channel_urls: true
remote_read_timeout_secs: 1000.0
conda activate vced # 激活环境
conda info --envs	# 验证是否成功
conda update -n base conda        //update最新版本的conda
conda create -n xxxx python=3.5   //创建python3.5的xxxx虚拟环境
conda activate xxxx               //开启xxxx环境
conda deactivate                  //关闭环境
conda env list                    //显示所有的虚拟环境

环境激活成功,但是pip有问题。/usr/local/bin/python3.9 -m pip install --upgrade pip升级pip出错。

  1. 安装其它包
# 安装rust,选择1(默认安装)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

在这里插入图片描述

sudo apt-get install ffmpeg # 安装ffmpeg
  1. 项目server环境配置
  • pip安装时警告The script pysemver is installed in ‘/home/zhxscut/.local/bin’ which is not on PATH,运行以下代码
  • 我安装过程中出现一次下载torch时ssl错误,重新pip安装就没了,不知道为啥
  • 安装完全部文件后试了一次备份操作wsl --export Ubuntu Ubuntu20.tar,花了半个小时左右。所以WSL备份不如vmware方便。
sudo vim ~/.zshrc 
#把export PATH=/home/zhxscut/.local/bin/:$PATH  放到最后
source ~/.zshrc  # 忘记运行此命令,结果下面运行streamlit run app.py时显示没有streamlit这个命令
# 下载本项目
git clone https://github.com/datawhalechina/vced.git
sudo apt install python3-pip # 安装pip
#考虑到下载很慢,请在Ubuntu系统中配置pip源
mkdir ~/.pip
vim ~/.pip/pip.conf
# 豆瓣源
[global]
trusted-host = pypi.douban.com
index-url = http://pypi.douban.com/simple
# 清华源
[global]
trusted-host =  pypi.tuna.tsinghua.edu.cn
index-url = https://pypi.tuna.tsinghua.edu.cn/simple

# server环境配置
cd code/service
pip install -r requirements.txt

2天前更新了service文件夹下的requirements.txt,安装这个就行(安装包列表如下)

jina==3.4.2
webvtt-py==0.4.6
ffmpeg-python==0.2.0
torchvision==0.12.0
ftfy==6.1.1
regex==2022.4.24
tqdm==4.64.0
transformers==4.9.1
scipy==1.8.0
pillow==9.1.0
tornado==6.1
protobuf==3.20
librosa==0.9.1
streamlit==1.12.0
myst-parser==0.18.1
  1. 安装CLIP
    CLIP安装过程会安装torch和torchvision,在我的实践中其安装版本与后续service环境配置有冲突,故CLIP的安装这一步可挪到service环境配置后进行。
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'ReadTimeoutError("HTTPSConnectionPool(host='pypi.org', port=443): Read timed out. (read timeout=15)")': /simple/nvidia-cuda-runtime-cu11/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7faf99351dc0>: Failed to establish a new connection: [Errno 111] Connection refused')': /simple/nvidia-cuda-runtime-cu11/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x7faf99351160>: Failed to establish a new connection: [Errno 111] Connection refused')': /simple/nvidia-cuda-runtime-cu11/
# 安装CLIP
pip install git+https://github.com/openai/CLIP.git 
  1. 启动项目
  • 启动服务端
cd code/service
python3 app.py

启动服务端时如果报错:
在这里插入图片描述
出现问题的原因是python3.8与python3.9语言特性的不同。具体为:python3.9所支持的函数变量类型定义描述方式:dict[list]及list[int]在python3.8中不被支持。根据其他学习者提供的debug方法,定位至code/service/customIndexer/executor.py文件,定位至文件对应段落,删去此函数变量类型定义,文件中共计两处:

def getNextMaxItem(self, result: list, ignore_range):#ignore_range: dict[list]
	...
def getRange(self, maxItem, result: list, thod = 0.1, ignore_range = None):#ignore_range:  list[int] = None
	...

再次启动,正常运行:
在这里插入图片描述

  • ctrl+C另起一行,启动前端
cd ../web
streamlit run app.py

  如果报错:ImportError: Pandas requires version '3.0.0' or newer of 'jinja2' (version '2.10.1' currently installed).,打开打开\wsl$\Ubuntu\home\zhxscut.local\lib\python3.8\site-packages\pandas\compat_optional.py发现需要3.0.0版本,更新jinja2:

pip install --upgrade jinja2==3.0.0

重新运行后成功:
在这里插入图片描述
我现在的问题就是,在一个ubantu里运行就报错:
两个ubantu运行报错:
在这里插入图片描述
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

神洛华

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值