vscode 打开 *.go文件的时候提示安装扩展, 点击install 或者 install all的时候 安装失败
打开一个终端执行如下语句
GOPROXY=https://proxy.golang.org,direct
关闭vscode ,重新打开
— 自动化运维 Leaning—
vscode 打开 *.go文件的时候提示安装扩展, 点击install 或者 install all的时候 安装失败
打开一个终端执行如下语句
GOPROXY=https://proxy.golang.org,direct
关闭vscode ,重新打开
运行faceswap faceswap.py gui 的时候提示
File "D:\XX\faceswap\lib\gui\menu.py", line 271, in _get_branches
retcode, stdout.decode().strip().replace("\n", " - "))
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb2 in position 6: invalid start byte
05/28/2022 21:00:14 CRITICAL An unexpected crash has occurred. Crash report written to 'D:\XX\faceswap\crash_report.2022.xx.xx.xxxxx052.log'. You MUST provide this file if seeking assistance. Please verify you are running the latest version of faceswap before reporting
提示文件menu.py line271行错误,
可能是因为我的是中文环境操作系统,所以报错,
找到源文件 faceswap/lib/gui/menu.py,修改271行内容
retcode, stdout.decode().strip().replace("\n", " - "))
为
retcode, stdout.decode("utf8","ignore").strip().replace("\n", " - "))
如图所示
修改完成后再次运行 faceswap faceswap.py gui即可正常打开
有时候设置好环境变量可以起到很大作用,比如把python安装到非系统盘,并且把模块安装到python文件夹里面,这样一个是方便管理,一个是即使系统重新安装了,环境还在,在新系统添加下环境变量即可使用,免去了再次安装模块的步骤。
下面是把python安装到 D:/ 盘,
模块 安装到python目录下面的 site-pakages。
通过pip install 进行安装的时候模块就会安装到python文件夹下。
python --version
pip list
pip show 模块名
闲来无聊,看到有的AI大神通过图像识别玩fps游戏 ,检测头部或者其他肢体来完成射击,突然来了兴趣,想自己弄一个,于是乎,参照其中一个改了下,原版本是用的是YOLOv5-v5版本,经过自己修改,目前在yolov5-v6.0版本下面正常运行
原始版本 项目地址
再次精简后的版本 项目地址(推荐)
本机实测正常环境:
python 3.8.10
yolov5的v6.0
pywin32 302
cuda Build cuda_11.6.r11.6
pytorch 1.10.0+cu113
torchvision 0.11.1+cu113
硬件:
AMD 5800H
RTX3060
16G内存
三星980 1T固态
在上面的平台,平均检测到射击的时间为15-20 ms,大约一帧的时间
在 8G内存,gtx 1070上面也测试通过,平均检测到射击时间为60ms
前段时间出于兴趣,弄了个yolo v5 训练游戏中目标并进行射击的小程序,后面看到movenet,也想尝试下,我是一个初学者,也没找到其他和fps相关的项目来做参考,就参照movenet给的项目代码改了一下,后面测了下还行,当然也有需要改进的地方,不足之处欢迎指正
代码总共100多行,借助于tensorflow框架,方便很多,实际使用过程中,中近距离没有问题,但是远距离识别率有点低,后期考虑再训练下模型
识别对比和后期功能完善:
1、检测时间,yolov5在3-8ms左右,movenet在10-15ms,
2、使用pyautogui或mss进行截图,然后截取区域进行检测,时间大约在10-35ms不等,考虑其他更快的截图方式
3、yolov5 通过GitHub给的模型训练自己的模型比较方便,labelimg 进行标注然后进行训练即可,比较方便快捷。movenet模型训练方法还在学习和寻找
movenet 项目介绍和使用都比较详细,安装tensorflow2.0框架后,调用和使用都比较方便
基于原代码删减后,只保留了检测和显示两个函数,添加了截图和鼠标自动瞄准
环境搭建可以参考另外一篇文章
YOLO v5项目地址
tensorflow默认情况下是使用所有GPU和显存,有时候我们需要分配显卡资源,需要手动设置,
常用代码
显示gpu或cpu块数
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
cpus = tf.config.experimental.list_physical_devices(device_type='CPU')
print(gpus, cpus)
使用下标为0,1的两块显卡
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
tf.config.experimental.set_visible_devices(devices=gpus[0:2], device_type='GPU')
两种设置显存使用策略
1、按需申请
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
for gpu in gpus:
tf.config.experimental.set_memory_growth(device=gpu, enable=True)
2、固定分配,分配4G显存
gpus = tf.config.experimental.list_physical_devices(device_type='GPU')
tf.config.experimental.set_virtual_device_configuration(gpus[0],
[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=4096)])
3、固定分配,分配60%的GPU显存
config = tf.compat.v1.ConfigProto()
config.gpu_options.per_process_gpu_memory_fraction = 0.6
tf.compat.v1.Session(config=config)
模拟多GPU,建立2个2G 显存的虚拟GPU,可以让多GPU环境代码在单GPU环境运行
gpus = tf.config.experimental.list_physical_devices('GPU')
tf.config.experimental.set_virtual_device_configuration(gpus[0],
[tf.config.experimental.VirtualDeviceConfiguration(memory_limit=2048),
tf.config.experimental.VirtualDeviceConfiguration(memory_limit=2048)])
参考:
movenet需要使用tensorflow框架和显卡驱动的支持,环境的搭建可以通过anacanda一键搭建,但对于我这个初学者,比较喜欢需要什么安装什么来一步步搭建
环境主要需要这么几个:
movenet模型(可在线下载)
opencv-python
tensorflow
tensorflow-gpu
tensorflow_docs
tensorflow_hub
cuda
cudnn
zlib
MoveNet: Ultra fast and accurate pose detection model
pip install opencv-python tensorflow tensorflow-gpu tensorflow_docs tensorflow_hub
如需安装特定版本可以在模块后面加上== ,比如 tensorflow==2.7.1
如需查看现在安装的模块信息,可以通过 pip show 模块名 进行查看,比如 pip show tensorflow
3、cuda toolkit 下载地址
https://developer.nvidia.com/cuda-toolkit-archive
根据自己的系统下载,比如Windows10,cuda11.6.2
安装的话一路默认即可
developer.nvidia.com/rdp/cudnn-archive
下载后是压缩包,需要把压缩包里面的文件解压到cuda安装路径的对应目录,一般默认在
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA
zlib下载地址
www.winimage.com/zLibDll/zlib123dllx64.zip
安装zlib,下载后解压到一个目录,然后把目录添加到系统path环境变量中,cuDNN也可以用同样的方法
https://docs.nvidia.com/deeplearning/cudnn/
1、python ,tensorflow,opencv ,cuda等的版本
可以用新的,不必要非要用老的或者指定版本,通过pip安装默认版本即可
2、not found cudnn_ops_infer64_8.dll 或者not found cudnn_cnn_infer64_8.dll
一般原因是没有安装cudnn或者没有设置cudnn环境变量
3、could not load library cudnn_cnn_infer64_8.dll error code 126或者
could not load library cudnn_cnn_infer64_8.dll error code 193
原因是zlib没有安装或者没有设置zlib目录环境变量,
使用vscode 打开movenet提供的代码,
www.tensorflow.org/hub/tutorials/movenet
这里为了验证做了精简
图片路径和模型路径可根据自己的实际情况修改,模型为手动下载到本地加载,在线加载模型会出错
效果如图
直接通过pip安装pytorch,cuda版本为11.3
pip3 install torch==1.10.0+cu113 torchvision==0.11.1+cu113 torchaudio==0.10.0+cu113 -f https://download.pytorch.org/whl/cu113/torch_stable.html
其他安装方法参照官网
有时候需要python2 有时候要使用python3,kali上面可以通过update-alternatives来进行设置
ls /usr/bin/python*
update-alternatives --install /usr/bin/python python /usr/bin/python3 150
update-alternatives --install /usr/bin/python python /usr/bin/python2 100
update-alternatives --config python
python --verison 查看当前的python版本
labelimg 图片目录 分类文件 标签目录
labelimg .\images2\ .\classes.txt .\labels\
==================
labelimg -h
usage: labelImg [-h] [image_dir] [class_file] [save_dir]
positional arguments:
image_dir
class_file
save_dir
optional arguments:
-h, --help show this help message and exit