96辅助游戏论坛 - 辅助工具|www.96fuzhu.com

 找回密码
 立即注册
5498057
117612016
4613091
查看: 12129|回复: 257

5/6更新APEX AI辅助瞄准 带敌我识别 yolov8需要自行搭建运行环境

  [复制链接]
发表于 2023-4-28 14:08 | 显示全部楼层 |阅读模式
本帖最后由 NingNingQwQ 于 2023-5-12 22:38 编辑

2023/5/6再次更新
已补链




2023/4/21更新


Github开源项目

YOLOV8辅助瞄准

如何设置环境:
pip install -r requirements.txt
如果您有支持 CUDA 的 GPU,则可以运行以下额外命令
pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116


使用 TensorRT 加速(可选)
添加以下命令:
pip install --upgrade setuptools pip --userpip install nvidia-pyindexpip install --upgrade nvidia-tensorrtpip install pycuda
如果你不能以这种方式安装tensorrt,你可以查找这个[color=var(--color-accent-fg)]Nvidia指南。
我提供了“.trt”模型,但很有可能您必须自己将“.pt”模型转换为“.trt”模型,因为 Tensorrt 引擎是特定于环境的。此存储库可能会有所帮助: [color=var(--color-accent-fg)]TensorRT-For-YOLO-Series


如何运行程序:
只需使用以下命令运行文件main.py
python main.py
几秒钟后,程序将开始运行。您可以在控制台中看到。Main Start
一旦你按住鼠标右键或鼠标左键(无论你按住瞄准还是开始射击),程序将开始瞄准敌人。


如何更改设置:
您可以更改文件中的设置。args.py


一些重要的设置!!!:
模型
默认模型适用于 Apex。但是,您可以使用 训练自己的模型,并使用此设置切换模型。train.py
“模型”目录中有几个模型,您可以选择其中之一。
这些模型用于 tensorRT,它比模型快约 4 倍,但精度相同。.trt.pt
模型速度:8n>8s>8m
模型精度:8n<8s<8m

crop_size:
此设置确定要检测的屏幕部分。太高可能会导致难以检测到小物体。




`[PWAH%`5)]WECV$VQE)XL9.png





游客,如果您要查看本帖隐藏内容请回复



回复

使用道具 举报

 楼主| 发表于 2023-5-9 03:18 | 显示全部楼层

使用指南

本帖最后由 NingNingQwQ 于 2023-5-9 03:27 编辑


使用指南,需要的话自己翻译就好了。

## Performance Benchmarks
<details>
<summary>Test setting:</summary>
   
    - OS: Windows 11 Pro 22H2
    - CPU: AMD Ryzen 3900X
    - GPU: NVIDIA GeForce RTX 2080 8G
    - RAM: 32G @ 3600MHz
    - Monitor resolution: 2560 x 1440
    - In-game resolution: 2560 x 1440
    - In-game FPS: Locked @ 60fps
   
</details>

| Model        | Size<br><sup>(pixels) | Enemy prediction<sup>val<br>mAP 50-95 | Teammate prediction<sup>val<br>mAP 50-95 | Speed<br><sup>.trt fp16<br>(fps) | Speed<br><sup>.trt int8<br>(fps) | IFF performence |
| -------------| --------------------- | -------------------- | -------------------- | ------------------------------ | ------------------------------- | ------------------ |
| Apex_8n      | 640                   | 54.5                 | 71.3                 | 58.88                          | 61.23                           | Poor                |
| Apex_8s      | 640                   | 66.9                 | 79.2                 | 27.10                          | 33.43                           | Acceptable               |
| Apex_8n_pruned| 640                  | 44.1                 | 55.9                 | 72.22                          | 74.04                           | Poor               |
| Apex_8s_pruned| 640                  | 52.9                 | 64.9                 | 30.54                          | 31.82                           | Poor               |


## Advantages and Todos
Advantages:
* [x] Fast screencapturing with dxshot
* [x] Not Logitech Macro/GHub dependent
* [x] Customizable trigger keys
* [x] PID capable
* [x] IFF(Identification friend or foe) capable (Works 50/50)
* [x] fp16 precision

Todos:
* [x] int8 precision (No significant improvement as for now)
* [x] Pruning (Sacrificies accuracy way too much)
* [ ] Increase accuracy of IFF
* [ ] Increase accuracy under: ADS, partial body exposure, gunfire blockage, smoke...

## 1. Set up the environment

### 1.1. Environment set up under Linux
- Install `Conda` (if not already installed)

    In your terminal window, run:`bash Miniconda3-latest-Linux-x86_64.sh` to install `Miniconda` (suggested) or run:`bash Anaconda-latest-Linux-x86_64.sh` to install `Anaconda`.
   
- Setup a new environment
   
    In your terminal window, run:
    ```shell
    conda create -n yolov8 python=3.10 # create environment 'yolov8' with python 3.10 installed
    conda activate yolov8 # activate environment 'yolov8'
    ```
   
- Install `CUDA` and `PyTorch`.
   
   ~~if you have a cuda capable gpu, you can running the following extra command~~

  Running inferrence on CPU is suboptimal and no longer suggested by this project. Please use `CUDA` capable GPU and run the following command to install `CUDA`, `cuDNN` and `PyTorch`:
   ``` shell
   pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116`
   ```
- Install `TensorRT`.

  Add the following command
   ```
   pip install --upgrade setuptools pip --user
   pip install nvidia-pyindex
   pip install --upgrade nvidia-tensorrt
   pip install pycuda
   ```
- Install python requirement.
   ``` shell
   pip install -r requirement.txt
   ```
   

### 1.2. Environment set up in Windows10 & Windows11

The following method has being tested and successed under `Windows 10 Pro Version 21H2/22H2`, `Windows11 Pro Version 22H2` and `Windows11 Pro Insider View Build 25346`. Technically, it works under all latest `Windows OS` builds.
- Version-align

    |  CUDA   |  cuDNN   | TensorRT | PyTorch  |
    | :-----: | :------: | :------: | :------: |
    | 11.7.0  | 8.5.0    |  8.5.2.2 | 2.0.0    |
    | 11.8.0  | 8.6.0    |  8.5.3.1 | 2.0.0    |
    | ...    | ...   |  ... | ...    |
   
    We will be using the first row as our package manifests.
   
- Install `CUDA`. (One can also follow the official instruction:[`CUDA official website`](https://docs.nvidia.com/cuda/cud ... -windows/index.html)).
    ```shell
    conda install cuda -c nvidia/label/cuda-11.7.0 # install CUDA 11.7.0
    ```

- Install `cuDNN`.
    - Register for the [`NVIDIA developer program`](https://developer.nvidia.com/login).
    - Go to the cuDNN download site:[`cuDNN download archive`](https://developer.nvidia.com/rdp/cudnn-archive).
    - Click `Download cuDNN v8.5.0 (August 8th, 2022), for CUDA 11.x`.
    - Download `Local Installer for Windows (Zip)`.
    - Unzip `cudnn-windows-x86_64-8.5.0.96_cuda11-archive.zip`.
    - Copy all three folders (`bin`,`include`,`lib`) and paste them to the `CUDA` installation directory `C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7`. (NOTE `bin`,`include`,`lib` folders are already exist in the CUDA folder.).

- Install `PyTorch`.
    ```shell
    conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
    ```
- Install `TensorRT`.
    Follow the [Nvidia instruction of installation](https://docs.nvidia.com/deeplear ... html#installing-zip).
    - Go to the [TensorRT download site](https://developer.nvidia.com/nvidia-tensorrt-8x-download).
    - Download `TensorRT 8.5 GA for Windows 10 and CUDA 11.0, 11.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7 and 11.8 ZIP Package`.
    - Unzip the folder `TensorRT-8.5.2.2` from `TensorRT-8.5.2.2.Windows10.x86_64.cuda-11.8.cudnn8.6.zip`.
    - Add the `<your install path>\TensorRT-8.5.2.2\lib` into PATH environment variable.
    - Go to the folder `<your install path>\TensorRT-8.5.2.2\python`
    - In command window, input
        ```shell
        conda activate yolov8 # activate dedicated environment
        pip install tensorrt-8.5.2.2-cp310-none-win_amd64.whl # install tensorrt package to python
        ```
- Install python requirement.
   ``` shell
   pip install -r requirement.txt
   ```

<details>
<summary> Verify installation and check versions.</summary>
   
- Verify installation of `CUDA`, `cuDNN`, `PyTorch` and `TensorRT`.  
   
    - Verify `CUDA`.
        ```shell
        nvcc -V
        ```
        If installment successed, you should see prompts like:
        ```shell
        nvcc: NVIDIA (R) Cuda compiler driver
        Copyright (c) 2005-2022 NVIDIA Corporation
        Built on Tue_May__3_19:00:59_Pacific_Daylight_Time_2022
        Cuda compilation tools, release 11.7, V11.7.64
        Build cuda_11.7.r11.7/compiler.31294372_0
        ```
     - Verify `cuDNN`.
     
        ```shell
        python
        import torch
        print(torch.backends.cudnn.version())
        ```
        
     - Verify `PyTorch`.
      
        ```shell
        python
        import torch
        print(torch.__version__)
        ```
   
    - Verify `TensorRT`.
      
        ```shell
        pip show tensorrt
        ```
        If installment successed, you should see prompts like:
        ```shell
        Name: tensorrt
        Version: 8.5.2.2
        Summary: A high performance deep learning inference library
        Home-page: https://developer.nvidia.com/tensorrt
        Author: NVIDIA Corporation
        ```   
   
   
   
</details>



## 2. Build your weight
### 2.1. PyTorch `.pt` weight
You have several options here to realize your `.pt` weight:
- (1) Use the provided weight `apex_v8n.pt`.
     
     This is a weight based on `yolov8n.pt`, trained with 7W screenshots and labeled 'Enemy', 'Teammate'. Due to the nature of this project, the provided weight is poorly trained to prevent abuse and cheating. However, it can already track characters well and demonstrate some level of IFF capability.  
     
- (2) Use the provided weight `apex_v8n.pt` as a pretrained weight and train your own weight with your own dataset.
     
     Please follow the [official instruction](https://docs.ultralytics.com/usage/cli/) of `Ultralytics` to train your own weight.
     
     Note that the dataset is required to use `YOLO` annotation format, please reform your dataset into the following structure:
        
    ```shell
    dataset/apex/
    ├── train
    |   ├── images
    │   |   ├── 000000000001.jpg
    │   |   ├── 000000580008.jpg
    │   |   |   ...
    |   ├── lables   
    │   |   ├── 000000000001.txt
    │   |   ├── 000000580008.txt
    │   |   |   ...
    ├── valid
    |   ├── images
    │   |   ├── 000000000113.jpg
    │   |   ├── 000000000567.jpg
    |   ├── lables   
    │   |   ├── 000000000113.txt
    │   |   ├── 000000000567.txt
    │   |   |   ...   
    ```
   
- (3) Train your own weight with official pretrained `yolov8` weights.
   
    If the provided weight which is based on `yolov8n.pt` can not meet your expectation. You can also explore the options of other pretrained weights provided by `yolov8`.
   
    - Model speed: `8n>8s>8m`
   
    - Model accuracy: `8n<8s<8m`
   
    Please follow the [official instruction](https://docs.ultralytics.com/usage/cli/) of `Ultralytics` to train your own weight.
   
### 2.2. ONNX `.onnx` weight (skip if only fp16 precision is desired)

You have several options here to to convert your `.pt` weight to a `.onnx` weight.

- (1) Use yolov8 built in function `YOLO export`:

    ```shell
    yolo export model=<your weight path>/best.pt format=onnx
    ```
    Note this built-in method is identical to the python code provided in [TensorRT-For-YOLO-Series](https://github.com/Linaom1214/TensorRT-For-YOLO-Series)
   
- (2) Use Paddleslim ACT (In Linux):
   
   

### 2.3. TensorRT `.trt` or `.engine` weight

Use any of the following methods to generate TensorRT engine:

- (1) Use yolov8 built-in function `YOLO export` to export `.engine` weight directly from `.pt` weight.
   
    ```shell
    # out put fp32 precision (default)
    yolo export model=<your weight path>/best.pt format=engine
   
    # out put fp16 precision (recommanded)
    yolo export model=<your weight path>/best.pt format=engine fp16=True
    ```
- (2) Use the third-party method [TensorRT-For-YOLO-Series](https://github.com/Linaom1214/TensorRT-For-YOLO-Series) to export `.trt` weight from previous generated `.onnx` weight.

    ```shell
    # out put fp32 precision
    python export.py -o <your weight path>/best.onnx -e apex_fp32.trt -p fp32 --end2end --v8
   
    # out put fp16 precision (default, recommanded)
    python export.py -o <your weight path>/best.onnx -e apex_fp16.trt --end2end --v8
   
    # out put int8 precision (for extreme performance)
    python export.py -o <your weight path>/best.onnx -e apex_int8.trt -p int8 --calib_input <your data path>/train/images --calib_num_images 500 --end2end --v8
    ```
   
## 3. Run the program
Replace the model and change settings in the `args_.py` file (See Section 4.)

Run the `main.py` file with the following command
```shell        
conda activate v8trt # activate dedeicated env
python main.py # start aim assist
```
After a few seconds, the program will start fucntioning. You should see the follwing prompts in the console:
```shell
listener start
Main start
Screenshot fps:  311.25682541048934
fps:  61.09998811302416
interval:  0.016366615295410156
```

Explaination of keys:
- `Shift`: Holding shift triggers aim assist. By default, only `holding shift` can trigger the aim assist.
- `Left`: Unlock `left mouse button`. Once `left` key is clicked, you should hear a beep and now holding `left mouse button` can also trigger aim assist
- `Right`: Unlock `right mouse button`. Once `right` key is clicked, you should hear a beep and now holding `right mouse button` can also trigger aim assist
- `End`: Cilck `End` for continious aiming. Auto aiming is always on and another click to turn off.
- `Left mouse button`: Optional trigger
- `Right mouse button`: Optional trigger
- `Home`: Stop listening and exit program

## 4. Change settings
You can change following settings in the `args_.py` file.
- `--model`: The weight to be used by this project. Please replace this with your own `.trt` or `.engine` weight.
- `--classes`: classes to be detected, can be expanded but need to be an array. For example, 0 represents 'Teammate', 1 represents 'Enemy'. Then the input should be [1].
- `--conf`: Confidence level for inference. Adjust it based on your model accuracy.
- `--crop_size`: The portion to detect from the screen. Adjust it based on your monitor resolution. For example: `1/3` for 1440P, or `1/2` for 1080P.
- `--pid`: Use PID controller to smooth aiming and prevent overdrifting. Leave it by default is recommanded.
- `--Kp`,`--Ki`,`--Kd`: PID components that need to be carefully calibrated. `--Kp=0.5`, `--Ki=0.1`, `--Kd=0.1` is recommanded as starting point.
You can also modify the `MyListener.py` file.
- Function `def listen_key(key)` and def `keys_released(key)`: Change `keyboard.Key.home`, `keyboard.Key.end`, `keyboard.Key.shift`, `keyboard.Key.left` or `keyboard.Key.right` to whatever keys you like to customize the key settings.
回复 支持 反对

使用道具 举报

发表于 2023-7-5 13:47 | 显示全部楼层

## 性能基准
<details>
<summary>测试设置:</summary>
   
    - 操作系统:Windows 11 Pro 22H2
    - CPU:AMD Ryzen 3900X
    - GPU:NVIDIA GeForce RTX 2080 8G
    - 内存:32G @ 3600MHz
    - 监视器分辨率:2560 x 1440
    - 游戏内分辨率:2560 x 1440
    - 游戏内FPS:锁定@60fps
   
</details>

| 模型          | 尺寸<br><sup>(像素) | 敌人预测<sup>val<br>mAP 50-95 | 队友预测<sup>val<br>mAP 50-95 | 速度<br><sup>.trt fp16<br>(fps) | 速度<br><sup>.trt int8<br>(fps) | IFF性能 |
| ------------- | --------------------- | -------------------- | -------------------- | ------------------------------ | ------------------------------- | ------------------ |
| Apex_8n      | 640                   | 54.5                 | 71.3                 | 58.88                          | 61.23                           | 差                |
| Apex_8s      | 640                   | 66.9                 | 79.2                 | 27.10                          | 33.43                           | 可接受               |
| Apex_8n_pruned| 640                  | 44.1                 | 55.9                 | 72.22                          | 74.04                           | 差               |
| Apex_8s_pruned| 640                  | 52.9                 | 64.9                 | 30.54                          | 31.82                           | 差               |


## 优点和待办事项
优点:
* [x] 使用dxshot进行快速屏幕捕获
* [x] 不依赖Logitech Macro/GHub
* [x] 可自定义触发键
* [x] 支持PID
* [x] 支持IFF(识别敌我)(效果五五开)
* [x] 支持fp16精度

待办事项:
* [x] 支持int8精度(目前改进不显著)
* [x] 支持剪枝(牺牲了太多的准确性)
* [ ] 提高IFF的准确度
* [ ] 在以下情况下提高准确度:瞄准,身体部分暴露,枪火阻挡,烟雾...

## 1. 设置环境

### 1.1. 在Linux下设置环境
- 安装 Conda (如果还未安装)

    在终端窗口中,运行: bash Miniconda3-latest-Linux-x86_64.sh 来安装 Miniconda (推荐)或运行: bash Anaconda-latest-Linux-x86_64.sh 来安装 Anaconda 。
   
- 设置新环境
   
    在终端窗口中,运行:
shell
    conda create -n yolov8 python=3.10 # 创建一个名为'yolov8'的环境,并安装python 3.10
    conda activate yolov8 # 激活'yolov8'环境
- 安装 CUDA 和 PyTorch 。
   
   ~~如果你有一个支持cuda的gpu,你可以运行以下额外的命令~~

  由于在CPU上运行推断效率低下,本项目不再建议使用。请使用支持 CUDA 的GPU,并运行以下命令来安装 CUDA 、 cuDNN 和 PyTorch :
shell
   pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1 --extra-index-url https://download.pytorch.org/whl/cu116`
- 安装 TensorRT 。

  添加以下命令
pip install --upgrade setuptools pip --user
   pip install nvidia-pyindex
   pip install --upgrade nvidia-tensorrt
   pip install pycuda
- 安装python需求。
shell
   pip install -r requirement.txt
### 1.2. 在Windows10和Windows11中设置环境

以下方法已在 Windows 10 Pro Version 21H2/22H2 、 Windows11 Pro Version 22H2 和 Windows11 Pro Insider View Build 25346 下测试并成功。理论上,它适用于所有最新的 Windows OS 版本。
- 版本对齐

    |  CUDA   |  cuDNN   | TensorRT | PyTorch  |
    | :-----: | :------: | :------: | :------: |
    | 11.7.0  | 8.5.0    |  8.5.2.2 | 2.0.0    |
    | 11.8.0  | 8.6.0    |  8.5.3.1 | 2.0.0    |
    | ...    | ...   |  ... | ...    |
   
    我们将使用第一行作为我们的包清单。
   
- 安装 CUDA 。 (也可以按照官方指导进行安装:[ CUDA官方网站 ](https://docs.nvidia.com/cuda/cud ... -windows/index.html))。
shell
    conda install cuda -c nvidia/label/cuda-11.7.0 # 安装CUDA 11.7.0
- 安装 cuDNN 。
    - 注册[ NVIDIA开发者计划 ](https://developer.nvidia.com/login)。
    - 前往cuDNN下载站点:[ cuDNN下载归档 ](https://developer.nvidia.com/rdp/cudnn-archive)。
    - 点击 Download cuDNN v8.5.0 (August 8th, 2022), for CUDA 11.x 。
    - 下载 Local Installer for Windows (Zip) 。
    - 解压 cudnn-windows-x86_64-8.5.0.96_cuda11-archive.zip 。
    - 复制所有三个文件夹( bin , include , lib )并将它们粘贴到 CUDA 安装目录 C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.7 。(注意 bin , include , lib 文件夹已经存在于CUDA文件夹中。)。

- 安装 PyTorch 。
shell
    conda install pytorch torchvision torchaudio pytorch-cuda=11.7 -c pytorch -c nvidia
- 安装 TensorRT 。
    按照[Nvidia安装指导](https://docs.nvidia.com/deeplear ... html#installing-zip)进行操作。
    - 前往[TensorRT下载站点](https://developer.nvidia.com/nvidia-tensorrt-8x-download)。
    - 下载 TensorRT 8.5 GA for Windows 10 and CUDA 11.0, 11.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7 and 11.8 ZIP Package 。
    - 从 TensorRT-8.5.2.2.Windows10.x86_64.cuda-11.8.cudnn8.6.zip 中解压文件夹 TensorRT-8.5.2.2 。
    - 将 <你的安装路径>\TensorRT-8.5.2.2\lib 添加到PATH环境变量中。
    - 前往文件夹 <你的安装路径>\TensorRT-8.5.2.2\python  
    - 在命令窗口中,输入
shell
        conda activate yolov8 # 激活专用环境
        pip install tensorrt-8.5.2.2-cp310-none-win_amd64.whl # 将tensorrt包安装到python
- 安装Python依赖项。
shell
   pip install -r requirement.txt
<details>
<summary>验证安装并检查版本。</summary>
   
- 验证 CUDA , cuDNN , PyTorch 和 TensorRT 的安装。   
   
    - 验证 CUDA 。
shell
        nvcc -V
如果安装成功,您应该看到类似以下的提示:
shell
        nvcc: NVIDIA (R) Cuda compiler driver
        版权所有 (c) 2005-2022 NVIDIA Corporation
        构建于 Tue_May__3_19:00:59_Pacific_Daylight_Time_2022
        Cuda 编译工具,版本 11.7,V11.7.64
        构建 cuda_11.7.r11.7/compiler.31294372_0
- 验证 cuDNN 。
shell
        python
        import torch
        print(torch.backends.cudnn.version())
- 验证 PyTorch 。
shell
        python
        import torch
        print(torch.__version__)
- 验证 TensorRT 。
shell
        pip show tensorrt
如果安装成功,您应该看到类似以下的提示:
shell
        Name: tensorrt
        Version: 8.5.2.2
        Summary: 高性能深度学习推理库
        Home-page: https://developer.nvidia.com/tensorrt
        Author: NVIDIA Corporation
</details>


## 2. 构建您的权重
### 2.1. PyTorch  .pt  权重
您有几个选项来实现您的  .pt  权重:
- (1) 使用提供的权重  apex_v8n.pt 。
      
     这是基于  yolov8n.pt  的权重,使用了 7W 张屏幕截图进行训练,并标记了 'Enemy' 和 'Teammate'。由于项目的性质,提供的权重训练不足,以防止滥用和作弊。然而,它已经可以很好地追踪角色,并展示了一定程度的 IFF 能力。
      
- (2) 使用提供的权重  apex_v8n.pt  作为预训练权重,并使用自己的数据集训练自己的权重。
      
     请按照  Ultralytics  的[官方说明](https://docs.ultralytics.com/usage/cli/)来训练您自己的权重。
      
     请注意,数据集需要使用  YOLO  注释格式,请将您的数据集重新组织成以下结构:
shell
    dataset/apex/
    ├── train
    |   ├── images
    │   |   ├── 000000000001.jpg
    │   |   ├── 000000580008.jpg
    │   |   |   ...
    |   ├── lables   
    │   |   ├── 000000000001.txt
    │   |   ├── 000000580008.txt
    │   |   |   ...
    ├── valid
    |   ├── images
    │   |   ├── 000000000113.jpg
    │   |   ├── 000000000567.jpg
    |   ├── lables   
    │   |   ├── 000000000113.txt
    │   |   ├── 000000000567.txt
    │   |   |   ...   
      
- (3) 使用官方预训练的  yolov8  权重来训练自己的权重。
   
    如果基于  yolov8n.pt  的提供的权重无法满足您的期望,您还可以探索  yolov8  提供的其他预训练权重的选项。
   
    - 模型速度: 8n>8s>8m  
   
    - 模型准确性: 8n<8s<8m  
   
    请按照  Ultralytics  的[官方说明](https://docs.ultralytics.com/usage/cli/)来训练您自己的权重。
### 2.2. ONNX  .onnx 权重(如果只需要fp16精度,则跳过)

您有几个选项可以将 .pt 权重转换为 .onnx 权重。

- (1)使用yolov8内置函数 YOLO export :
shell
    yolo export model=<your weight path>/best.pt format=onnx
请注意,此内置方法与[TensorRT-For-YOLO-Series](https://github.com/Linaom1214/TensorRT-For-YOLO-Series)中提供的Python代码相同。
   
- (2)使用Paddleslim ACT(在Linux中):
   
   

### 2.3. TensorRT  .trt 或 .engine 权重

使用以下任一方法生成TensorRT引擎:

- (1)使用yolov8内置函数 YOLO export 直接从 .pt 权重导出 .engine 权重。
shell
    # 输出fp32精度(默认)
    yolo export model=<your weight path>/best.pt format=engine
   
    # 输出fp16精度(推荐)
    yolo export model=<your weight path>/best.pt format=engine fp16=True
- (2)使用第三方方法[TensorRT-For-YOLO-Series](https://github.com/Linaom1214/TensorRT-For-YOLO-Series)从先前生成的 .onnx 权重导出 .trt 权重。
shell
    # 输出fp32精度
    python export.py -o <your weight path>/best.onnx -e apex_fp32.trt -p fp32 --end2end --v8
   
    # 输出fp16精度(默认,推荐)
    python export.py -o <your weight path>/best.onnx -e apex_fp16.trt --end2end --v8
   
    # 输出int8精度(用于极端性能)
    python export.py -o <your weight path>/best.onnx -e apex_int8.trt -p int8 --calib_input <your data path>/train/images --calib_num_images 500 --end2end --v8
## 3. 运行程序
替换模型并在 args_.py 文件中更改设置(参见第4节)。

使用以下命令运行 main.py 文件
shell        
conda activate v8trt # 激活专用环境
python main.py # 启动瞄准辅助
几秒钟后,程序将开始运行。您应该在控制台中看到以下提示:
shell
listener start
Main start
Screenshot fps:  311.25682541048934
fps:  61.09998811302416
interval:  0.016366615295410156
按键说明:
-  Shift :按住Shift键触发瞄准辅助。默认情况下,只有 按住Shift键 才能触发瞄准辅助。
-  Left :解锁“左键”。单击 左 键后,您应该听到一声哔声,现在按住 左键 也可以触发瞄准辅助。
-  Right :解锁“右键”。单击 右 键后,您应该听到一声哔声,现在按住 右键 也可以触发瞄准辅助。
-  End :单击 End 进行连续瞄准。自动瞄准始终开启,再次单击可关闭。
-  左键 :可选触发器
-  右键 :可选触发器
-  Home :停止监听并退出程序

## 4. 更改设置
您可以在 args_.py 文件中更改以下设置。
-  --model :此项目要使用的权重。请将其替换为您自己的 .trt 或 .engine 权重。
-  --classes :要检测的类别,可以扩展但需要是一个数组。例如,0表示“队友”,1表示“敌人”。然后输入应为[1]。
-  --conf :推理的置信度水平。根据模型的准确性进行调整。
-  --crop_size :从屏幕中检测的部分。根据您的显示器分辨率进行调整。例如:1440P的情况下使用 1/3 ,或者1080P的情况下使用 1/2 。
-  --pid :使用PID控制器平滑瞄准并防止过度漂移。建议保持默认设置。
-  --Kp , --Ki , --Kd :需要仔细校准的PID组件。推荐使用 --Kp=0.5 , --Ki=0.1 , --Kd=0.1 作为起点。
您还可以修改 MyListener.py 文件。
- 函数 def listen_key(key) 和 def keys_released(key) :将 keyboard.Key.home , keyboard.Key.end , keyboard.Key.shift , keyboard.Key.left 或 keyboard.Key.right 更改为您喜欢的任意键,以自定义键设置。
回复 支持 1 反对 0

使用道具 举报

发表于 2023-4-28 15:22 | 显示全部楼层
66666666666666666
回复 支持 0 反对 1

使用道具 举报

发表于 2023-4-28 14:41 | 显示全部楼层
666666666
回复

使用道具 举报

发表于 2023-4-28 14:43 | 显示全部楼层
666666666
回复

使用道具 举报

发表于 2023-4-28 15:03 | 显示全部楼层
666666
回复

使用道具 举报

发表于 2023-4-28 15:41 | 显示全部楼层
666666666
回复

使用道具 举报

发表于 2023-4-28 15:49 | 显示全部楼层
现在AI需要简单化
回复 支持 反对

使用道具 举报

发表于 2023-4-28 15:50 | 显示全部楼层
............
回复

使用道具 举报

发表于 2023-4-28 15:52 | 显示全部楼层
666666666666
回复 支持 反对

使用道具 举报

发表于 2023-4-28 15:53 | 显示全部楼层
6666666666666666666
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|96辅助游戏论坛

GMT+8, 2024-9-8 11:19 , Processed in 0.077735 second(s), 25 queries .

Powered by Discuz! X3.4

© 2016-2023 Comsenz Inc.

快速回复 返回顶部 返回列表