├── .gitattributes
├── .gitignore
├── .idea
├── .gitignore
├── csgobot.iml
├── inspectionProfiles
│ ├── Project_Default.xml
│ └── profiles_settings.xml
├── misc.xml
├── modules.xml
└── vcs.xml
├── LICENSE
├── README.md
├── config.toml
├── configurator.py
├── detector_yolov7.py
├── detector_yolov8.py
├── main.py
├── requirements.txt
├── semiauto_dataset_collector.py
├── tools
├── analyze.py
├── classes.txt
├── clear.py
├── fix.py
├── readme.txt
├── rttest.py
├── tftest.py
└── uniform.py
├── uutils
├── __init__.py
├── benchmark.py
├── controls
│ ├── __init__.py
│ ├── keyboard
│ │ └── __init__.py
│ └── mouse
│ │ ├── __init__.py
│ │ ├── pyautogui.py
│ │ ├── pydirectinput.py
│ │ ├── pynput.py
│ │ └── win32.py
├── cv2.py
├── fov_mouse.py
├── fps.py
├── grabbers
│ ├── __init__.py
│ ├── d3dshot.py
│ ├── dxcam.py
│ ├── dxcamcapture.py
│ ├── mss.py
│ ├── obs_vc.py
│ ├── screengear.py
│ └── win32.py
├── nms.py
├── streaming
│ ├── __init__.py
│ └── client.py
├── time.py
├── torch_utils.py
├── win32.py
└── windmouse.py
├── yolov7
├── .gitignore
├── LICENSE.md
├── README.md
├── cfg
│ ├── baseline
│ │ ├── r50-csp.yaml
│ │ ├── x50-csp.yaml
│ │ ├── yolor-csp-x.yaml
│ │ ├── yolor-csp.yaml
│ │ ├── yolor-d6.yaml
│ │ ├── yolor-e6.yaml
│ │ ├── yolor-p6.yaml
│ │ ├── yolor-w6.yaml
│ │ ├── yolov3-spp.yaml
│ │ ├── yolov3.yaml
│ │ └── yolov4-csp.yaml
│ ├── deploy
│ │ ├── yolov7-d6.yaml
│ │ ├── yolov7-e6.yaml
│ │ ├── yolov7-e6e.yaml
│ │ ├── yolov7-tiny-silu.yaml
│ │ ├── yolov7-tiny.yaml
│ │ ├── yolov7-w6.yaml
│ │ ├── yolov7.yaml
│ │ └── yolov7x.yaml
│ └── training
│ │ ├── yolov7-d6.yaml
│ │ ├── yolov7-e6.yaml
│ │ ├── yolov7-e6e.yaml
│ │ ├── yolov7-tiny.yaml
│ │ ├── yolov7-w6.yaml
│ │ ├── yolov7.yaml
│ │ └── yolov7x.yaml
├── deploy
│ └── triton-inference-server
│ │ ├── README.md
│ │ ├── boundingbox.py
│ │ ├── client.py
│ │ ├── labels.py
│ │ ├── processing.py
│ │ └── render.py
├── detect.py
├── export.py
├── hubconf.py
├── models
│ ├── __init__.py
│ ├── common.py
│ ├── experimental.py
│ └── yolo.py
├── paper
│ └── yolov7.pdf
├── requirements.txt
├── test.py
├── tools
│ ├── YOLOv7-Dynamic-Batch-ONNXRUNTIME.ipynb
│ ├── YOLOv7-Dynamic-Batch-TENSORRT.ipynb
│ ├── YOLOv7CoreML.ipynb
│ ├── YOLOv7onnx.ipynb
│ ├── YOLOv7trt.ipynb
│ ├── compare_YOLOv7_vs_YOLOv5m6.ipynb
│ ├── compare_YOLOv7_vs_YOLOv5m6_half.ipynb
│ ├── compare_YOLOv7_vs_YOLOv5s6.ipynb
│ ├── compare_YOLOv7e6_vs_YOLOv5x6.ipynb
│ ├── compare_YOLOv7e6_vs_YOLOv5x6_half.ipynb
│ ├── instance.ipynb
│ ├── keypoint.ipynb
│ ├── reparameterization.ipynb
│ └── visualization.ipynb
├── train.py
├── train_aux.py
└── utils
│ ├── __init__.py
│ ├── activations.py
│ ├── add_nms.py
│ ├── autoanchor.py
│ ├── aws
│ ├── __init__.py
│ ├── mime.sh
│ ├── resume.py
│ └── userdata.sh
│ ├── datasets.py
│ ├── general.py
│ ├── google_app_engine
│ ├── Dockerfile
│ ├── additional_requirements.txt
│ └── app.yaml
│ ├── google_utils.py
│ ├── loss.py
│ ├── metrics.py
│ ├── plots.py
│ ├── torch_utils.py
│ └── wandb_logging
│ ├── __init__.py
│ ├── log_dataset.py
│ └── wandb_utils.py
└── yolov8
├── .gitignore
├── YOLOv8
├── yolov8m
│ └── args.yaml
└── yolov8s
│ └── args.yaml
├── cs2.yaml
├── cs2_cfg.yaml
├── cs2_yolov8m_640_augmented_v2.pt
├── cs2_yolov8m_640_augmented_v3.pt
├── cs2_yolov8m_640_augmented_v4.pt
├── cs2_yolov8m_640_clean_base.pt
├── cs2_yolov8m_640_clean_base_augmented.pt
├── cs2_yolov8s_640.pt
├── datasets
├── .gitignore
├── Where to get dataset archive.txt
└── prepare.py
├── train.py
├── yolov8m.pt
├── yolov8n.pt
├── yolov8s.pt
└── yolov8s_csgoV1_640.pt
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pt filter=lfs diff=lfs merge=lfs -text
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Created by .ignore support plugin (hsz.mobi)
2 | ### Python template
3 | # Byte-compiled / optimized / DLL files
4 | __pycache__/
5 | *.py[cod]
6 | *$py.class
7 |
8 | # C extensions
9 | *.so
10 |
11 | # Distribution / packaging
12 | .Python
13 | env/
14 | build/
15 | develop-eggs/
16 | dist/
17 | downloads/
18 | eggs/
19 | .eggs/
20 | lib/
21 | lib64/
22 | parts/
23 | sdist/
24 | var/
25 | *.egg-info/
26 | .installed.cfg
27 | *.egg
28 |
29 | # PyInstaller
30 | # Usually these files are written by a python script from a template
31 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
32 | *.manifest
33 | *.spec
34 |
35 | # Installer logs
36 | pip-log.txt
37 | pip-delete-this-directory.txt
38 |
39 | # Unit test / coverage reports
40 | htmlcov/
41 | .tox/
42 | .coverage
43 | .coverage.*
44 | .cache
45 | nosetests.xml
46 | coverage.xml
47 | *,cover
48 | .hypothesis/
49 |
50 | # Translations
51 | *.mo
52 | *.pot
53 |
54 | # Django stuff:
55 | *.log
56 | local_settings.py
57 |
58 | # Flask stuff:
59 | instance/
60 | .webassets-cache
61 |
62 | # Scrapy stuff:
63 | .scrapy
64 |
65 | # Sphinx documentation
66 | docs/_build/
67 |
68 | # PyBuilder
69 | target/
70 |
71 | # IPython Notebook
72 | .ipynb_checkpoints
73 |
74 | # pyenv
75 | .python-version
76 |
77 | # celery beat schedule file
78 | celerybeat-schedule
79 |
80 | # dotenv
81 | .env
82 |
83 | # virtualenv
84 | venv/
85 | ENV/
86 |
87 | # Spyder project settings
88 | .spyderproject
89 |
90 | # Rope project settings
91 | .ropeproject
92 | ### VirtualEnv template
93 | # Virtualenv
94 | # http://iamzed.com/2009/05/07/a-primer-on-virtualenv/
95 | [Bb]in
96 | [Ii]nclude
97 | [Ll]ib
98 | [Ll]ib64
99 | [Ll]ocal
100 | [Ss]cripts
101 | pyvenv.cfg
102 | .venv
103 | pip-selfcheck.json
104 |
105 | ### JetBrains template
106 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
107 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
108 |
109 | # User-specific stuff
110 | .idea/**/workspace.xml
111 | .idea/**/tasks.xml
112 | .idea/**/usage.statistics.xml
113 | .idea/**/dictionaries
114 | .idea/**/shelf
115 |
116 | # AWS User-specific
117 | .idea/**/aws.xml
118 |
119 | # Generated files
120 | .idea/**/contentModel.xml
121 |
122 | # Sensitive or high-churn files
123 | .idea/**/dataSources/
124 | .idea/**/dataSources.ids
125 | .idea/**/dataSources.local.xml
126 | .idea/**/sqlDataSources.xml
127 | .idea/**/dynamic.xml
128 | .idea/**/uiDesigner.xml
129 | .idea/**/dbnavigator.xml
130 |
131 | # Gradle
132 | .idea/**/gradle.xml
133 | .idea/**/libraries
134 |
135 | # Gradle and Maven with auto-import
136 | # When using Gradle or Maven with auto-import, you should exclude module files,
137 | # since they will be recreated, and may cause churn. Uncomment if using
138 | # auto-import.
139 | # .idea/artifacts
140 | # .idea/compiler.xml
141 | # .idea/jarRepositories.xml
142 | # .idea/modules.xml
143 | # .idea/*.iml
144 | # .idea/modules
145 | # *.iml
146 | # *.ipr
147 |
148 | # CMake
149 | cmake-build-*/
150 |
151 | # Mongo Explorer plugin
152 | .idea/**/mongoSettings.xml
153 |
154 | # File-based project format
155 | *.iws
156 |
157 | # IntelliJ
158 | out/
159 |
160 | # mpeltonen/sbt-idea plugin
161 | .idea_modules/
162 |
163 | # JIRA plugin
164 | atlassian-ide-plugin.xml
165 |
166 | # Cursive Clojure plugin
167 | .idea/replstate.xml
168 |
169 | # SonarLint plugin
170 | .idea/sonarlint/
171 |
172 | # Crashlytics plugin (for Android Studio and IntelliJ)
173 | com_crashlytics_export_strings.xml
174 | crashlytics.properties
175 | crashlytics-build.properties
176 | fabric.properties
177 |
178 | # Editor-based Rest Client
179 | .idea/httpRequests
180 |
181 | # Android studio 3.1+ serialized cache file
182 | .idea/caches/build_file_checksums.ser
183 |
184 | # idea folder, uncomment if you don't need it
185 | # .idea
186 |
187 | # custom
188 | _giveaway
189 | _old
190 | cs
191 | data
192 |
--------------------------------------------------------------------------------
/.idea/.gitignore:
--------------------------------------------------------------------------------
1 | # Default ignored files
2 | /shelf/
3 | /workspace.xml
4 |
--------------------------------------------------------------------------------
/.idea/csgobot.iml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/Project_Default.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/.idea/inspectionProfiles/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/.idea/misc.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/.idea/modules.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/.idea/vcs.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## Source code of the CSGO neural network.
2 | All the code is provided "as is."
3 | Detectors are divided into classes and subclasses.
4 | The dataset is separate and available for download to Boosty subscribers: https://boosty.to/howdyho
5 |
6 | Other than that:
7 | For now, you'll have to figure it out on your own — there’s no documentation yet.
8 |
9 | The archive contains various scripts for auto-aiming and detecting.
10 |
11 | It also includes different generations of models for the Yolov7 and Yolov8 neural networks (including those for semi-automatic generation).
12 |
--------------------------------------------------------------------------------
/config.toml:
--------------------------------------------------------------------------------
1 | [main]
2 | detector = "yolov8" # main detector. Respective config section must be present
3 |
4 | [grabber]
5 | # window_title = "Counter-Strike: Global Offensive - Direct3D 9" # capture windows pos & size by window rect
6 | window_title = "Counter-Strike 2"
7 |
8 | obs_vc_device_index = -1 # -1 to ignore
9 | obs_vc_device_name = "OBS Virtual Camera"
10 |
11 | # or set custom caption coords
12 | left = 0
13 | top = 0
14 | width = 0 # 1920
15 | height = 0 # 1080
16 |
17 | [yolov8]
18 | # weights = "./yolov8/best.pt"
19 | # weights = "./yolov8/cs2_yolov8m_640_clean_base.pt"
20 | # weights = "./yolov8/yolov8s_csgoV1_640.pt"
21 | weights = "./yolov8/cs2_yolov8m_640_augmented_v4.pt"
22 | resize_image_to_fit_multiply_of_32 = false #lowers performance. Only use if grabbed image size is not multiply of 32
23 |
24 | [yolov7]
25 | # weights = "./yolov7/yolov7-csgoV5_1024.pt"
26 | # weights = "./yolov7/yolov7-csgoV6_640.pt"
27 | weights = "./yolov7/yolov7-csgoV6_640.pt"
28 | # inference_size = 640
29 | inference_size = 1024
30 | conf_thres = 0.1
31 | iou_thres = 0.45
32 | augment = 0
33 | device = ""
34 | resize_image_to_fit_multiply_of_32 = false #lowers performance. Only use if grabbed image size is not multiply of 32
35 |
36 | [fov_mouse]
37 | fov_h = 106.26
38 | fov_v = 73.74
39 | x360 = 16364 # 163636
40 | sensitivity = 2.1 # not used
41 |
42 | [cv2]
43 | title = "CS2 AI vision"
44 | show_window = true #lowers performance not that much, but can be turned of to get extra few inference FPS (1-2 or smth like that)
45 | paint_boxes = true #in most cases you want this to be turned on
46 | show_fps = true
47 | show_current_team = true
48 | paint_aim_dots = true
49 | convert_rgb2bgr = true #lowers performance. Should not be used
50 | resize_window = true #lowers performance. Should not be used
51 | window_width = 1280 #used only if resize_window is set to true
52 | window_height = 720 #used only if resize_window is set to true
--------------------------------------------------------------------------------
/configurator.py:
--------------------------------------------------------------------------------
1 | import tomli
2 |
3 | config = None
4 |
5 | if config is None:
6 | with open("config.toml", "rb") as f:
7 | config = tomli.load(f)
--------------------------------------------------------------------------------
/detector_yolov8.py:
--------------------------------------------------------------------------------
1 | from ultralytics import YOLO
2 | import numpy
3 | import cv2
4 | import torch
5 | import random
6 |
7 | from ultralytics.utils.ops import scale_coords, xyxy2xywh
8 |
9 | from configurator import config
10 |
11 |
12 | class Detector:
13 | # yolov7 params
14 | weights = config["yolov8"]["weights"] # model.pt path(s)
15 | names = []
16 |
17 | def __init__(self, names):
18 |
19 | # set names
20 | self.names = names
21 |
22 | # generate random colors
23 | self.colors = [[random.randint(0, 255) for _ in range(3)] for _ in self.names]
24 |
25 | # load model
26 | self.model = model = YOLO(config["yolov8"]["weights"])
27 |
28 | # set device
29 | self.device = 'cuda' if torch.cuda.is_available() else 'cpu'
30 | self.model.to(self.device)
31 |
32 |
33 | def set_colors(self, new_colors):
34 | self.colors = new_colors
35 |
36 |
37 | def get_cls_label(self, cls):
38 | return self.names[cls]
39 |
40 |
41 | def detect(self, img: numpy.ndarray, verbose = False, half = False, apply_nms = True, nms_config = {}):
42 | """
43 | Make an inference (prediction) of a given image.
44 | Image size must be multiple of 32 (ex. 640).
45 | And the channels count must be 3 (RGB).
46 | :param img: Input image, must be numpy.ndarray with shape of (samples, channels, height, width).
47 | :return: Detected bounding boxes in a dict format, where's the key is a class.
48 | """
49 |
50 | # get some img data
51 | img_height, img_width, img_channels = img.shape
52 |
53 | if img_channels > 3:
54 | return False
55 | # img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR) # leave 3 channels
56 |
57 | # reshape for PyTorch (samples, channels, height, width)
58 | # img = numpy.moveaxis(img, -1, 0)
59 |
60 | result = {}
61 | presults = self.model.predict(
62 | source = img,
63 | verbose = verbose,
64 | half = half,
65 | nms = apply_nms,
66 | conf = nms_config["conf_thres"],
67 | iou = nms_config["iou_thres"],
68 | )
69 |
70 | for presult in presults:
71 | for idx, cls in enumerate(presult.boxes.cls):
72 | result.setdefault(self.names[int(cls)], [])
73 |
74 | result[self.names[int(cls)]].append({
75 | "cls": int(cls),
76 | "conf": presult.boxes.conf[idx].item(),
77 | "xyxy": presult.boxes[idx].xyxy.cpu().numpy()[0].tolist()
78 | })
79 |
80 | return result
81 |
82 |
83 | def filter_rects(self, bbox_list: dict, e_classes: list):
84 | filtered_rects = []
85 |
86 | for i, (c, ds) in enumerate(bbox_list.items()):
87 | if c in e_classes:
88 | for d in ds:
89 | aim_box = {
90 | "tcls": c,
91 | "cls": d["cls"],
92 | "conf": d["conf"],
93 | "xyxy": d["xyxy"]
94 | }
95 | filtered_rects.append(aim_box)
96 |
97 | return filtered_rects
98 |
99 |
100 | def plot_one_box(self, x, img, color=None, label=None, line_thickness=3):
101 | # Plots one bounding box on image img
102 | tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1 # line/font thickness
103 | color = color or [random.randint(0, 255) for _ in range(3)]
104 | c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3]))
105 | cv2.rectangle(img, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA)
106 | if label:
107 | tf = max(tl - 1, 1) # font thickness
108 | t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0]
109 | c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3
110 | cv2.rectangle(img, c1, c2, color, -1, cv2.LINE_AA) # filled
111 | cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [225, 255, 255], thickness=tf, lineType=cv2.LINE_AA)
112 |
113 |
114 | def paint_boxes(self, img: numpy.ndarray, bbox_list: dict, min_conf: float) -> numpy.ndarray:
115 | """
116 | Paint predicted bounding boxes to a given image.
117 | :param img: Input image.
118 | :param bbox_list: Detected bounding boxes (expected output from detect method).
119 | :return:
120 | """
121 | for i, (c, ds) in enumerate(bbox_list.items()):
122 | for d in ds:
123 | if float(d['conf']) > min_conf:
124 | self.plot_one_box(d["xyxy"], img, label=f"{self.get_cls_label(d['cls'])} {d['conf']:.2f}", color=self.colors[int(d["cls"])], line_thickness=2)
125 |
126 | return img
127 |
128 | def paint_aim_boxes(self, img: numpy.ndarray, aims_list: list) -> numpy.ndarray:
129 | """
130 | Paint aims bounding boxes to a given image.
131 | :param img: Input image.
132 | :param aims_list: Detected aim boxes (expected output from filter_rects method).
133 | :return:
134 | """
135 | for aim in aims_list:
136 | self.plot_one_box(aim["xyxy"], img, label=f"{aim['tcls']} {aim['conf']:.2f}", color=self.colors[int(aim["cls"])], line_thickness=2)
137 |
138 | return img
139 |
--------------------------------------------------------------------------------
/requirements.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Priler/csgobot/1993ae7644527c84c7c891b8b6ebbcad2e5075f1/requirements.txt
--------------------------------------------------------------------------------
/tools/analyze.py:
--------------------------------------------------------------------------------
1 | import os
2 | from PIL import Image
3 |
4 | # vars
5 | dirs = ("./images/test/", "./images/train/")
6 | ext = ('.jpg')
7 | files = []
8 | resolutions = {}
9 |
10 | # collect files
11 | for dirname in dirs:
12 | for filename in os.listdir(dirname):
13 | if filename.endswith(ext):
14 | files.append(dirname + filename)
15 |
16 | # collect sizes
17 | for filename in files:
18 | im = Image.open(filename)
19 | w, h = im.size
20 |
21 | # TODO: add chart?
22 | if f"{w},{h}" not in resolutions.keys():
23 | resolutions[f"{w},{h}"] = 1
24 | else:
25 | resolutions[f"{w},{h}"] += 1
26 |
27 | # sort
28 | resolutions = sorted(resolutions.items(), key=lambda x: x[1])
29 |
30 | # print
31 | for res in resolutions:
32 | print(f"{res[1] / len(files) * 100:.1f}% - {res[0]}")
--------------------------------------------------------------------------------
/tools/classes.txt:
--------------------------------------------------------------------------------
1 | c
2 | ch
3 | t
4 | th
--------------------------------------------------------------------------------
/tools/clear.py:
--------------------------------------------------------------------------------
1 | import glob, os
2 |
3 | exceptions = ['classes'] # .txt files that will be excluded
4 | removed = 0
5 | os.chdir("./images/")
6 | for filename in glob.glob("*.txt"):
7 | basename = os.path.splitext(filename)[0]
8 |
9 | if basename in exceptions:
10 | continue
11 |
12 | imgfile = basename + '.png'
13 | if not os.path.isfile(imgfile):
14 | imgfile = basename + '.jpg' # try jpg
15 |
16 | with open(filename) as f:
17 | content = f.read()
18 |
19 | # remove, if file is empty or if there's no image file
20 | if not content.strip() or not os.path.isfile(imgfile):
21 | os.remove(filename)
22 |
23 | if os.path.isfile(imgfile):
24 | os.remove(imgfile)
25 |
26 | print(f"File {filename} removed ...")
27 | removed += 1
28 |
29 | print("===============================")
30 | if removed:
31 | print(f"Total files removed: {removed}")
32 | else:
33 | print("No files to be removed found.")
--------------------------------------------------------------------------------
/tools/fix.py:
--------------------------------------------------------------------------------
1 | import glob, os, sys
2 |
3 | # from => to
4 | correction_table = (
5 | (0, 1), # fix ch
6 | (1, 0), # fix c
7 | (2, 3), # fix th
8 | (3, 2) # fix t
9 |
10 | )
11 |
12 | exceptions = ['classes'] # .txt files that will be excluded
13 | fixed = 0
14 | os.chdir("./images/")
15 | for filename in glob.glob("*.txt"):
16 | rewrite = False
17 | basename = os.path.splitext(filename)[0]
18 |
19 | if basename in exceptions:
20 | continue
21 |
22 | with open(filename) as f:
23 | lines = f.read().splitlines()
24 |
25 | for lk, lv in enumerate(lines):
26 | dt_data = lv.strip().split(" ")
27 |
28 | for patch in correction_table:
29 | # patch
30 | if str(dt_data[0]) == str(patch[0]):
31 | # print(f"Patch applied: {dt_data[0]} => {patch[1]}")
32 | dt_data[0] = str(patch[1])
33 |
34 | lines[lk] = " ".join(dt_data)
35 |
36 | rewrite = True
37 | break # patch found & applied, break
38 |
39 | if rewrite:
40 | with open(filename, 'w') as f:
41 | f.write("\n".join(lines))
42 |
43 | fixed += 1
44 | print(f"File {filename} fixed ...")
45 |
46 |
47 | print("===============================")
48 | if fixed:
49 | print(f"Total files fixed: {fixed}")
50 | else:
51 | print("No files to be fixed found.")
--------------------------------------------------------------------------------
/tools/readme.txt:
--------------------------------------------------------------------------------
1 | A simple collection of some useful small python scripts.
--------------------------------------------------------------------------------
/tools/rttest.py:
--------------------------------------------------------------------------------
1 | import tensorrt
2 | print(tensorrt.__version__)
3 | assert tensorrt.Builder(tensorrt.Logger())
--------------------------------------------------------------------------------
/tools/tftest.py:
--------------------------------------------------------------------------------
1 | import tensorflow as tf
2 | print("tensorflow version", tf.__version__)
3 |
4 | x = [[3.]]
5 | y = [[4.]]
6 | print("Result: {}".format(tf.matmul(x, y)))
--------------------------------------------------------------------------------
/tools/uniform.py:
--------------------------------------------------------------------------------
1 | import os, sys
2 | from PIL import Image
3 | from lxml import etree
4 | from pyquery import PyQuery as pq
5 | from pathlib import Path
6 |
7 | # vars
8 | dirs = ("./images/test/", "./images/train/")
9 | ext = ('.jpg')
10 | files = []
11 | resolutions = {}
12 | uniform_target_resolution = 400 # height
13 |
14 | # collect files
15 | for dirname in dirs:
16 | for filename in os.listdir(dirname):
17 | if filename.endswith(ext):
18 | files.append(dirname + filename)
19 |
20 | # resize the images
21 | for filename in files:
22 | im = Image.open(filename)
23 | w, h = im.size
24 |
25 | xdiff = w / uniform_target_resolution # scale difference multiplier
26 |
27 | if w != uniform_target_resolution:
28 | # downscale/upscale
29 | new_width = int(uniform_target_resolution)
30 | new_height = int(uniform_target_resolution * h / w)
31 |
32 | im = im.resize((new_width, new_height), Image.ANTIALIAS)
33 | im.save(filename) # save resized
34 |
35 | # edit xml
36 | xmlfile = os.path.splitext(filename)[0] + '.xml'
37 | xml = pq(filename=xmlfile)
38 |
39 | xml("size > width").text(str(new_width))
40 | xml("size > height").text(str(new_height))
41 |
42 | xml("object > bndbox > xmin,\
43 | object > bndbox > xmax,\
44 | object > bndbox > ymin,\
45 | object > bndbox > ymax").map(lambda i, e: pq(e).text(str(int(float(pq(e).text()) / xdiff))))
46 |
47 | # save edited xml file
48 | Path(xmlfile).write_text(
49 | xml.outerHtml(),
50 | encoding='utf-8'
51 | )
52 |
53 | # log
54 | print(f"File {filename} processed ...")
--------------------------------------------------------------------------------
/uutils/__init__.py:
--------------------------------------------------------------------------------
1 | # init
--------------------------------------------------------------------------------
/uutils/benchmark.py:
--------------------------------------------------------------------------------
1 | import time
2 |
3 |
4 | class Benchmark:
5 | __marks = {} # {0: [result, point1, point2, ...]}
6 |
7 | def start(self, point_name=None) -> float:
8 | if point_name is None:
9 | point_name = 0
10 |
11 | self.__marks[point_name] = [0, ((time.time_ns() / 1000000) / 1000)%60, 0]
12 | # print(f"start: {self.__marks}")
13 |
14 | return self.__marks[point_name]
15 |
16 | def end(self, point_name=None) -> tuple:
17 | if point_name is None:
18 | point_name = 0
19 |
20 | # print(self.__marks)
21 | self.__marks[point_name][2] = ((time.time_ns() / 1000000) / 1000)%60
22 | self.__marks[point_name][0] = self.__marks[point_name][2] - self.__marks[point_name][1]
23 |
24 | return self.__marks[point_name][0], f"{int(1E3 * self.__marks[point_name][0])}ms"
25 |
26 | def clear_points(self):
27 | self.__marks = {}
28 |
--------------------------------------------------------------------------------
/uutils/controls/__init__.py:
--------------------------------------------------------------------------------
1 | # init
--------------------------------------------------------------------------------
/uutils/controls/keyboard/__init__.py:
--------------------------------------------------------------------------------
1 | # init
--------------------------------------------------------------------------------
/uutils/controls/mouse/__init__.py:
--------------------------------------------------------------------------------
1 | # init
--------------------------------------------------------------------------------
/uutils/controls/mouse/pyautogui.py:
--------------------------------------------------------------------------------
1 | import pyautogui
2 |
3 | pyautogui.MINIMUM_DURATION = 0
4 | pyautogui.MINIMUM_SLEEP = 0
5 | pyautogui.PAUSE = 0
6 | pyautogui.FAILSAFE = False
7 |
8 |
9 | class MouseControls:
10 | type = "pyautogui"
11 |
12 | @staticmethod
13 | def move(x, y):
14 | pyautogui.moveTo(x, y)
15 |
16 | @staticmethod
17 | def move_relative(rel_x, rel_y):
18 | pyautogui.moveRel(rel_x, rel_y)
19 |
20 | @staticmethod
21 | def click():
22 | pyautogui.leftClick()
23 |
24 | @staticmethod
25 | def get_position():
26 | point = pyautogui.position()
27 | return (point.x, point.y)
28 |
--------------------------------------------------------------------------------
/uutils/controls/mouse/pydirectinput.py:
--------------------------------------------------------------------------------
1 | import pydirectinput
2 |
3 | pydirectinput.MINIMUM_DURATION = 0
4 | pydirectinput.MINIMUM_SLEEP = 0
5 | pydirectinput.PAUSE = 0
6 | pydirectinput.FAILSAFE = False
7 |
8 |
9 | class MouseControls:
10 | type = "pydirectinput"
11 |
12 | @staticmethod
13 | def move(x, y):
14 | pydirectinput.moveTo(x, y)
15 |
16 | @staticmethod
17 | def move_relative(rel_x, rel_y):
18 | pydirectinput.moveRel(rel_x, rel_y)
19 |
20 | @staticmethod
21 | def click():
22 | pydirectinput.leftClick()
23 |
24 | @staticmethod
25 | def get_position():
26 | return list(pydirectinput.position())
27 |
--------------------------------------------------------------------------------
/uutils/controls/mouse/pynput.py:
--------------------------------------------------------------------------------
1 | from pynput.mouse import Button, Controller
2 |
3 | mouse = Controller()
4 |
5 |
6 | class MouseControls:
7 | type = "pynput"
8 |
9 | @staticmethod
10 | def move(x, y):
11 | mouse.position = (x, y)
12 |
13 | @staticmethod
14 | def move_relative(rel_x, rel_y):
15 | mouse.move(rel_x, rel_y)
16 |
17 | @staticmethod
18 | def click():
19 | mouse.click(Button.left, 1)
20 |
21 | @staticmethod
22 | def get_position():
23 | return mouse.position
24 |
--------------------------------------------------------------------------------
/uutils/controls/mouse/win32.py:
--------------------------------------------------------------------------------
1 | # Taken from ??? (unknown source)
2 | import ctypes
3 | import win32api
4 | import win32con
5 |
6 |
7 | class MouseControls:
8 | """It simulates the mouse"""
9 | MOUSEEVENTF_MOVE = 0x0001 # mouse move
10 | MOUSEEVENTF_LEFTDOWN = 0x0002 # left button down
11 | MOUSEEVENTF_LEFTUP = 0x0004 # left button up
12 | MOUSEEVENTF_RIGHTDOWN = 0x0008 # right button down
13 | MOUSEEVENTF_RIGHTUP = 0x0010 # right button up
14 | MOUSEEVENTF_MIDDLEDOWN = 0x0020 # middle button down
15 | MOUSEEVENTF_MIDDLEUP = 0x0040 # middle button up
16 | MOUSEEVENTF_WHEEL = 0x0800 # wheel button rolled
17 | MOUSEEVENTF_ABSOLUTE = 0x8000 # absolute move
18 | SM_CXSCREEN = 0
19 | SM_CYSCREEN = 1
20 |
21 | def __init__(self):
22 | self.state_left = win32api.GetKeyState(0x01)
23 |
24 | def __do_event(self, flags, x_pos, y_pos, data, extra_info):
25 | """generate a mouse event"""
26 | x_calc = 65536 * x_pos / ctypes.windll.user32.GetSystemMetrics(self.SM_CXSCREEN) + 1
27 | y_calc = 65536 * y_pos / ctypes.windll.user32.GetSystemMetrics(self.SM_CYSCREEN) + 1
28 |
29 | xl = ctypes.c_long()
30 | xl.value = int(x_calc)
31 | yl = ctypes.c_long()
32 | yl.value = int(y_calc)
33 | return ctypes.windll.user32.mouse_event(flags, xl, yl, data, extra_info)
34 |
35 | def __get_button_value(self, button_name, button_up=False):
36 | """convert the name of the button into the corresponding value"""
37 | buttons = 0
38 | if button_name.find("right") >= 0:
39 | buttons = self.MOUSEEVENTF_RIGHTDOWN
40 | if button_name.find("left") >= 0:
41 | buttons = buttons + self.MOUSEEVENTF_LEFTDOWN
42 | if button_name.find("middle") >= 0:
43 | buttons = buttons + self.MOUSEEVENTF_MIDDLEDOWN
44 | if button_up:
45 | buttons = buttons << 1
46 | return buttons
47 |
48 | def is_left_mouse_down(self):
49 | a = win32api.GetKeyState(0x01)
50 |
51 | if a < 0:
52 | return True
53 | else:
54 | return False
55 |
56 | def move(self, x, y):
57 | """move the mouse to the specified coordinates"""
58 | old_pos = self.get_position()
59 | x = x if (x != -1) else old_pos[0]
60 | y = y if (y != -1) else old_pos[1]
61 | self.__do_event(self.MOUSEEVENTF_MOVE + self.MOUSEEVENTF_ABSOLUTE, x, y, 0, 0)
62 |
63 | def move_relative(self, x, y):
64 | """move the mouse to the specified coordinates"""
65 | # self.__do_event(self.MOUSEEVENTF_MOVE, x, y, 0, 0)
66 | win32api.mouse_event(win32con.MOUSEEVENTF_MOVE, x, y, 0, 0)
67 |
68 | def get_position(self):
69 | """get mouse position"""
70 | return win32api.GetCursorPos()
71 |
72 | def click(self):
73 | """left mouse button click"""
74 | self.__do_event(self.__get_button_value("left", False) + self.__get_button_value("left", True), 0, 0, 0, 0)
75 |
76 | def press_button(self, button_name="left", button_up=False):
77 | """push a button of the mouse"""
78 | self.__do_event(self.__get_button_value(button_name, button_up), 0, 0, 0, 0)
79 |
80 | def hold_mouse(self, button_name="left"):
81 | """hold a button of the mouse"""
82 | self.__do_event(self.__get_button_value(button_name, False), 0, 0, 0, 0)
83 |
84 | def release_mouse(self, button_name="left"):
85 | """release a button of the mouse"""
86 | self.__do_event(self.__get_button_value(button_name, True), 0, 0, 0, 0)
87 |
88 | def double_click (self):
89 | """Double click at the specifed placed"""
90 | for i in range(0, 1):
91 | self.click()
--------------------------------------------------------------------------------
/uutils/cv2.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy
3 |
4 | def list_ports():
5 | """
6 | Test the ports and returns a tuple with the available ports and the ones that are working.
7 | """
8 | non_working_ports = []
9 | dev_port = 0
10 | working_ports = []
11 | available_ports = []
12 | while len(non_working_ports) < 6: # if there are more than 5 non working ports stop the testing.
13 | camera = cv2.VideoCapture(dev_port)
14 | if not camera.isOpened():
15 | non_working_ports.append(dev_port)
16 | print("Port %s is not working." %dev_port)
17 | else:
18 | is_reading, img = camera.read()
19 | w = camera.get(3)
20 | h = camera.get(4)
21 | if is_reading:
22 | print("Port %s is working and reads images (%s x %s)" %(dev_port,h,w))
23 | working_ports.append(dev_port)
24 | else:
25 | print("Port %s for camera ( %s x %s) is present but does not reads." %(dev_port,h,w))
26 | available_ports.append(dev_port)
27 | dev_port +=1
28 | return available_ports,working_ports,non_working_ports
29 |
30 |
31 | def combine_bounding_box(box1, box2):
32 | box1_size = (box1[0] + box1[2], box1[1] + box1[3])
33 | box2_size = (box2[0] + box2[2], box2[1] + box2[3])
34 |
35 | x = min(box1[0], box2[0])
36 | y = min(box1[1], box2[1])
37 | w = max(box1_size[0], box2_size[0])
38 | h = max(box1_size[1], box2_size[1])
39 | return x, y, w - x, h - y
40 |
41 |
42 | def convert_rectangle_to_xyxy(rect):
43 | return rect[0], rect[1], rect[0] + rect[2], rect[1] + rect[3]
44 |
45 |
46 | def bb_intersection_over_union(boxA, boxB):
47 | # determine the (x, y)-coordinates of the intersection rectangle
48 | xA = max(boxA[0], boxB[0])
49 | yA = max(boxA[1], boxB[1])
50 | xB = min(boxA[2], boxB[2])
51 | yB = min(boxA[3], boxB[3])
52 |
53 | # compute the area of intersection rectangle
54 | # interArea = abs(max((xB - xA, 0)) * max((yB - yA), 0))
55 | interArea = max((xB - xA), 0) * max((yB - yA), 0)
56 | if interArea == 0:
57 | return 0
58 | # compute the area of both the prediction and ground-truth
59 | # rectangles
60 | boxAArea = abs((boxA[2] - boxA[0]) * (boxA[3] - boxA[1]))
61 | boxBArea = abs((boxB[2] - boxB[0]) * (boxB[3] - boxB[1]))
62 |
63 | # compute the intersection over union by taking the intersection
64 | # area and dividing it by the sum of prediction + ground-truth
65 | # areas - the interesection area
66 | iou = interArea / float(boxAArea + boxBArea - interArea)
67 |
68 | # return the intersection over union value
69 | return iou
70 |
71 |
72 | def check_intersection(box1, box2):
73 | # crutch, but works :3
74 | return not bb_intersection_over_union(convert_rectangle_to_xyxy(box1), convert_rectangle_to_xyxy(box2)) == 0
75 |
76 |
77 | def filter_rectangles(rect_list: list) -> list:
78 | """
79 | Filter given rect_list with selected filter type and return.
80 | :param rect_list: Rectangles list.
81 | :param filter_type: 1 to filter INSIDE, -1 to filter OUTSIDE, 0 to filter INTERSECTED
82 | :return:
83 | """
84 |
85 | changes = True
86 | while changes:
87 | changes = False
88 |
89 | for k, v in enumerate(rect_list):
90 | for rk, r in enumerate(rect_list):
91 | if rk == k:
92 | continue
93 |
94 | # print(f"v: {v}, r: {r}, I - {check_intersection(v, r)}")
95 | if check_intersection(v, r):
96 | v = combine_bounding_box(v, r)
97 | rect_list.pop(rk)
98 | rect_list[k] = v
99 | changes = True
100 | break
101 |
102 | if changes:
103 | break
104 |
105 | return rect_list
106 |
107 |
108 | def point_get_difference(source_point, dest_point):
109 | # 1000, 1000
110 | # source_point = (960, 540)
111 | # dest_point = (833, 645)
112 | # result = (100, 100)
113 |
114 | x = dest_point[0]-source_point[0]
115 | y = dest_point[1]-source_point[1]
116 |
117 | return x, y
118 |
119 |
120 | def round_to_multiple(number, multiple):
121 | return multiple * round(number / multiple)
122 |
--------------------------------------------------------------------------------
/uutils/fov_mouse.py:
--------------------------------------------------------------------------------
1 | from math import atan, degrees, radians, tan
2 | from uutils.cv2 import point_get_difference
3 |
4 | class FovMouseMovement:
5 | fov = [106.26, 73.74] # horizontal, vertical (info https://web.archive.org/web/20140516063105/http://forums.steampowered.com/forums/showpost.php?p=31476234&postcount=13)
6 | x360 = 16364 # x value to rotate on 360 degrees
7 | x1 = None
8 | x_full_hor = None
9 | sensitivity = 1
10 | screen = None # x, y, w, h
11 |
12 | def __init__(self, screen, fov, x360, sensitivity):
13 | self.screen = screen
14 |
15 | self.fov = fov
16 | self.x360 = x360
17 |
18 | self.x1 = x360/360
19 | self.x_full_hor = self.x1 * self.fov[0]
20 | # 2420 = 53.13 grads
21 | # 360 grads = 16,400 # 16364
22 |
23 | self.sensitivity = sensitivity
24 |
25 |
26 | def get_rel_move_pixels(self, angles):
27 | return (
28 | angles[0] * self.x1,
29 | angles[1] * self.x1
30 | )
31 |
32 |
33 | def get_angles(self, aim_target):
34 | """
35 | Get (x, y) angles from center of image to aim_target.
36 |
37 | Args:
38 | aim_target: pair of numbers (x, y) where to aim
39 | # window_size: size of area (x, y)
40 | # fov: field of view in degrees, (horizontal, vertical)
41 |
42 | Returns:
43 | Pair of floating point angles (x, y) in degrees
44 | """
45 | fov = (radians(self.fov[0]), radians(self.fov[1]))
46 |
47 | x_pos = aim_target[0] / (self.screen[2] - 1)
48 | y_pos = aim_target[1] / (self.screen[3] - 1)
49 |
50 | x_angle = atan((x_pos - 0.5) * 2 * tan(self.fov[0] / 2))
51 | y_angle = atan((y_pos - 0.5) * 2 * tan(self.fov[1] / 2))
52 |
53 | return degrees(x_angle), degrees(y_angle)
54 |
55 |
56 | def get_move_angle__new3(self, aim_target):
57 | # print(aim_target, gwr, pixels_per_degree, fov)
58 | # angle is the angle in radians that the camera needs to
59 | # rotate to aim at the point
60 |
61 | # px is the point x position on the screen, normalised by
62 | # the resolution (so 0.0 for the left-most pixel, 0.5 for
63 | # the centre and 1.0 for the right-most
64 |
65 | # FOV is the field of view in the x dimension in radians
66 | game_window_rect__center = (self.screen[2] / 2, self.screen[3] / 2)
67 | rel_diff = list(point_get_difference(game_window_rect__center, aim_target))
68 |
69 | #x_degs = degrees(atan(rel_diff[0] / game_window_rect__center[0] * tan(radians(self.fov[0] / 2))))
70 | #y_degs = degrees(atan(rel_diff[1] / game_window_rect__center[1] * tan(radians(self.fov[1] / 2))))
71 |
72 | x__normalized = rel_diff[0] / (self.screen[2]-1)
73 | x_angle = degrees(atan(x__normalized * 2 * tan(radians(self.fov[0]) / 2)))
74 |
75 | y__normalized = rel_diff[1] / (self.screen[3]-1)
76 | y_angle = degrees(atan(y__normalized * 2 * tan(radians(self.fov[1]) / 2)))
77 |
78 | #print("REL DIFF", rel_diff)
79 | #print("X NORMALIZED", x__normalized)
80 | #print("ANGLES IS", (x_angle, y_angle))
81 |
82 | rel_diff[0] = x_angle
83 | rel_diff[1] = y_angle
84 | return rel_diff
85 |
86 |
87 | def get_move_angle__new(self, aim_target):
88 | game_window_rect__center = (self.screen[2]/2, self.screen[3]/2)
89 | rel_diff = list(point_get_difference(game_window_rect__center, aim_target))
90 |
91 | x_degs = degrees(atan(rel_diff[0]/game_window_rect__center[0])) * ((self.fov[0]/2)/45)
92 | y_degs = degrees(atan(rel_diff[1] / game_window_rect__center[0])) * ((self.fov[1]/2)/45)
93 | rel_diff[0] = x_degs
94 | rel_diff[1] = y_degs
95 |
96 | return rel_diff
97 |
98 |
99 | def get_move_angle(self, aim_target):
100 | game_window_rect__center = (self.screen[2]/2, self.screen[3]/2)
101 |
102 | # rel_diff = list(point_get_difference(game_window_rect__center, aim_target)) # get absolute offset
103 | rel_diff = [0, 0]
104 |
105 | if game_window_rect__center[0] > aim_target[0]:
106 | rel_diff[0] = -1
107 | else:
108 | rel_diff[0] = 1
109 |
110 | if game_window_rect__center[1] > aim_target[1]:
111 | rel_diff[1] = -1
112 | else:
113 | rel_diff[1] = 1
114 |
115 | # FOR X (convert to degrees movement
116 | x_mult_factor = (self.x1 * self.fov[0] / 2) / game_window_rect__center[0]
117 | X_CORRECTION_DEGS = 7.2 # 7.2
118 |
119 | x_diff = game_window_rect__center[0] - aim_target[0]
120 | x_diff_move_factor = x_diff * x_mult_factor
121 | x_diff__angle = x_diff_move_factor / self.x1
122 |
123 | if x_diff > game_window_rect__center[0] / 2:
124 | x_diff_quarter = x_diff - game_window_rect__center[0] / 2
125 | x_diff__angle_fixed = X_CORRECTION_DEGS - (X_CORRECTION_DEGS * (x_diff_quarter / (game_window_rect__center[0] / 2)))
126 | else:
127 | x_diff_quarter = x_diff
128 | x_diff__angle_fixed = X_CORRECTION_DEGS * (x_diff_quarter / (game_window_rect__center[0] / 2))
129 |
130 | x_diff__angle_move_factor = x_diff__angle + x_diff__angle_fixed
131 | x_move = x_diff__angle_move_factor / self.x_get_ratio(x_diff__angle_move_factor)
132 |
133 | if rel_diff[0] < 0:
134 | rel_diff[0] = -int(abs(x_move))
135 | else:
136 | rel_diff[0] = int(abs(x_move))
137 |
138 | # FOR Y (convert to degrees movement
139 | y_mult_factor = (self.x1 * self.fov[1] / 2) / game_window_rect__center[1]
140 | Y_CORRECTION_DEGS = 4.05 # 7.2
141 |
142 | y_diff = game_window_rect__center[1] - aim_target[1]
143 | y_diff_move_factor = y_diff * y_mult_factor
144 | y_diff__angle = y_diff_move_factor / self.x1
145 |
146 | if y_diff > game_window_rect__center[1] / 2:
147 | y_diff_quarter = y_diff - game_window_rect__center[1] / 2
148 | y_diff__angle_fixed = Y_CORRECTION_DEGS - (Y_CORRECTION_DEGS * (y_diff_quarter / (game_window_rect__center[1] / 2)))
149 | else:
150 | y_diff_quarter = y_diff
151 | y_diff__angle_fixed = Y_CORRECTION_DEGS * (y_diff_quarter / (game_window_rect__center[1] / 2))
152 |
153 | y_diff__angle_move_factor = y_diff__angle + y_diff__angle_fixed
154 | y_move = y_diff__angle_move_factor / self.y_get_ratio(y_diff__angle_move_factor)
155 |
156 | if rel_diff[1] < 0:
157 | rel_diff[1] = -int(abs(y_move))
158 | else:
159 | rel_diff[1] = int(abs(y_move))
160 |
161 | return rel_diff
162 |
163 |
164 | def x_get_ratio(self, angle):
165 | if angle < 15:
166 | return 0.0201
167 | elif angle < 20:
168 | return 0.0204
169 | elif angle < 24.5:
170 | return 0.0206
171 | elif angle < 29:
172 | return 0.0211
173 | elif angle < 33.5:
174 | return 0.0216
175 | elif angle < 35:
176 | return 0.02175
177 | elif angle < 39:
178 | return 0.0214
179 | elif angle < 45:
180 | return 0.0212
181 | elif angle < 49:
182 | return 0.0214
183 | else:
184 | return 0.0216
185 |
186 |
187 | def y_get_ratio(self, angle):
188 | if angle < 6:
189 | return 0.022
190 | elif angle < 15:
191 | return 0.023
192 | elif angle < 24:
193 | return 0.0235
194 | elif angle < 25:
195 | return 0.0232
196 | elif angle < 26:
197 | return 0.0228
198 | elif angle < 28:
199 | return 0.0225
200 | elif angle < 29:
201 | return 0.0223
202 | elif angle < 35:
203 | return 0.022
204 | elif angle < 40:
205 | return 0.021
206 |
--------------------------------------------------------------------------------
/uutils/fps.py:
--------------------------------------------------------------------------------
1 | # Taken from https://stackoverflow.com/questions/43761004/fps-how-to-divide-count-by-time-function-to-determine-fps
2 | import time
3 | import collections
4 |
5 |
6 | class FPS:
7 | def __init__(self,avarageof=50):
8 | self.frametimestamps = collections.deque(maxlen=avarageof)
9 |
10 | def __call__(self):
11 | self.frametimestamps.append(((time.time_ns() / 1000000) / 1000)%60)
12 | if len(self.frametimestamps) > 1:
13 | return len(self.frametimestamps)/(self.frametimestamps[-1]-self.frametimestamps[0])
14 | else:
15 | return 0.0
--------------------------------------------------------------------------------
/uutils/grabbers/__init__.py:
--------------------------------------------------------------------------------
1 | # init
--------------------------------------------------------------------------------
/uutils/grabbers/d3dshot.py:
--------------------------------------------------------------------------------
1 | import d3dshot
2 |
3 |
4 | class Grabber:
5 | type = "d3dshot"
6 | d = None
7 |
8 | def __init__(self):
9 | self.d = d3dshot.create(capture_output="numpy")
10 |
11 | def get_image(self, grab_area):
12 | """
13 | Make a screenshot of a given area and return it.
14 | :param grab_area: Format is {"top": 40, "left": 0, "width": 800, "height": 640}
15 | :return: numpy array
16 | """
17 |
18 | # noinspection PyTypeChecker
19 | return self.d.screenshot(region=(grab_area["left"], grab_area["top"], grab_area["left"]+grab_area["width"], grab_area["top"]+grab_area["height"]))
20 |
--------------------------------------------------------------------------------
/uutils/grabbers/dxcam.py:
--------------------------------------------------------------------------------
1 | import dxcam
2 |
3 |
4 | class Grabber:
5 | type="dxcam"
6 | dxcamera = None
7 | dxcapture_initialized = False
8 |
9 | def __dxcapture_init(self):
10 | self.dxcamera = dxcam.create()
11 | self.dxcapture_initialized = True
12 |
13 | def get_image(self, grab_area):
14 | """
15 | Make a screenshot of a given area and return it.
16 | :param grab_area: Format is {"top": 40, "left": 0, "width": 800, "height": 640}
17 | :return: numpy array
18 | """
19 | if not self.dxcapture_initialized:
20 | self.__dxcapture_init()
21 |
22 | # noinspection PyTypeChecker
23 | return self.dxcamera.grab(region=(
24 | grab_area['left'], grab_area['top'],
25 | grab_area['width'] + grab_area['left'], grab_area['height'] + grab_area['top']
26 | ))
27 |
--------------------------------------------------------------------------------
/uutils/grabbers/dxcamcapture.py:
--------------------------------------------------------------------------------
1 | import dxcam
2 |
3 |
4 | class Grabber:
5 | type = "dxcamcapture"
6 | dxcamera = None
7 | dxcapture_initialized = False
8 |
9 | def __dxcapture_init(self, grab_area):
10 | self.dxcamera = dxcam.create()
11 |
12 | self.dxcamera.start(region=(
13 | grab_area['left'], grab_area['top'],
14 | grab_area['width'] + grab_area['left'], grab_area['height'] + grab_area['top']
15 | ))
16 |
17 | if self.dxcamera.is_capturing:
18 | print("DXCAMERA capturing started ...")
19 | self.dxcapture_initialized = True
20 | else:
21 | print("DXCAMERA capture error.")
22 | exit(1)
23 |
24 | def get_image(self, grab_area):
25 | """
26 | Make a screenshot of a given area and return it.
27 | :param grab_area: Format is {"top": 40, "left": 0, "width": 800, "height": 640}
28 | :return: numpy array
29 | """
30 | if not self.dxcapture_initialized:
31 | self.__dxcapture_init(grab_area)
32 |
33 | # noinspection PyTypeChecker
34 | return self.dxcamera.get_latest_frame()
35 |
--------------------------------------------------------------------------------
/uutils/grabbers/mss.py:
--------------------------------------------------------------------------------
1 | import mss
2 | import numpy
3 | import cv2
4 |
5 |
6 | class Grabber:
7 | type = "mss"
8 | sct = mss.mss()
9 |
10 | def get_image(self, grab_area):
11 | """
12 | Make a screenshot of a given area and return it.
13 | :param grab_area: Format is {"top": 40, "left": 0, "width": 800, "height": 640}
14 | :return: numpy array
15 | """
16 | return cv2.cvtColor(numpy.array(self.sct.grab(grab_area)), cv2.COLOR_BGR2RGB) # return RGB, not BGRA
17 |
--------------------------------------------------------------------------------
/uutils/grabbers/obs_vc.py:
--------------------------------------------------------------------------------
1 | import cv2
2 | import numpy
3 |
4 |
5 | class Grabber:
6 | type = "obs_vc"
7 | device = None
8 | cap_size_set = False
9 |
10 | def obs_vc_init(self, capture_device = 0):
11 | self.device = cv2.VideoCapture(capture_device)
12 |
13 | def set_cap_size(self, w, h):
14 | # h = 360
15 | # w = 640
16 |
17 | self.device.set(cv2.CAP_PROP_FRAME_WIDTH, w)
18 | self.device.set(cv2.CAP_PROP_FRAME_HEIGHT, h)
19 |
20 |
21 | def get_image(self, grab_area):
22 | """
23 | Return last frame.
24 | :return: numpy array
25 | """
26 | if not self.cap_size_set:
27 | self.set_cap_size(grab_area['width'], grab_area['height'])
28 | self.cap_size_set = True
29 |
30 | ret, frame = self.device.read()
31 | frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
32 |
33 | return frame
34 |
--------------------------------------------------------------------------------
/uutils/grabbers/screengear.py:
--------------------------------------------------------------------------------
1 | from vidgear.gears import ScreenGear
2 |
3 |
4 | class Grabber:
5 | type = "screengear"
6 | stream = None
7 | stream_initialized = False
8 |
9 | def __stream_init(self, grab_area):
10 | self.stream = ScreenGear(logging=True, **grab_area).start()
11 | self.stream_initialized = True
12 |
13 | def get_image(self, grab_area):
14 | """
15 | Make a screenshot of a given area and return it.
16 | :param grab_area: Format is {"top": 40, "left": 0, "width": 800, "height": 640}
17 | :return: numpy array
18 | """
19 | if not self.stream_initialized:
20 | self.__stream_init(grab_area)
21 |
22 | # noinspection PyTypeChecker
23 | return self.stream.read()
24 |
--------------------------------------------------------------------------------
/uutils/grabbers/win32.py:
--------------------------------------------------------------------------------
1 | import win32gui, win32ui, win32con, win32api
2 | import numpy
3 | import cv2
4 |
5 |
6 | class Grabber:
7 | type = "win32"
8 |
9 | @staticmethod
10 | def __win32_grab(region=None):
11 | hwin = win32gui.GetDesktopWindow()
12 |
13 | if region:
14 | left, top, x2, y2 = region
15 | width = x2 - left
16 | height = y2 - top
17 | else:
18 | width = win32api.GetSystemMetrics(win32con.SM_CXVIRTUALSCREEN)
19 | height = win32api.GetSystemMetrics(win32con.SM_CYVIRTUALSCREEN)
20 | left = win32api.GetSystemMetrics(win32con.SM_XVIRTUALSCREEN)
21 | top = win32api.GetSystemMetrics(win32con.SM_YVIRTUALSCREEN)
22 |
23 | hwindc = win32gui.GetWindowDC(hwin)
24 | srcdc = win32ui.CreateDCFromHandle(hwindc)
25 | memdc = srcdc.CreateCompatibleDC()
26 | bmp = win32ui.CreateBitmap()
27 | bmp.CreateCompatibleBitmap(srcdc, width, height)
28 | memdc.SelectObject(bmp)
29 | memdc.BitBlt((0, 0), (width, height), srcdc, (left, top), win32con.SRCCOPY)
30 |
31 | signedIntsArray = bmp.GetBitmapBits(True)
32 | img = numpy.fromstring(signedIntsArray, dtype='uint8')
33 | img.shape = (height, width, 4) # height, width, channels
34 |
35 | srcdc.DeleteDC()
36 | memdc.DeleteDC()
37 | win32gui.ReleaseDC(hwin, hwindc)
38 | win32gui.DeleteObject(bmp.GetHandle())
39 |
40 | img = cv2.cvtColor(img, cv2.COLOR_BGRA2RGB) # convert to RGB
41 |
42 | return img
43 |
44 | def get_image(self, grab_area):
45 | """
46 | Make a screenshot of a given area and return it.
47 | :param grab_area: Format is {"top": 40, "left": 0, "width": 800, "height": 640}
48 | :return: numpy array
49 | """
50 | # noinspection PyTypeChecker
51 | return self.__win32_grab((
52 | grab_area['left'], grab_area['top'],
53 | grab_area['width'] + grab_area['left'], grab_area['height'] + grab_area['top']
54 | ))
55 |
--------------------------------------------------------------------------------
/uutils/nms.py:
--------------------------------------------------------------------------------
1 | # Taken from: https://pyimagesearch.com/2015/02/16/faster-non-maximum-suppression-python/
2 | import numpy as np
3 |
4 |
5 | # Malisiewicz et al.
6 | def non_max_suppression_fast(boxes, overlapThresh):
7 | # if there are no boxes, return an empty list
8 | if len(boxes) == 0:
9 | return []
10 | # if the bounding boxes integers, convert them to floats --
11 | # this is important since we'll be doing a bunch of divisions
12 | if boxes.dtype.kind == "i":
13 | boxes = boxes.astype("float")
14 | # initialize the list of picked indexes
15 | pick = []
16 | # grab the coordinates of the bounding boxes
17 | x1 = boxes[:, 0]
18 | y1 = boxes[:, 1]
19 | x2 = boxes[:, 2]
20 | y2 = boxes[:, 3]
21 | # compute the area of the bounding boxes and sort the bounding
22 | # boxes by the bottom-right y-coordinate of the bounding box
23 | area = (x2 - x1 + 1) * (y2 - y1 + 1)
24 | idxs = np.argsort(y2)
25 | # keep looping while some indexes still remain in the indexes
26 | # list
27 | while len(idxs) > 0:
28 | # grab the last index in the indexes list and add the
29 | # index value to the list of picked indexes
30 | last = len(idxs) - 1
31 | i = idxs[last]
32 | pick.append(i)
33 | # find the largest (x, y) coordinates for the start of
34 | # the bounding box and the smallest (x, y) coordinates
35 | # for the end of the bounding box
36 | xx1 = np.maximum(x1[i], x1[idxs[:last]])
37 | yy1 = np.maximum(y1[i], y1[idxs[:last]])
38 | xx2 = np.minimum(x2[i], x2[idxs[:last]])
39 | yy2 = np.minimum(y2[i], y2[idxs[:last]])
40 | # compute the width and height of the bounding box
41 | w = np.maximum(0, xx2 - xx1 + 1)
42 | h = np.maximum(0, yy2 - yy1 + 1)
43 | # compute the ratio of overlap
44 | overlap = (w * h) / area[idxs[:last]]
45 | # delete all indexes from the index list that have
46 | idxs = np.delete(idxs, np.concatenate(([last],
47 | np.where(overlap > overlapThresh)[0])))
48 | # return only the bounding boxes that were picked using the
49 | # integer data type
50 | return boxes[pick].astype("int")
51 |
--------------------------------------------------------------------------------
/uutils/streaming/__init__.py:
--------------------------------------------------------------------------------
1 | # init
--------------------------------------------------------------------------------
/uutils/streaming/client.py:
--------------------------------------------------------------------------------
1 | import socket
2 | import time
3 |
4 | import cv2
5 | import mss
6 | import numpy
7 |
8 | from zlib import decompress
9 | import lz4.frame
10 |
11 | import pygame
12 |
13 | WIDTH = 1280
14 | HEIGHT = 720
15 |
16 | def recvall(conn, length):
17 | """ Retreive all pixels. """
18 |
19 | buf = b''
20 | while len(buf) < length:
21 | data = conn.recv(length - len(buf))
22 | if not data:
23 | return data
24 | buf += data
25 | return buf
26 |
27 | def main(host='192.168.50.210', port=4000):
28 | title = "[MSS] FPS benchmark"
29 | new_frame_time, prev_frame_time, fps = 0, 0, 0
30 | last_time = time.time()
31 |
32 | font = cv2.FONT_HERSHEY_SIMPLEX
33 | watching = True
34 |
35 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
36 | sock.connect((host, port))
37 | try:
38 | while watching:
39 | print("STEP 1")
40 |
41 | # Retreive the size of the pixels length, the pixels length and pixels
42 | size_len = int.from_bytes(sock.recv(1), byteorder='big')
43 | print(f"step 1.1 (size_len = {size_len})")
44 | size = int.from_bytes(recvall(sock, size_len), byteorder='big')
45 | print(f"step 1.2 (size = {size})")
46 | pixels_recvd = recvall(sock, size)
47 | # pixels = decompress(pixels_recvd)
48 | pixels = lz4.frame.decompress(pixels_recvd)
49 |
50 | print(f"STEP 2 (size = {len(pixels_recvd)})")
51 |
52 | # convert received pixels to cv2 image
53 | buf_as_np_array = numpy.frombuffer(pixels, numpy.uint8)
54 | rgb = buf_as_np_array.reshape(HEIGHT, WIDTH, 3)
55 | img = cv2.cvtColor(rgb, cv2.COLOR_RGB2BGR)
56 |
57 | print("STEP 3")
58 |
59 | # calc fps
60 | new_frame_time = time.time()
61 | fps = 1/(new_frame_time-prev_frame_time)
62 | prev_frame_time = new_frame_time
63 | fps = int(fps)
64 |
65 | # display fps
66 | cv2.putText(img, str(fps), (7, 40), font, 1, (100, 255, 0), 3, cv2.LINE_AA)
67 |
68 | # display grabbed image (480p)
69 | # imS = cv2.resize(img, (854, 480))
70 | cv2.imshow(title, img)
71 | if cv2.waitKey(1) & 0xFF == ord("q"):
72 | cv2.destroyAllWindows()
73 | break
74 | finally:
75 | sock.close()
76 |
77 | if __name__ == '__main__':
78 | main()
--------------------------------------------------------------------------------
/uutils/time.py:
--------------------------------------------------------------------------------
1 | import time
2 |
3 |
4 | def sleep(duration, get_now=time.perf_counter):
5 | """
6 | Custom sleep function that works more accurate then time.sleep does.
7 | Taken from: https://stackoverflow.com/a/60185893/3684575
8 | :param duration: Duration to sleep (in seconds).
9 | :param get_now: Function to retrieve current time (time.perf_counter by default)
10 | :return:
11 | """
12 | now = get_now()
13 | end = now + duration
14 | while now < end:
15 | now = get_now()
16 |
--------------------------------------------------------------------------------
/uutils/win32.py:
--------------------------------------------------------------------------------
1 | import win32gui
2 |
3 |
4 | class WinHelper:
5 | @staticmethod
6 | def GetWindowRect(window_title, subtract_window_border=(16, 39, 16, 0)) -> tuple:
7 | assert len(window_title)
8 | assert len(subtract_window_border) == 4
9 |
10 | window_handle = win32gui.FindWindow(None, window_title)
11 | window_rect = list(win32gui.GetWindowRect(window_handle))
12 |
13 | window_rect[2] -= window_rect[0] # calc width
14 | window_rect[3] -= window_rect[1] # calc height
15 |
16 | if subtract_window_border:
17 | window_rect[0] += subtract_window_border[0] # left
18 | window_rect[1] += subtract_window_border[1] # top
19 | window_rect[2] -= subtract_window_border[2] # right
20 | window_rect[3] -= subtract_window_border[3] # bottom
21 |
22 | return tuple(window_rect)
23 |
--------------------------------------------------------------------------------
/uutils/windmouse.py:
--------------------------------------------------------------------------------
1 | """
2 | The author of this source code is Dr. Benjamin J. Land (~BenLand100).
3 | And it has been used under the GPLv3 compatible licence.
4 | Thanks!.
5 | ***
6 | URL: https://ben.land/post/2021/04/25/windmouse-human-mouse-movement/
7 | """
8 | import numpy
9 |
10 | sqrt3 = numpy.sqrt(3)
11 | sqrt5 = numpy.sqrt(5)
12 |
13 |
14 | def wind_mouse(start_x, start_y, dest_x, dest_y, G_0=9, W_0=3, M_0=15, D_0=12, move_mouse=lambda x, y: None):
15 | """
16 | WindMouse algorithm. Calls the move_mouse kwarg with each new step.
17 | Released under the terms of the GPLv3 license.
18 | G_0 - magnitude of the gravitational force
19 | W_0 - magnitude of the wind force fluctuations
20 | M_0 - maximum step size (velocity clip threshold)
21 | D_0 - distance where wind behavior changes from random to damped
22 | """
23 | current_x, current_y = start_x, start_y
24 | v_x = v_y = W_x = W_y = 0
25 | while (dist := numpy.hypot(dest_x - start_x, dest_y - start_y)) >= 1:
26 | W_mag = min(W_0, dist)
27 | if dist >= D_0:
28 | W_x = W_x / sqrt3 + (2 * numpy.random.random() - 1) * W_mag / sqrt5
29 | W_y = W_y / sqrt3 + (2 * numpy.random.random() - 1) * W_mag / sqrt5
30 | else:
31 | W_x /= sqrt3
32 | W_y /= sqrt3
33 | if M_0 < 3:
34 | M_0 = numpy.random.random() * 3 + 3
35 | else:
36 | M_0 /= sqrt5
37 | v_x += W_x + G_0 * (dest_x - start_x) / dist
38 | v_y += W_y + G_0 * (dest_y - start_y) / dist
39 | v_mag = numpy.hypot(v_x, v_y)
40 | if v_mag > M_0:
41 | v_clip = M_0 / 2 + numpy.random.random() * M_0 / 2
42 | v_x = (v_x / v_mag) * v_clip
43 | v_y = (v_y / v_mag) * v_clip
44 | start_x += v_x
45 | start_y += v_y
46 | move_x = int(numpy.round(start_x))
47 | move_y = int(numpy.round(start_y))
48 | if current_x != move_x or current_y != move_y:
49 | # This should wait for the mouse polling interval
50 | move_mouse(current_x := move_x, current_y := move_y)
51 | return current_x, current_y
52 |
--------------------------------------------------------------------------------
/yolov7/.gitignore:
--------------------------------------------------------------------------------
1 | # Repo-specific GitIgnore ----------------------------------------------------------------------------------------------
2 | *.jpg
3 | *.jpeg
4 | *.png
5 | *.bmp
6 | *.tif
7 | *.tiff
8 | *.heic
9 | *.JPG
10 | *.JPEG
11 | *.PNG
12 | *.BMP
13 | *.TIF
14 | *.TIFF
15 | *.HEIC
16 | *.mp4
17 | *.mov
18 | *.MOV
19 | *.avi
20 | *.data
21 | *.json
22 | *.cfg
23 | !setup.cfg
24 | !cfg/yolov3*.cfg
25 |
26 | storage.googleapis.com
27 | runs/*
28 | data/*
29 | data/images/*
30 | !data/*.yaml
31 | !data/hyps
32 | !data/scripts
33 | !data/images
34 | !data/images/zidane.jpg
35 | !data/images/bus.jpg
36 | !data/*.sh
37 |
38 | results*.csv
39 |
40 | # Datasets -------------------------------------------------------------------------------------------------------------
41 | coco/
42 | coco128/
43 | VOC/
44 |
45 | coco2017labels-segments.zip
46 | test2017.zip
47 | train2017.zip
48 | val2017.zip
49 |
50 | # MATLAB GitIgnore -----------------------------------------------------------------------------------------------------
51 | *.m~
52 | *.mat
53 | !targets*.mat
54 |
55 | # Neural Network weights -----------------------------------------------------------------------------------------------
56 | *.weights
57 | *.pt
58 | *.pb
59 | *.onnx
60 | *.engine
61 | *.mlmodel
62 | *.torchscript
63 | *.tflite
64 | *.h5
65 | *_saved_model/
66 | *_web_model/
67 | *_openvino_model/
68 | darknet53.conv.74
69 | yolov3-tiny.conv.15
70 | *.ptl
71 | *.trt
72 |
73 | # GitHub Python GitIgnore ----------------------------------------------------------------------------------------------
74 | # Byte-compiled / optimized / DLL files
75 | __pycache__/
76 | *.py[cod]
77 | *$py.class
78 |
79 | # C extensions
80 | *.so
81 |
82 | # Distribution / packaging
83 | .Python
84 | env/
85 | build/
86 | develop-eggs/
87 | dist/
88 | downloads/
89 | eggs/
90 | .eggs/
91 | lib/
92 | lib64/
93 | parts/
94 | sdist/
95 | var/
96 | wheels/
97 | *.egg-info/
98 | /wandb/
99 | .installed.cfg
100 | *.egg
101 |
102 |
103 | # PyInstaller
104 | # Usually these files are written by a python script from a template
105 | # before PyInstaller builds the exe, so as to inject date/other infos into it.
106 | *.manifest
107 | *.spec
108 |
109 | # Installer logs
110 | pip-log.txt
111 | pip-delete-this-directory.txt
112 |
113 | # Unit test / coverage reports
114 | htmlcov/
115 | .tox/
116 | .coverage
117 | .coverage.*
118 | .cache
119 | nosetests.xml
120 | coverage.xml
121 | *.cover
122 | .hypothesis/
123 |
124 | # Translations
125 | *.mo
126 | *.pot
127 |
128 | # Django stuff:
129 | *.log
130 | local_settings.py
131 |
132 | # Flask stuff:
133 | instance/
134 | .webassets-cache
135 |
136 | # Scrapy stuff:
137 | .scrapy
138 |
139 | # Sphinx documentation
140 | docs/_build/
141 |
142 | # PyBuilder
143 | target/
144 |
145 | # Jupyter Notebook
146 | .ipynb_checkpoints
147 |
148 | # pyenv
149 | .python-version
150 |
151 | # celery beat schedule file
152 | celerybeat-schedule
153 |
154 | # SageMath parsed files
155 | *.sage.py
156 |
157 | # dotenv
158 | .env
159 |
160 | # virtualenv
161 | .venv*
162 | venv*/
163 | ENV*/
164 |
165 | # Spyder project settings
166 | .spyderproject
167 | .spyproject
168 |
169 | # Rope project settings
170 | .ropeproject
171 |
172 | # mkdocs documentation
173 | /site
174 |
175 | # mypy
176 | .mypy_cache/
177 |
178 |
179 | # https://github.com/github/gitignore/blob/master/Global/macOS.gitignore -----------------------------------------------
180 |
181 | # General
182 | .DS_Store
183 | .AppleDouble
184 | .LSOverride
185 |
186 | # Icon must end with two \r
187 | Icon
188 | Icon?
189 |
190 | # Thumbnails
191 | ._*
192 |
193 | # Files that might appear in the root of a volume
194 | .DocumentRevisions-V100
195 | .fseventsd
196 | .Spotlight-V100
197 | .TemporaryItems
198 | .Trashes
199 | .VolumeIcon.icns
200 | .com.apple.timemachine.donotpresent
201 |
202 | # Directories potentially created on remote AFP share
203 | .AppleDB
204 | .AppleDesktop
205 | Network Trash Folder
206 | Temporary Items
207 | .apdisk
208 |
209 |
210 | # https://github.com/github/gitignore/blob/master/Global/JetBrains.gitignore
211 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
212 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
213 |
214 | # User-specific stuff:
215 | .idea/*
216 | .idea/**/workspace.xml
217 | .idea/**/tasks.xml
218 | .idea/dictionaries
219 | .html # Bokeh Plots
220 | .pg # TensorFlow Frozen Graphs
221 | .avi # videos
222 |
223 | # Sensitive or high-churn files:
224 | .idea/**/dataSources/
225 | .idea/**/dataSources.ids
226 | .idea/**/dataSources.local.xml
227 | .idea/**/sqlDataSources.xml
228 | .idea/**/dynamic.xml
229 | .idea/**/uiDesigner.xml
230 |
231 | # Gradle:
232 | .idea/**/gradle.xml
233 | .idea/**/libraries
234 |
235 | # CMake
236 | cmake-build-debug/
237 | cmake-build-release/
238 |
239 | # Mongo Explorer plugin:
240 | .idea/**/mongoSettings.xml
241 |
242 | ## File-based project format:
243 | *.iws
244 |
245 | ## Plugin-specific files:
246 |
247 | # IntelliJ
248 | out/
249 |
250 | # mpeltonen/sbt-idea plugin
251 | .idea_modules/
252 |
253 | # JIRA plugin
254 | atlassian-ide-plugin.xml
255 |
256 | # Cursive Clojure plugin
257 | .idea/replstate.xml
258 |
259 | # Crashlytics plugin (for Android Studio and IntelliJ)
260 | com_crashlytics_export_strings.xml
261 | crashlytics.properties
262 | crashlytics-build.properties
263 | fabric.properties
264 |
--------------------------------------------------------------------------------
/yolov7/cfg/baseline/r50-csp.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [12,16, 19,36, 40,28] # P3/8
9 | - [36,75, 76,55, 72,146] # P4/16
10 | - [142,110, 192,243, 459,401] # P5/32
11 |
12 | # CSP-ResNet backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Stem, [128]], # 0-P1/2
16 | [-1, 3, ResCSPC, [128]],
17 | [-1, 1, Conv, [256, 3, 2]], # 2-P3/8
18 | [-1, 4, ResCSPC, [256]],
19 | [-1, 1, Conv, [512, 3, 2]], # 4-P3/8
20 | [-1, 6, ResCSPC, [512]],
21 | [-1, 1, Conv, [1024, 3, 2]], # 6-P3/8
22 | [-1, 3, ResCSPC, [1024]], # 7
23 | ]
24 |
25 | # CSP-Res-PAN head
26 | head:
27 | [[-1, 1, SPPCSPC, [512]], # 8
28 | [-1, 1, Conv, [256, 1, 1]],
29 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
30 | [5, 1, Conv, [256, 1, 1]], # route backbone P4
31 | [[-1, -2], 1, Concat, [1]],
32 | [-1, 2, ResCSPB, [256]], # 13
33 | [-1, 1, Conv, [128, 1, 1]],
34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
35 | [3, 1, Conv, [128, 1, 1]], # route backbone P3
36 | [[-1, -2], 1, Concat, [1]],
37 | [-1, 2, ResCSPB, [128]], # 18
38 | [-1, 1, Conv, [256, 3, 1]],
39 | [-2, 1, Conv, [256, 3, 2]],
40 | [[-1, 13], 1, Concat, [1]], # cat
41 | [-1, 2, ResCSPB, [256]], # 22
42 | [-1, 1, Conv, [512, 3, 1]],
43 | [-2, 1, Conv, [512, 3, 2]],
44 | [[-1, 8], 1, Concat, [1]], # cat
45 | [-1, 2, ResCSPB, [512]], # 26
46 | [-1, 1, Conv, [1024, 3, 1]],
47 |
48 | [[19,23,27], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov7/cfg/baseline/x50-csp.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [12,16, 19,36, 40,28] # P3/8
9 | - [36,75, 76,55, 72,146] # P4/16
10 | - [142,110, 192,243, 459,401] # P5/32
11 |
12 | # CSP-ResNeXt backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Stem, [128]], # 0-P1/2
16 | [-1, 3, ResXCSPC, [128]],
17 | [-1, 1, Conv, [256, 3, 2]], # 2-P3/8
18 | [-1, 4, ResXCSPC, [256]],
19 | [-1, 1, Conv, [512, 3, 2]], # 4-P3/8
20 | [-1, 6, ResXCSPC, [512]],
21 | [-1, 1, Conv, [1024, 3, 2]], # 6-P3/8
22 | [-1, 3, ResXCSPC, [1024]], # 7
23 | ]
24 |
25 | # CSP-ResX-PAN head
26 | head:
27 | [[-1, 1, SPPCSPC, [512]], # 8
28 | [-1, 1, Conv, [256, 1, 1]],
29 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
30 | [5, 1, Conv, [256, 1, 1]], # route backbone P4
31 | [[-1, -2], 1, Concat, [1]],
32 | [-1, 2, ResXCSPB, [256]], # 13
33 | [-1, 1, Conv, [128, 1, 1]],
34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
35 | [3, 1, Conv, [128, 1, 1]], # route backbone P3
36 | [[-1, -2], 1, Concat, [1]],
37 | [-1, 2, ResXCSPB, [128]], # 18
38 | [-1, 1, Conv, [256, 3, 1]],
39 | [-2, 1, Conv, [256, 3, 2]],
40 | [[-1, 13], 1, Concat, [1]], # cat
41 | [-1, 2, ResXCSPB, [256]], # 22
42 | [-1, 1, Conv, [512, 3, 1]],
43 | [-2, 1, Conv, [512, 3, 2]],
44 | [[-1, 8], 1, Concat, [1]], # cat
45 | [-1, 2, ResXCSPB, [512]], # 26
46 | [-1, 1, Conv, [1024, 3, 1]],
47 |
48 | [[19,23,27], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5)
49 | ]
50 |
--------------------------------------------------------------------------------
/yolov7/cfg/baseline/yolor-csp-x.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.33 # model depth multiple
4 | width_multiple: 1.25 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [12,16, 19,36, 40,28] # P3/8
9 | - [36,75, 76,55, 72,146] # P4/16
10 | - [142,110, 192,243, 459,401] # P5/32
11 |
12 | # CSP-Darknet backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [32, 3, 1]], # 0
16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2
17 | [-1, 1, Bottleneck, [64]],
18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4
19 | [-1, 2, BottleneckCSPC, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8
21 | [-1, 8, BottleneckCSPC, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16
23 | [-1, 8, BottleneckCSPC, [512]],
24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32
25 | [-1, 4, BottleneckCSPC, [1024]], # 10
26 | ]
27 |
28 | # CSP-Dark-PAN head
29 | head:
30 | [[-1, 1, SPPCSPC, [512]], # 11
31 | [-1, 1, Conv, [256, 1, 1]],
32 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
33 | [8, 1, Conv, [256, 1, 1]], # route backbone P4
34 | [[-1, -2], 1, Concat, [1]],
35 | [-1, 2, BottleneckCSPB, [256]], # 16
36 | [-1, 1, Conv, [128, 1, 1]],
37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
38 | [6, 1, Conv, [128, 1, 1]], # route backbone P3
39 | [[-1, -2], 1, Concat, [1]],
40 | [-1, 2, BottleneckCSPB, [128]], # 21
41 | [-1, 1, Conv, [256, 3, 1]],
42 | [-2, 1, Conv, [256, 3, 2]],
43 | [[-1, 16], 1, Concat, [1]], # cat
44 | [-1, 2, BottleneckCSPB, [256]], # 25
45 | [-1, 1, Conv, [512, 3, 1]],
46 | [-2, 1, Conv, [512, 3, 2]],
47 | [[-1, 11], 1, Concat, [1]], # cat
48 | [-1, 2, BottleneckCSPB, [512]], # 29
49 | [-1, 1, Conv, [1024, 3, 1]],
50 |
51 | [[22,26,30], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5)
52 | ]
53 |
--------------------------------------------------------------------------------
/yolov7/cfg/baseline/yolor-csp.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [12,16, 19,36, 40,28] # P3/8
9 | - [36,75, 76,55, 72,146] # P4/16
10 | - [142,110, 192,243, 459,401] # P5/32
11 |
12 | # CSP-Darknet backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [32, 3, 1]], # 0
16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2
17 | [-1, 1, Bottleneck, [64]],
18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4
19 | [-1, 2, BottleneckCSPC, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8
21 | [-1, 8, BottleneckCSPC, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16
23 | [-1, 8, BottleneckCSPC, [512]],
24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32
25 | [-1, 4, BottleneckCSPC, [1024]], # 10
26 | ]
27 |
28 | # CSP-Dark-PAN head
29 | head:
30 | [[-1, 1, SPPCSPC, [512]], # 11
31 | [-1, 1, Conv, [256, 1, 1]],
32 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
33 | [8, 1, Conv, [256, 1, 1]], # route backbone P4
34 | [[-1, -2], 1, Concat, [1]],
35 | [-1, 2, BottleneckCSPB, [256]], # 16
36 | [-1, 1, Conv, [128, 1, 1]],
37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
38 | [6, 1, Conv, [128, 1, 1]], # route backbone P3
39 | [[-1, -2], 1, Concat, [1]],
40 | [-1, 2, BottleneckCSPB, [128]], # 21
41 | [-1, 1, Conv, [256, 3, 1]],
42 | [-2, 1, Conv, [256, 3, 2]],
43 | [[-1, 16], 1, Concat, [1]], # cat
44 | [-1, 2, BottleneckCSPB, [256]], # 25
45 | [-1, 1, Conv, [512, 3, 1]],
46 | [-2, 1, Conv, [512, 3, 2]],
47 | [[-1, 11], 1, Concat, [1]], # cat
48 | [-1, 2, BottleneckCSPB, [512]], # 29
49 | [-1, 1, Conv, [1024, 3, 1]],
50 |
51 | [[22,26,30], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5)
52 | ]
53 |
--------------------------------------------------------------------------------
/yolov7/cfg/baseline/yolor-d6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # expand model depth
4 | width_multiple: 1.25 # expand layer channels
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # CSP-Darknet backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [[-1, 1, ReOrg, []], # 0
17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2
18 | [-1, 1, DownC, [128]], # 2-P2/4
19 | [-1, 3, BottleneckCSPA, [128]],
20 | [-1, 1, DownC, [256]], # 4-P3/8
21 | [-1, 15, BottleneckCSPA, [256]],
22 | [-1, 1, DownC, [512]], # 6-P4/16
23 | [-1, 15, BottleneckCSPA, [512]],
24 | [-1, 1, DownC, [768]], # 8-P5/32
25 | [-1, 7, BottleneckCSPA, [768]],
26 | [-1, 1, DownC, [1024]], # 10-P6/64
27 | [-1, 7, BottleneckCSPA, [1024]], # 11
28 | ]
29 |
30 | # CSP-Dark-PAN head
31 | head:
32 | [[-1, 1, SPPCSPC, [512]], # 12
33 | [-1, 1, Conv, [384, 1, 1]],
34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
35 | [-6, 1, Conv, [384, 1, 1]], # route backbone P5
36 | [[-1, -2], 1, Concat, [1]],
37 | [-1, 3, BottleneckCSPB, [384]], # 17
38 | [-1, 1, Conv, [256, 1, 1]],
39 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
40 | [-13, 1, Conv, [256, 1, 1]], # route backbone P4
41 | [[-1, -2], 1, Concat, [1]],
42 | [-1, 3, BottleneckCSPB, [256]], # 22
43 | [-1, 1, Conv, [128, 1, 1]],
44 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
45 | [-20, 1, Conv, [128, 1, 1]], # route backbone P3
46 | [[-1, -2], 1, Concat, [1]],
47 | [-1, 3, BottleneckCSPB, [128]], # 27
48 | [-1, 1, Conv, [256, 3, 1]],
49 | [-2, 1, DownC, [256]],
50 | [[-1, 22], 1, Concat, [1]], # cat
51 | [-1, 3, BottleneckCSPB, [256]], # 31
52 | [-1, 1, Conv, [512, 3, 1]],
53 | [-2, 1, DownC, [384]],
54 | [[-1, 17], 1, Concat, [1]], # cat
55 | [-1, 3, BottleneckCSPB, [384]], # 35
56 | [-1, 1, Conv, [768, 3, 1]],
57 | [-2, 1, DownC, [512]],
58 | [[-1, 12], 1, Concat, [1]], # cat
59 | [-1, 3, BottleneckCSPB, [512]], # 39
60 | [-1, 1, Conv, [1024, 3, 1]],
61 |
62 | [[28,32,36,40], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5, P6)
63 | ]
--------------------------------------------------------------------------------
/yolov7/cfg/baseline/yolor-e6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # expand model depth
4 | width_multiple: 1.25 # expand layer channels
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # CSP-Darknet backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [[-1, 1, ReOrg, []], # 0
17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2
18 | [-1, 1, DownC, [128]], # 2-P2/4
19 | [-1, 3, BottleneckCSPA, [128]],
20 | [-1, 1, DownC, [256]], # 4-P3/8
21 | [-1, 7, BottleneckCSPA, [256]],
22 | [-1, 1, DownC, [512]], # 6-P4/16
23 | [-1, 7, BottleneckCSPA, [512]],
24 | [-1, 1, DownC, [768]], # 8-P5/32
25 | [-1, 3, BottleneckCSPA, [768]],
26 | [-1, 1, DownC, [1024]], # 10-P6/64
27 | [-1, 3, BottleneckCSPA, [1024]], # 11
28 | ]
29 |
30 | # CSP-Dark-PAN head
31 | head:
32 | [[-1, 1, SPPCSPC, [512]], # 12
33 | [-1, 1, Conv, [384, 1, 1]],
34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
35 | [-6, 1, Conv, [384, 1, 1]], # route backbone P5
36 | [[-1, -2], 1, Concat, [1]],
37 | [-1, 3, BottleneckCSPB, [384]], # 17
38 | [-1, 1, Conv, [256, 1, 1]],
39 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
40 | [-13, 1, Conv, [256, 1, 1]], # route backbone P4
41 | [[-1, -2], 1, Concat, [1]],
42 | [-1, 3, BottleneckCSPB, [256]], # 22
43 | [-1, 1, Conv, [128, 1, 1]],
44 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
45 | [-20, 1, Conv, [128, 1, 1]], # route backbone P3
46 | [[-1, -2], 1, Concat, [1]],
47 | [-1, 3, BottleneckCSPB, [128]], # 27
48 | [-1, 1, Conv, [256, 3, 1]],
49 | [-2, 1, DownC, [256]],
50 | [[-1, 22], 1, Concat, [1]], # cat
51 | [-1, 3, BottleneckCSPB, [256]], # 31
52 | [-1, 1, Conv, [512, 3, 1]],
53 | [-2, 1, DownC, [384]],
54 | [[-1, 17], 1, Concat, [1]], # cat
55 | [-1, 3, BottleneckCSPB, [384]], # 35
56 | [-1, 1, Conv, [768, 3, 1]],
57 | [-2, 1, DownC, [512]],
58 | [[-1, 12], 1, Concat, [1]], # cat
59 | [-1, 3, BottleneckCSPB, [512]], # 39
60 | [-1, 1, Conv, [1024, 3, 1]],
61 |
62 | [[28,32,36,40], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5, P6)
63 | ]
--------------------------------------------------------------------------------
/yolov7/cfg/baseline/yolor-p6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # expand model depth
4 | width_multiple: 1.0 # expand layer channels
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # CSP-Darknet backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [[-1, 1, ReOrg, []], # 0
17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2
18 | [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
19 | [-1, 3, BottleneckCSPA, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 4-P3/8
21 | [-1, 7, BottleneckCSPA, [256]],
22 | [-1, 1, Conv, [384, 3, 2]], # 6-P4/16
23 | [-1, 7, BottleneckCSPA, [384]],
24 | [-1, 1, Conv, [512, 3, 2]], # 8-P5/32
25 | [-1, 3, BottleneckCSPA, [512]],
26 | [-1, 1, Conv, [640, 3, 2]], # 10-P6/64
27 | [-1, 3, BottleneckCSPA, [640]], # 11
28 | ]
29 |
30 | # CSP-Dark-PAN head
31 | head:
32 | [[-1, 1, SPPCSPC, [320]], # 12
33 | [-1, 1, Conv, [256, 1, 1]],
34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
35 | [-6, 1, Conv, [256, 1, 1]], # route backbone P5
36 | [[-1, -2], 1, Concat, [1]],
37 | [-1, 3, BottleneckCSPB, [256]], # 17
38 | [-1, 1, Conv, [192, 1, 1]],
39 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
40 | [-13, 1, Conv, [192, 1, 1]], # route backbone P4
41 | [[-1, -2], 1, Concat, [1]],
42 | [-1, 3, BottleneckCSPB, [192]], # 22
43 | [-1, 1, Conv, [128, 1, 1]],
44 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
45 | [-20, 1, Conv, [128, 1, 1]], # route backbone P3
46 | [[-1, -2], 1, Concat, [1]],
47 | [-1, 3, BottleneckCSPB, [128]], # 27
48 | [-1, 1, Conv, [256, 3, 1]],
49 | [-2, 1, Conv, [192, 3, 2]],
50 | [[-1, 22], 1, Concat, [1]], # cat
51 | [-1, 3, BottleneckCSPB, [192]], # 31
52 | [-1, 1, Conv, [384, 3, 1]],
53 | [-2, 1, Conv, [256, 3, 2]],
54 | [[-1, 17], 1, Concat, [1]], # cat
55 | [-1, 3, BottleneckCSPB, [256]], # 35
56 | [-1, 1, Conv, [512, 3, 1]],
57 | [-2, 1, Conv, [320, 3, 2]],
58 | [[-1, 12], 1, Concat, [1]], # cat
59 | [-1, 3, BottleneckCSPB, [320]], # 39
60 | [-1, 1, Conv, [640, 3, 1]],
61 |
62 | [[28,32,36,40], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5, P6)
63 | ]
--------------------------------------------------------------------------------
/yolov7/cfg/baseline/yolor-w6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # expand model depth
4 | width_multiple: 1.0 # expand layer channels
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # CSP-Darknet backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [[-1, 1, ReOrg, []], # 0
17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2
18 | [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
19 | [-1, 3, BottleneckCSPA, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 4-P3/8
21 | [-1, 7, BottleneckCSPA, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 6-P4/16
23 | [-1, 7, BottleneckCSPA, [512]],
24 | [-1, 1, Conv, [768, 3, 2]], # 8-P5/32
25 | [-1, 3, BottleneckCSPA, [768]],
26 | [-1, 1, Conv, [1024, 3, 2]], # 10-P6/64
27 | [-1, 3, BottleneckCSPA, [1024]], # 11
28 | ]
29 |
30 | # CSP-Dark-PAN head
31 | head:
32 | [[-1, 1, SPPCSPC, [512]], # 12
33 | [-1, 1, Conv, [384, 1, 1]],
34 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
35 | [-6, 1, Conv, [384, 1, 1]], # route backbone P5
36 | [[-1, -2], 1, Concat, [1]],
37 | [-1, 3, BottleneckCSPB, [384]], # 17
38 | [-1, 1, Conv, [256, 1, 1]],
39 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
40 | [-13, 1, Conv, [256, 1, 1]], # route backbone P4
41 | [[-1, -2], 1, Concat, [1]],
42 | [-1, 3, BottleneckCSPB, [256]], # 22
43 | [-1, 1, Conv, [128, 1, 1]],
44 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
45 | [-20, 1, Conv, [128, 1, 1]], # route backbone P3
46 | [[-1, -2], 1, Concat, [1]],
47 | [-1, 3, BottleneckCSPB, [128]], # 27
48 | [-1, 1, Conv, [256, 3, 1]],
49 | [-2, 1, Conv, [256, 3, 2]],
50 | [[-1, 22], 1, Concat, [1]], # cat
51 | [-1, 3, BottleneckCSPB, [256]], # 31
52 | [-1, 1, Conv, [512, 3, 1]],
53 | [-2, 1, Conv, [384, 3, 2]],
54 | [[-1, 17], 1, Concat, [1]], # cat
55 | [-1, 3, BottleneckCSPB, [384]], # 35
56 | [-1, 1, Conv, [768, 3, 1]],
57 | [-2, 1, Conv, [512, 3, 2]],
58 | [[-1, 12], 1, Concat, [1]], # cat
59 | [-1, 3, BottleneckCSPB, [512]], # 39
60 | [-1, 1, Conv, [1024, 3, 1]],
61 |
62 | [[28,32,36,40], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5, P6)
63 | ]
--------------------------------------------------------------------------------
/yolov7/cfg/baseline/yolov3-spp.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # darknet53 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [32, 3, 1]], # 0
16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2
17 | [-1, 1, Bottleneck, [64]],
18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4
19 | [-1, 2, Bottleneck, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8
21 | [-1, 8, Bottleneck, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16
23 | [-1, 8, Bottleneck, [512]],
24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32
25 | [-1, 4, Bottleneck, [1024]], # 10
26 | ]
27 |
28 | # YOLOv3-SPP head
29 | head:
30 | [[-1, 1, Bottleneck, [1024, False]],
31 | [-1, 1, SPP, [512, [5, 9, 13]]],
32 | [-1, 1, Conv, [1024, 3, 1]],
33 | [-1, 1, Conv, [512, 1, 1]],
34 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large)
35 |
36 | [-2, 1, Conv, [256, 1, 1]],
37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
38 | [[-1, 8], 1, Concat, [1]], # cat backbone P4
39 | [-1, 1, Bottleneck, [512, False]],
40 | [-1, 1, Bottleneck, [512, False]],
41 | [-1, 1, Conv, [256, 1, 1]],
42 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium)
43 |
44 | [-2, 1, Conv, [128, 1, 1]],
45 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
46 | [[-1, 6], 1, Concat, [1]], # cat backbone P3
47 | [-1, 1, Bottleneck, [256, False]],
48 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small)
49 |
50 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
51 | ]
52 |
--------------------------------------------------------------------------------
/yolov7/cfg/baseline/yolov3.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # darknet53 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [32, 3, 1]], # 0
16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2
17 | [-1, 1, Bottleneck, [64]],
18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4
19 | [-1, 2, Bottleneck, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8
21 | [-1, 8, Bottleneck, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16
23 | [-1, 8, Bottleneck, [512]],
24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32
25 | [-1, 4, Bottleneck, [1024]], # 10
26 | ]
27 |
28 | # YOLOv3 head
29 | head:
30 | [[-1, 1, Bottleneck, [1024, False]],
31 | [-1, 1, Conv, [512, [1, 1]]],
32 | [-1, 1, Conv, [1024, 3, 1]],
33 | [-1, 1, Conv, [512, 1, 1]],
34 | [-1, 1, Conv, [1024, 3, 1]], # 15 (P5/32-large)
35 |
36 | [-2, 1, Conv, [256, 1, 1]],
37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
38 | [[-1, 8], 1, Concat, [1]], # cat backbone P4
39 | [-1, 1, Bottleneck, [512, False]],
40 | [-1, 1, Bottleneck, [512, False]],
41 | [-1, 1, Conv, [256, 1, 1]],
42 | [-1, 1, Conv, [512, 3, 1]], # 22 (P4/16-medium)
43 |
44 | [-2, 1, Conv, [128, 1, 1]],
45 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
46 | [[-1, 6], 1, Concat, [1]], # cat backbone P3
47 | [-1, 1, Bottleneck, [256, False]],
48 | [-1, 2, Bottleneck, [256, False]], # 27 (P3/8-small)
49 |
50 | [[27, 22, 15], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
51 | ]
52 |
--------------------------------------------------------------------------------
/yolov7/cfg/baseline/yolov4-csp.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [12,16, 19,36, 40,28] # P3/8
9 | - [36,75, 76,55, 72,146] # P4/16
10 | - [142,110, 192,243, 459,401] # P5/32
11 |
12 | # CSP-Darknet backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [32, 3, 1]], # 0
16 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2
17 | [-1, 1, Bottleneck, [64]],
18 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4
19 | [-1, 2, BottleneckCSPC, [128]],
20 | [-1, 1, Conv, [256, 3, 2]], # 5-P3/8
21 | [-1, 8, BottleneckCSPC, [256]],
22 | [-1, 1, Conv, [512, 3, 2]], # 7-P4/16
23 | [-1, 8, BottleneckCSPC, [512]],
24 | [-1, 1, Conv, [1024, 3, 2]], # 9-P5/32
25 | [-1, 4, BottleneckCSPC, [1024]], # 10
26 | ]
27 |
28 | # CSP-Dark-PAN head
29 | head:
30 | [[-1, 1, SPPCSPC, [512]], # 11
31 | [-1, 1, Conv, [256, 1, 1]],
32 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
33 | [8, 1, Conv, [256, 1, 1]], # route backbone P4
34 | [[-1, -2], 1, Concat, [1]],
35 | [-1, 2, BottleneckCSPB, [256]], # 16
36 | [-1, 1, Conv, [128, 1, 1]],
37 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
38 | [6, 1, Conv, [128, 1, 1]], # route backbone P3
39 | [[-1, -2], 1, Concat, [1]],
40 | [-1, 2, BottleneckCSPB, [128]], # 21
41 | [-1, 1, Conv, [256, 3, 1]],
42 | [-2, 1, Conv, [256, 3, 2]],
43 | [[-1, 16], 1, Concat, [1]], # cat
44 | [-1, 2, BottleneckCSPB, [256]], # 25
45 | [-1, 1, Conv, [512, 3, 1]],
46 | [-2, 1, Conv, [512, 3, 2]],
47 | [[-1, 11], 1, Concat, [1]], # cat
48 | [-1, 2, BottleneckCSPB, [512]], # 29
49 | [-1, 1, Conv, [1024, 3, 1]],
50 |
51 | [[22,26,30], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
52 | ]
53 |
--------------------------------------------------------------------------------
/yolov7/cfg/deploy/yolov7-d6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # yolov7-d6 backbone
14 | backbone:
15 | # [from, number, module, args],
16 | [[-1, 1, ReOrg, []], # 0
17 | [-1, 1, Conv, [96, 3, 1]], # 1-P1/2
18 |
19 | [-1, 1, DownC, [192]], # 2-P2/4
20 | [-1, 1, Conv, [64, 1, 1]],
21 | [-2, 1, Conv, [64, 1, 1]],
22 | [-1, 1, Conv, [64, 3, 1]],
23 | [-1, 1, Conv, [64, 3, 1]],
24 | [-1, 1, Conv, [64, 3, 1]],
25 | [-1, 1, Conv, [64, 3, 1]],
26 | [-1, 1, Conv, [64, 3, 1]],
27 | [-1, 1, Conv, [64, 3, 1]],
28 | [-1, 1, Conv, [64, 3, 1]],
29 | [-1, 1, Conv, [64, 3, 1]],
30 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]],
31 | [-1, 1, Conv, [192, 1, 1]], # 14
32 |
33 | [-1, 1, DownC, [384]], # 15-P3/8
34 | [-1, 1, Conv, [128, 1, 1]],
35 | [-2, 1, Conv, [128, 1, 1]],
36 | [-1, 1, Conv, [128, 3, 1]],
37 | [-1, 1, Conv, [128, 3, 1]],
38 | [-1, 1, Conv, [128, 3, 1]],
39 | [-1, 1, Conv, [128, 3, 1]],
40 | [-1, 1, Conv, [128, 3, 1]],
41 | [-1, 1, Conv, [128, 3, 1]],
42 | [-1, 1, Conv, [128, 3, 1]],
43 | [-1, 1, Conv, [128, 3, 1]],
44 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]],
45 | [-1, 1, Conv, [384, 1, 1]], # 27
46 |
47 | [-1, 1, DownC, [768]], # 28-P4/16
48 | [-1, 1, Conv, [256, 1, 1]],
49 | [-2, 1, Conv, [256, 1, 1]],
50 | [-1, 1, Conv, [256, 3, 1]],
51 | [-1, 1, Conv, [256, 3, 1]],
52 | [-1, 1, Conv, [256, 3, 1]],
53 | [-1, 1, Conv, [256, 3, 1]],
54 | [-1, 1, Conv, [256, 3, 1]],
55 | [-1, 1, Conv, [256, 3, 1]],
56 | [-1, 1, Conv, [256, 3, 1]],
57 | [-1, 1, Conv, [256, 3, 1]],
58 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]],
59 | [-1, 1, Conv, [768, 1, 1]], # 40
60 |
61 | [-1, 1, DownC, [1152]], # 41-P5/32
62 | [-1, 1, Conv, [384, 1, 1]],
63 | [-2, 1, Conv, [384, 1, 1]],
64 | [-1, 1, Conv, [384, 3, 1]],
65 | [-1, 1, Conv, [384, 3, 1]],
66 | [-1, 1, Conv, [384, 3, 1]],
67 | [-1, 1, Conv, [384, 3, 1]],
68 | [-1, 1, Conv, [384, 3, 1]],
69 | [-1, 1, Conv, [384, 3, 1]],
70 | [-1, 1, Conv, [384, 3, 1]],
71 | [-1, 1, Conv, [384, 3, 1]],
72 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]],
73 | [-1, 1, Conv, [1152, 1, 1]], # 53
74 |
75 | [-1, 1, DownC, [1536]], # 54-P6/64
76 | [-1, 1, Conv, [512, 1, 1]],
77 | [-2, 1, Conv, [512, 1, 1]],
78 | [-1, 1, Conv, [512, 3, 1]],
79 | [-1, 1, Conv, [512, 3, 1]],
80 | [-1, 1, Conv, [512, 3, 1]],
81 | [-1, 1, Conv, [512, 3, 1]],
82 | [-1, 1, Conv, [512, 3, 1]],
83 | [-1, 1, Conv, [512, 3, 1]],
84 | [-1, 1, Conv, [512, 3, 1]],
85 | [-1, 1, Conv, [512, 3, 1]],
86 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]],
87 | [-1, 1, Conv, [1536, 1, 1]], # 66
88 | ]
89 |
90 | # yolov7-d6 head
91 | head:
92 | [[-1, 1, SPPCSPC, [768]], # 67
93 |
94 | [-1, 1, Conv, [576, 1, 1]],
95 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
96 | [53, 1, Conv, [576, 1, 1]], # route backbone P5
97 | [[-1, -2], 1, Concat, [1]],
98 |
99 | [-1, 1, Conv, [384, 1, 1]],
100 | [-2, 1, Conv, [384, 1, 1]],
101 | [-1, 1, Conv, [192, 3, 1]],
102 | [-1, 1, Conv, [192, 3, 1]],
103 | [-1, 1, Conv, [192, 3, 1]],
104 | [-1, 1, Conv, [192, 3, 1]],
105 | [-1, 1, Conv, [192, 3, 1]],
106 | [-1, 1, Conv, [192, 3, 1]],
107 | [-1, 1, Conv, [192, 3, 1]],
108 | [-1, 1, Conv, [192, 3, 1]],
109 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
110 | [-1, 1, Conv, [576, 1, 1]], # 83
111 |
112 | [-1, 1, Conv, [384, 1, 1]],
113 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
114 | [40, 1, Conv, [384, 1, 1]], # route backbone P4
115 | [[-1, -2], 1, Concat, [1]],
116 |
117 | [-1, 1, Conv, [256, 1, 1]],
118 | [-2, 1, Conv, [256, 1, 1]],
119 | [-1, 1, Conv, [128, 3, 1]],
120 | [-1, 1, Conv, [128, 3, 1]],
121 | [-1, 1, Conv, [128, 3, 1]],
122 | [-1, 1, Conv, [128, 3, 1]],
123 | [-1, 1, Conv, [128, 3, 1]],
124 | [-1, 1, Conv, [128, 3, 1]],
125 | [-1, 1, Conv, [128, 3, 1]],
126 | [-1, 1, Conv, [128, 3, 1]],
127 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
128 | [-1, 1, Conv, [384, 1, 1]], # 99
129 |
130 | [-1, 1, Conv, [192, 1, 1]],
131 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
132 | [27, 1, Conv, [192, 1, 1]], # route backbone P3
133 | [[-1, -2], 1, Concat, [1]],
134 |
135 | [-1, 1, Conv, [128, 1, 1]],
136 | [-2, 1, Conv, [128, 1, 1]],
137 | [-1, 1, Conv, [64, 3, 1]],
138 | [-1, 1, Conv, [64, 3, 1]],
139 | [-1, 1, Conv, [64, 3, 1]],
140 | [-1, 1, Conv, [64, 3, 1]],
141 | [-1, 1, Conv, [64, 3, 1]],
142 | [-1, 1, Conv, [64, 3, 1]],
143 | [-1, 1, Conv, [64, 3, 1]],
144 | [-1, 1, Conv, [64, 3, 1]],
145 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
146 | [-1, 1, Conv, [192, 1, 1]], # 115
147 |
148 | [-1, 1, DownC, [384]],
149 | [[-1, 99], 1, Concat, [1]],
150 |
151 | [-1, 1, Conv, [256, 1, 1]],
152 | [-2, 1, Conv, [256, 1, 1]],
153 | [-1, 1, Conv, [128, 3, 1]],
154 | [-1, 1, Conv, [128, 3, 1]],
155 | [-1, 1, Conv, [128, 3, 1]],
156 | [-1, 1, Conv, [128, 3, 1]],
157 | [-1, 1, Conv, [128, 3, 1]],
158 | [-1, 1, Conv, [128, 3, 1]],
159 | [-1, 1, Conv, [128, 3, 1]],
160 | [-1, 1, Conv, [128, 3, 1]],
161 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
162 | [-1, 1, Conv, [384, 1, 1]], # 129
163 |
164 | [-1, 1, DownC, [576]],
165 | [[-1, 83], 1, Concat, [1]],
166 |
167 | [-1, 1, Conv, [384, 1, 1]],
168 | [-2, 1, Conv, [384, 1, 1]],
169 | [-1, 1, Conv, [192, 3, 1]],
170 | [-1, 1, Conv, [192, 3, 1]],
171 | [-1, 1, Conv, [192, 3, 1]],
172 | [-1, 1, Conv, [192, 3, 1]],
173 | [-1, 1, Conv, [192, 3, 1]],
174 | [-1, 1, Conv, [192, 3, 1]],
175 | [-1, 1, Conv, [192, 3, 1]],
176 | [-1, 1, Conv, [192, 3, 1]],
177 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
178 | [-1, 1, Conv, [576, 1, 1]], # 143
179 |
180 | [-1, 1, DownC, [768]],
181 | [[-1, 67], 1, Concat, [1]],
182 |
183 | [-1, 1, Conv, [512, 1, 1]],
184 | [-2, 1, Conv, [512, 1, 1]],
185 | [-1, 1, Conv, [256, 3, 1]],
186 | [-1, 1, Conv, [256, 3, 1]],
187 | [-1, 1, Conv, [256, 3, 1]],
188 | [-1, 1, Conv, [256, 3, 1]],
189 | [-1, 1, Conv, [256, 3, 1]],
190 | [-1, 1, Conv, [256, 3, 1]],
191 | [-1, 1, Conv, [256, 3, 1]],
192 | [-1, 1, Conv, [256, 3, 1]],
193 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
194 | [-1, 1, Conv, [768, 1, 1]], # 157
195 |
196 | [115, 1, Conv, [384, 3, 1]],
197 | [129, 1, Conv, [768, 3, 1]],
198 | [143, 1, Conv, [1152, 3, 1]],
199 | [157, 1, Conv, [1536, 3, 1]],
200 |
201 | [[158,159,160,161], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6)
202 | ]
203 |
--------------------------------------------------------------------------------
/yolov7/cfg/deploy/yolov7-e6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # yolov7-e6 backbone
14 | backbone:
15 | # [from, number, module, args],
16 | [[-1, 1, ReOrg, []], # 0
17 | [-1, 1, Conv, [80, 3, 1]], # 1-P1/2
18 |
19 | [-1, 1, DownC, [160]], # 2-P2/4
20 | [-1, 1, Conv, [64, 1, 1]],
21 | [-2, 1, Conv, [64, 1, 1]],
22 | [-1, 1, Conv, [64, 3, 1]],
23 | [-1, 1, Conv, [64, 3, 1]],
24 | [-1, 1, Conv, [64, 3, 1]],
25 | [-1, 1, Conv, [64, 3, 1]],
26 | [-1, 1, Conv, [64, 3, 1]],
27 | [-1, 1, Conv, [64, 3, 1]],
28 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
29 | [-1, 1, Conv, [160, 1, 1]], # 12
30 |
31 | [-1, 1, DownC, [320]], # 13-P3/8
32 | [-1, 1, Conv, [128, 1, 1]],
33 | [-2, 1, Conv, [128, 1, 1]],
34 | [-1, 1, Conv, [128, 3, 1]],
35 | [-1, 1, Conv, [128, 3, 1]],
36 | [-1, 1, Conv, [128, 3, 1]],
37 | [-1, 1, Conv, [128, 3, 1]],
38 | [-1, 1, Conv, [128, 3, 1]],
39 | [-1, 1, Conv, [128, 3, 1]],
40 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
41 | [-1, 1, Conv, [320, 1, 1]], # 23
42 |
43 | [-1, 1, DownC, [640]], # 24-P4/16
44 | [-1, 1, Conv, [256, 1, 1]],
45 | [-2, 1, Conv, [256, 1, 1]],
46 | [-1, 1, Conv, [256, 3, 1]],
47 | [-1, 1, Conv, [256, 3, 1]],
48 | [-1, 1, Conv, [256, 3, 1]],
49 | [-1, 1, Conv, [256, 3, 1]],
50 | [-1, 1, Conv, [256, 3, 1]],
51 | [-1, 1, Conv, [256, 3, 1]],
52 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
53 | [-1, 1, Conv, [640, 1, 1]], # 34
54 |
55 | [-1, 1, DownC, [960]], # 35-P5/32
56 | [-1, 1, Conv, [384, 1, 1]],
57 | [-2, 1, Conv, [384, 1, 1]],
58 | [-1, 1, Conv, [384, 3, 1]],
59 | [-1, 1, Conv, [384, 3, 1]],
60 | [-1, 1, Conv, [384, 3, 1]],
61 | [-1, 1, Conv, [384, 3, 1]],
62 | [-1, 1, Conv, [384, 3, 1]],
63 | [-1, 1, Conv, [384, 3, 1]],
64 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
65 | [-1, 1, Conv, [960, 1, 1]], # 45
66 |
67 | [-1, 1, DownC, [1280]], # 46-P6/64
68 | [-1, 1, Conv, [512, 1, 1]],
69 | [-2, 1, Conv, [512, 1, 1]],
70 | [-1, 1, Conv, [512, 3, 1]],
71 | [-1, 1, Conv, [512, 3, 1]],
72 | [-1, 1, Conv, [512, 3, 1]],
73 | [-1, 1, Conv, [512, 3, 1]],
74 | [-1, 1, Conv, [512, 3, 1]],
75 | [-1, 1, Conv, [512, 3, 1]],
76 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
77 | [-1, 1, Conv, [1280, 1, 1]], # 56
78 | ]
79 |
80 | # yolov7-e6 head
81 | head:
82 | [[-1, 1, SPPCSPC, [640]], # 57
83 |
84 | [-1, 1, Conv, [480, 1, 1]],
85 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
86 | [45, 1, Conv, [480, 1, 1]], # route backbone P5
87 | [[-1, -2], 1, Concat, [1]],
88 |
89 | [-1, 1, Conv, [384, 1, 1]],
90 | [-2, 1, Conv, [384, 1, 1]],
91 | [-1, 1, Conv, [192, 3, 1]],
92 | [-1, 1, Conv, [192, 3, 1]],
93 | [-1, 1, Conv, [192, 3, 1]],
94 | [-1, 1, Conv, [192, 3, 1]],
95 | [-1, 1, Conv, [192, 3, 1]],
96 | [-1, 1, Conv, [192, 3, 1]],
97 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
98 | [-1, 1, Conv, [480, 1, 1]], # 71
99 |
100 | [-1, 1, Conv, [320, 1, 1]],
101 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
102 | [34, 1, Conv, [320, 1, 1]], # route backbone P4
103 | [[-1, -2], 1, Concat, [1]],
104 |
105 | [-1, 1, Conv, [256, 1, 1]],
106 | [-2, 1, Conv, [256, 1, 1]],
107 | [-1, 1, Conv, [128, 3, 1]],
108 | [-1, 1, Conv, [128, 3, 1]],
109 | [-1, 1, Conv, [128, 3, 1]],
110 | [-1, 1, Conv, [128, 3, 1]],
111 | [-1, 1, Conv, [128, 3, 1]],
112 | [-1, 1, Conv, [128, 3, 1]],
113 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
114 | [-1, 1, Conv, [320, 1, 1]], # 85
115 |
116 | [-1, 1, Conv, [160, 1, 1]],
117 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
118 | [23, 1, Conv, [160, 1, 1]], # route backbone P3
119 | [[-1, -2], 1, Concat, [1]],
120 |
121 | [-1, 1, Conv, [128, 1, 1]],
122 | [-2, 1, Conv, [128, 1, 1]],
123 | [-1, 1, Conv, [64, 3, 1]],
124 | [-1, 1, Conv, [64, 3, 1]],
125 | [-1, 1, Conv, [64, 3, 1]],
126 | [-1, 1, Conv, [64, 3, 1]],
127 | [-1, 1, Conv, [64, 3, 1]],
128 | [-1, 1, Conv, [64, 3, 1]],
129 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
130 | [-1, 1, Conv, [160, 1, 1]], # 99
131 |
132 | [-1, 1, DownC, [320]],
133 | [[-1, 85], 1, Concat, [1]],
134 |
135 | [-1, 1, Conv, [256, 1, 1]],
136 | [-2, 1, Conv, [256, 1, 1]],
137 | [-1, 1, Conv, [128, 3, 1]],
138 | [-1, 1, Conv, [128, 3, 1]],
139 | [-1, 1, Conv, [128, 3, 1]],
140 | [-1, 1, Conv, [128, 3, 1]],
141 | [-1, 1, Conv, [128, 3, 1]],
142 | [-1, 1, Conv, [128, 3, 1]],
143 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
144 | [-1, 1, Conv, [320, 1, 1]], # 111
145 |
146 | [-1, 1, DownC, [480]],
147 | [[-1, 71], 1, Concat, [1]],
148 |
149 | [-1, 1, Conv, [384, 1, 1]],
150 | [-2, 1, Conv, [384, 1, 1]],
151 | [-1, 1, Conv, [192, 3, 1]],
152 | [-1, 1, Conv, [192, 3, 1]],
153 | [-1, 1, Conv, [192, 3, 1]],
154 | [-1, 1, Conv, [192, 3, 1]],
155 | [-1, 1, Conv, [192, 3, 1]],
156 | [-1, 1, Conv, [192, 3, 1]],
157 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
158 | [-1, 1, Conv, [480, 1, 1]], # 123
159 |
160 | [-1, 1, DownC, [640]],
161 | [[-1, 57], 1, Concat, [1]],
162 |
163 | [-1, 1, Conv, [512, 1, 1]],
164 | [-2, 1, Conv, [512, 1, 1]],
165 | [-1, 1, Conv, [256, 3, 1]],
166 | [-1, 1, Conv, [256, 3, 1]],
167 | [-1, 1, Conv, [256, 3, 1]],
168 | [-1, 1, Conv, [256, 3, 1]],
169 | [-1, 1, Conv, [256, 3, 1]],
170 | [-1, 1, Conv, [256, 3, 1]],
171 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
172 | [-1, 1, Conv, [640, 1, 1]], # 135
173 |
174 | [99, 1, Conv, [320, 3, 1]],
175 | [111, 1, Conv, [640, 3, 1]],
176 | [123, 1, Conv, [960, 3, 1]],
177 | [135, 1, Conv, [1280, 3, 1]],
178 |
179 | [[136,137,138,139], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6)
180 | ]
181 |
--------------------------------------------------------------------------------
/yolov7/cfg/deploy/yolov7-tiny-silu.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # YOLOv7-tiny backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [32, 3, 2]], # 0-P1/2
16 |
17 | [-1, 1, Conv, [64, 3, 2]], # 1-P2/4
18 |
19 | [-1, 1, Conv, [32, 1, 1]],
20 | [-2, 1, Conv, [32, 1, 1]],
21 | [-1, 1, Conv, [32, 3, 1]],
22 | [-1, 1, Conv, [32, 3, 1]],
23 | [[-1, -2, -3, -4], 1, Concat, [1]],
24 | [-1, 1, Conv, [64, 1, 1]], # 7
25 |
26 | [-1, 1, MP, []], # 8-P3/8
27 | [-1, 1, Conv, [64, 1, 1]],
28 | [-2, 1, Conv, [64, 1, 1]],
29 | [-1, 1, Conv, [64, 3, 1]],
30 | [-1, 1, Conv, [64, 3, 1]],
31 | [[-1, -2, -3, -4], 1, Concat, [1]],
32 | [-1, 1, Conv, [128, 1, 1]], # 14
33 |
34 | [-1, 1, MP, []], # 15-P4/16
35 | [-1, 1, Conv, [128, 1, 1]],
36 | [-2, 1, Conv, [128, 1, 1]],
37 | [-1, 1, Conv, [128, 3, 1]],
38 | [-1, 1, Conv, [128, 3, 1]],
39 | [[-1, -2, -3, -4], 1, Concat, [1]],
40 | [-1, 1, Conv, [256, 1, 1]], # 21
41 |
42 | [-1, 1, MP, []], # 22-P5/32
43 | [-1, 1, Conv, [256, 1, 1]],
44 | [-2, 1, Conv, [256, 1, 1]],
45 | [-1, 1, Conv, [256, 3, 1]],
46 | [-1, 1, Conv, [256, 3, 1]],
47 | [[-1, -2, -3, -4], 1, Concat, [1]],
48 | [-1, 1, Conv, [512, 1, 1]], # 28
49 | ]
50 |
51 | # YOLOv7-tiny head
52 | head:
53 | [[-1, 1, Conv, [256, 1, 1]],
54 | [-2, 1, Conv, [256, 1, 1]],
55 | [-1, 1, SP, [5]],
56 | [-2, 1, SP, [9]],
57 | [-3, 1, SP, [13]],
58 | [[-1, -2, -3, -4], 1, Concat, [1]],
59 | [-1, 1, Conv, [256, 1, 1]],
60 | [[-1, -7], 1, Concat, [1]],
61 | [-1, 1, Conv, [256, 1, 1]], # 37
62 |
63 | [-1, 1, Conv, [128, 1, 1]],
64 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
65 | [21, 1, Conv, [128, 1, 1]], # route backbone P4
66 | [[-1, -2], 1, Concat, [1]],
67 |
68 | [-1, 1, Conv, [64, 1, 1]],
69 | [-2, 1, Conv, [64, 1, 1]],
70 | [-1, 1, Conv, [64, 3, 1]],
71 | [-1, 1, Conv, [64, 3, 1]],
72 | [[-1, -2, -3, -4], 1, Concat, [1]],
73 | [-1, 1, Conv, [128, 1, 1]], # 47
74 |
75 | [-1, 1, Conv, [64, 1, 1]],
76 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
77 | [14, 1, Conv, [64, 1, 1]], # route backbone P3
78 | [[-1, -2], 1, Concat, [1]],
79 |
80 | [-1, 1, Conv, [32, 1, 1]],
81 | [-2, 1, Conv, [32, 1, 1]],
82 | [-1, 1, Conv, [32, 3, 1]],
83 | [-1, 1, Conv, [32, 3, 1]],
84 | [[-1, -2, -3, -4], 1, Concat, [1]],
85 | [-1, 1, Conv, [64, 1, 1]], # 57
86 |
87 | [-1, 1, Conv, [128, 3, 2]],
88 | [[-1, 47], 1, Concat, [1]],
89 |
90 | [-1, 1, Conv, [64, 1, 1]],
91 | [-2, 1, Conv, [64, 1, 1]],
92 | [-1, 1, Conv, [64, 3, 1]],
93 | [-1, 1, Conv, [64, 3, 1]],
94 | [[-1, -2, -3, -4], 1, Concat, [1]],
95 | [-1, 1, Conv, [128, 1, 1]], # 65
96 |
97 | [-1, 1, Conv, [256, 3, 2]],
98 | [[-1, 37], 1, Concat, [1]],
99 |
100 | [-1, 1, Conv, [128, 1, 1]],
101 | [-2, 1, Conv, [128, 1, 1]],
102 | [-1, 1, Conv, [128, 3, 1]],
103 | [-1, 1, Conv, [128, 3, 1]],
104 | [[-1, -2, -3, -4], 1, Concat, [1]],
105 | [-1, 1, Conv, [256, 1, 1]], # 73
106 |
107 | [57, 1, Conv, [128, 3, 1]],
108 | [65, 1, Conv, [256, 3, 1]],
109 | [73, 1, Conv, [512, 3, 1]],
110 |
111 | [[74,75,76], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
112 | ]
113 |
--------------------------------------------------------------------------------
/yolov7/cfg/deploy/yolov7-tiny.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # yolov7-tiny backbone
13 | backbone:
14 | # [from, number, module, args] c2, k=1, s=1, p=None, g=1, act=True
15 | [[-1, 1, Conv, [32, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 0-P1/2
16 |
17 | [-1, 1, Conv, [64, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 1-P2/4
18 |
19 | [-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
20 | [-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
21 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
22 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
23 | [[-1, -2, -3, -4], 1, Concat, [1]],
24 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 7
25 |
26 | [-1, 1, MP, []], # 8-P3/8
27 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
28 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
29 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
30 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
31 | [[-1, -2, -3, -4], 1, Concat, [1]],
32 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 14
33 |
34 | [-1, 1, MP, []], # 15-P4/16
35 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
36 | [-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
37 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
38 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
39 | [[-1, -2, -3, -4], 1, Concat, [1]],
40 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 21
41 |
42 | [-1, 1, MP, []], # 22-P5/32
43 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
44 | [-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
45 | [-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
46 | [-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
47 | [[-1, -2, -3, -4], 1, Concat, [1]],
48 | [-1, 1, Conv, [512, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 28
49 | ]
50 |
51 | # yolov7-tiny head
52 | head:
53 | [[-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
54 | [-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
55 | [-1, 1, SP, [5]],
56 | [-2, 1, SP, [9]],
57 | [-3, 1, SP, [13]],
58 | [[-1, -2, -3, -4], 1, Concat, [1]],
59 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
60 | [[-1, -7], 1, Concat, [1]],
61 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 37
62 |
63 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
64 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
65 | [21, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P4
66 | [[-1, -2], 1, Concat, [1]],
67 |
68 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
69 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
70 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
71 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
72 | [[-1, -2, -3, -4], 1, Concat, [1]],
73 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 47
74 |
75 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
76 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
77 | [14, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P3
78 | [[-1, -2], 1, Concat, [1]],
79 |
80 | [-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
81 | [-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
82 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
83 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
84 | [[-1, -2, -3, -4], 1, Concat, [1]],
85 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 57
86 |
87 | [-1, 1, Conv, [128, 3, 2, None, 1, nn.LeakyReLU(0.1)]],
88 | [[-1, 47], 1, Concat, [1]],
89 |
90 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
91 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
92 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
93 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
94 | [[-1, -2, -3, -4], 1, Concat, [1]],
95 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 65
96 |
97 | [-1, 1, Conv, [256, 3, 2, None, 1, nn.LeakyReLU(0.1)]],
98 | [[-1, 37], 1, Concat, [1]],
99 |
100 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
101 | [-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
102 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
103 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
104 | [[-1, -2, -3, -4], 1, Concat, [1]],
105 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 73
106 |
107 | [57, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
108 | [65, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
109 | [73, 1, Conv, [512, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
110 |
111 | [[74,75,76], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
112 | ]
113 |
--------------------------------------------------------------------------------
/yolov7/cfg/deploy/yolov7-w6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # yolov7-w6 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [[-1, 1, ReOrg, []], # 0
17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2
18 |
19 | [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
20 | [-1, 1, Conv, [64, 1, 1]],
21 | [-2, 1, Conv, [64, 1, 1]],
22 | [-1, 1, Conv, [64, 3, 1]],
23 | [-1, 1, Conv, [64, 3, 1]],
24 | [-1, 1, Conv, [64, 3, 1]],
25 | [-1, 1, Conv, [64, 3, 1]],
26 | [[-1, -3, -5, -6], 1, Concat, [1]],
27 | [-1, 1, Conv, [128, 1, 1]], # 10
28 |
29 | [-1, 1, Conv, [256, 3, 2]], # 11-P3/8
30 | [-1, 1, Conv, [128, 1, 1]],
31 | [-2, 1, Conv, [128, 1, 1]],
32 | [-1, 1, Conv, [128, 3, 1]],
33 | [-1, 1, Conv, [128, 3, 1]],
34 | [-1, 1, Conv, [128, 3, 1]],
35 | [-1, 1, Conv, [128, 3, 1]],
36 | [[-1, -3, -5, -6], 1, Concat, [1]],
37 | [-1, 1, Conv, [256, 1, 1]], # 19
38 |
39 | [-1, 1, Conv, [512, 3, 2]], # 20-P4/16
40 | [-1, 1, Conv, [256, 1, 1]],
41 | [-2, 1, Conv, [256, 1, 1]],
42 | [-1, 1, Conv, [256, 3, 1]],
43 | [-1, 1, Conv, [256, 3, 1]],
44 | [-1, 1, Conv, [256, 3, 1]],
45 | [-1, 1, Conv, [256, 3, 1]],
46 | [[-1, -3, -5, -6], 1, Concat, [1]],
47 | [-1, 1, Conv, [512, 1, 1]], # 28
48 |
49 | [-1, 1, Conv, [768, 3, 2]], # 29-P5/32
50 | [-1, 1, Conv, [384, 1, 1]],
51 | [-2, 1, Conv, [384, 1, 1]],
52 | [-1, 1, Conv, [384, 3, 1]],
53 | [-1, 1, Conv, [384, 3, 1]],
54 | [-1, 1, Conv, [384, 3, 1]],
55 | [-1, 1, Conv, [384, 3, 1]],
56 | [[-1, -3, -5, -6], 1, Concat, [1]],
57 | [-1, 1, Conv, [768, 1, 1]], # 37
58 |
59 | [-1, 1, Conv, [1024, 3, 2]], # 38-P6/64
60 | [-1, 1, Conv, [512, 1, 1]],
61 | [-2, 1, Conv, [512, 1, 1]],
62 | [-1, 1, Conv, [512, 3, 1]],
63 | [-1, 1, Conv, [512, 3, 1]],
64 | [-1, 1, Conv, [512, 3, 1]],
65 | [-1, 1, Conv, [512, 3, 1]],
66 | [[-1, -3, -5, -6], 1, Concat, [1]],
67 | [-1, 1, Conv, [1024, 1, 1]], # 46
68 | ]
69 |
70 | # yolov7-w6 head
71 | head:
72 | [[-1, 1, SPPCSPC, [512]], # 47
73 |
74 | [-1, 1, Conv, [384, 1, 1]],
75 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
76 | [37, 1, Conv, [384, 1, 1]], # route backbone P5
77 | [[-1, -2], 1, Concat, [1]],
78 |
79 | [-1, 1, Conv, [384, 1, 1]],
80 | [-2, 1, Conv, [384, 1, 1]],
81 | [-1, 1, Conv, [192, 3, 1]],
82 | [-1, 1, Conv, [192, 3, 1]],
83 | [-1, 1, Conv, [192, 3, 1]],
84 | [-1, 1, Conv, [192, 3, 1]],
85 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
86 | [-1, 1, Conv, [384, 1, 1]], # 59
87 |
88 | [-1, 1, Conv, [256, 1, 1]],
89 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
90 | [28, 1, Conv, [256, 1, 1]], # route backbone P4
91 | [[-1, -2], 1, Concat, [1]],
92 |
93 | [-1, 1, Conv, [256, 1, 1]],
94 | [-2, 1, Conv, [256, 1, 1]],
95 | [-1, 1, Conv, [128, 3, 1]],
96 | [-1, 1, Conv, [128, 3, 1]],
97 | [-1, 1, Conv, [128, 3, 1]],
98 | [-1, 1, Conv, [128, 3, 1]],
99 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
100 | [-1, 1, Conv, [256, 1, 1]], # 71
101 |
102 | [-1, 1, Conv, [128, 1, 1]],
103 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
104 | [19, 1, Conv, [128, 1, 1]], # route backbone P3
105 | [[-1, -2], 1, Concat, [1]],
106 |
107 | [-1, 1, Conv, [128, 1, 1]],
108 | [-2, 1, Conv, [128, 1, 1]],
109 | [-1, 1, Conv, [64, 3, 1]],
110 | [-1, 1, Conv, [64, 3, 1]],
111 | [-1, 1, Conv, [64, 3, 1]],
112 | [-1, 1, Conv, [64, 3, 1]],
113 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
114 | [-1, 1, Conv, [128, 1, 1]], # 83
115 |
116 | [-1, 1, Conv, [256, 3, 2]],
117 | [[-1, 71], 1, Concat, [1]], # cat
118 |
119 | [-1, 1, Conv, [256, 1, 1]],
120 | [-2, 1, Conv, [256, 1, 1]],
121 | [-1, 1, Conv, [128, 3, 1]],
122 | [-1, 1, Conv, [128, 3, 1]],
123 | [-1, 1, Conv, [128, 3, 1]],
124 | [-1, 1, Conv, [128, 3, 1]],
125 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
126 | [-1, 1, Conv, [256, 1, 1]], # 93
127 |
128 | [-1, 1, Conv, [384, 3, 2]],
129 | [[-1, 59], 1, Concat, [1]], # cat
130 |
131 | [-1, 1, Conv, [384, 1, 1]],
132 | [-2, 1, Conv, [384, 1, 1]],
133 | [-1, 1, Conv, [192, 3, 1]],
134 | [-1, 1, Conv, [192, 3, 1]],
135 | [-1, 1, Conv, [192, 3, 1]],
136 | [-1, 1, Conv, [192, 3, 1]],
137 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
138 | [-1, 1, Conv, [384, 1, 1]], # 103
139 |
140 | [-1, 1, Conv, [512, 3, 2]],
141 | [[-1, 47], 1, Concat, [1]], # cat
142 |
143 | [-1, 1, Conv, [512, 1, 1]],
144 | [-2, 1, Conv, [512, 1, 1]],
145 | [-1, 1, Conv, [256, 3, 1]],
146 | [-1, 1, Conv, [256, 3, 1]],
147 | [-1, 1, Conv, [256, 3, 1]],
148 | [-1, 1, Conv, [256, 3, 1]],
149 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
150 | [-1, 1, Conv, [512, 1, 1]], # 113
151 |
152 | [83, 1, Conv, [256, 3, 1]],
153 | [93, 1, Conv, [512, 3, 1]],
154 | [103, 1, Conv, [768, 3, 1]],
155 | [113, 1, Conv, [1024, 3, 1]],
156 |
157 | [[114,115,116,117], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5, P6)
158 | ]
159 |
--------------------------------------------------------------------------------
/yolov7/cfg/deploy/yolov7.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [12,16, 19,36, 40,28] # P3/8
9 | - [36,75, 76,55, 72,146] # P4/16
10 | - [142,110, 192,243, 459,401] # P5/32
11 |
12 | # yolov7 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [32, 3, 1]], # 0
16 |
17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2
18 | [-1, 1, Conv, [64, 3, 1]],
19 |
20 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4
21 | [-1, 1, Conv, [64, 1, 1]],
22 | [-2, 1, Conv, [64, 1, 1]],
23 | [-1, 1, Conv, [64, 3, 1]],
24 | [-1, 1, Conv, [64, 3, 1]],
25 | [-1, 1, Conv, [64, 3, 1]],
26 | [-1, 1, Conv, [64, 3, 1]],
27 | [[-1, -3, -5, -6], 1, Concat, [1]],
28 | [-1, 1, Conv, [256, 1, 1]], # 11
29 |
30 | [-1, 1, MP, []],
31 | [-1, 1, Conv, [128, 1, 1]],
32 | [-3, 1, Conv, [128, 1, 1]],
33 | [-1, 1, Conv, [128, 3, 2]],
34 | [[-1, -3], 1, Concat, [1]], # 16-P3/8
35 | [-1, 1, Conv, [128, 1, 1]],
36 | [-2, 1, Conv, [128, 1, 1]],
37 | [-1, 1, Conv, [128, 3, 1]],
38 | [-1, 1, Conv, [128, 3, 1]],
39 | [-1, 1, Conv, [128, 3, 1]],
40 | [-1, 1, Conv, [128, 3, 1]],
41 | [[-1, -3, -5, -6], 1, Concat, [1]],
42 | [-1, 1, Conv, [512, 1, 1]], # 24
43 |
44 | [-1, 1, MP, []],
45 | [-1, 1, Conv, [256, 1, 1]],
46 | [-3, 1, Conv, [256, 1, 1]],
47 | [-1, 1, Conv, [256, 3, 2]],
48 | [[-1, -3], 1, Concat, [1]], # 29-P4/16
49 | [-1, 1, Conv, [256, 1, 1]],
50 | [-2, 1, Conv, [256, 1, 1]],
51 | [-1, 1, Conv, [256, 3, 1]],
52 | [-1, 1, Conv, [256, 3, 1]],
53 | [-1, 1, Conv, [256, 3, 1]],
54 | [-1, 1, Conv, [256, 3, 1]],
55 | [[-1, -3, -5, -6], 1, Concat, [1]],
56 | [-1, 1, Conv, [1024, 1, 1]], # 37
57 |
58 | [-1, 1, MP, []],
59 | [-1, 1, Conv, [512, 1, 1]],
60 | [-3, 1, Conv, [512, 1, 1]],
61 | [-1, 1, Conv, [512, 3, 2]],
62 | [[-1, -3], 1, Concat, [1]], # 42-P5/32
63 | [-1, 1, Conv, [256, 1, 1]],
64 | [-2, 1, Conv, [256, 1, 1]],
65 | [-1, 1, Conv, [256, 3, 1]],
66 | [-1, 1, Conv, [256, 3, 1]],
67 | [-1, 1, Conv, [256, 3, 1]],
68 | [-1, 1, Conv, [256, 3, 1]],
69 | [[-1, -3, -5, -6], 1, Concat, [1]],
70 | [-1, 1, Conv, [1024, 1, 1]], # 50
71 | ]
72 |
73 | # yolov7 head
74 | head:
75 | [[-1, 1, SPPCSPC, [512]], # 51
76 |
77 | [-1, 1, Conv, [256, 1, 1]],
78 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
79 | [37, 1, Conv, [256, 1, 1]], # route backbone P4
80 | [[-1, -2], 1, Concat, [1]],
81 |
82 | [-1, 1, Conv, [256, 1, 1]],
83 | [-2, 1, Conv, [256, 1, 1]],
84 | [-1, 1, Conv, [128, 3, 1]],
85 | [-1, 1, Conv, [128, 3, 1]],
86 | [-1, 1, Conv, [128, 3, 1]],
87 | [-1, 1, Conv, [128, 3, 1]],
88 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
89 | [-1, 1, Conv, [256, 1, 1]], # 63
90 |
91 | [-1, 1, Conv, [128, 1, 1]],
92 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
93 | [24, 1, Conv, [128, 1, 1]], # route backbone P3
94 | [[-1, -2], 1, Concat, [1]],
95 |
96 | [-1, 1, Conv, [128, 1, 1]],
97 | [-2, 1, Conv, [128, 1, 1]],
98 | [-1, 1, Conv, [64, 3, 1]],
99 | [-1, 1, Conv, [64, 3, 1]],
100 | [-1, 1, Conv, [64, 3, 1]],
101 | [-1, 1, Conv, [64, 3, 1]],
102 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
103 | [-1, 1, Conv, [128, 1, 1]], # 75
104 |
105 | [-1, 1, MP, []],
106 | [-1, 1, Conv, [128, 1, 1]],
107 | [-3, 1, Conv, [128, 1, 1]],
108 | [-1, 1, Conv, [128, 3, 2]],
109 | [[-1, -3, 63], 1, Concat, [1]],
110 |
111 | [-1, 1, Conv, [256, 1, 1]],
112 | [-2, 1, Conv, [256, 1, 1]],
113 | [-1, 1, Conv, [128, 3, 1]],
114 | [-1, 1, Conv, [128, 3, 1]],
115 | [-1, 1, Conv, [128, 3, 1]],
116 | [-1, 1, Conv, [128, 3, 1]],
117 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
118 | [-1, 1, Conv, [256, 1, 1]], # 88
119 |
120 | [-1, 1, MP, []],
121 | [-1, 1, Conv, [256, 1, 1]],
122 | [-3, 1, Conv, [256, 1, 1]],
123 | [-1, 1, Conv, [256, 3, 2]],
124 | [[-1, -3, 51], 1, Concat, [1]],
125 |
126 | [-1, 1, Conv, [512, 1, 1]],
127 | [-2, 1, Conv, [512, 1, 1]],
128 | [-1, 1, Conv, [256, 3, 1]],
129 | [-1, 1, Conv, [256, 3, 1]],
130 | [-1, 1, Conv, [256, 3, 1]],
131 | [-1, 1, Conv, [256, 3, 1]],
132 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
133 | [-1, 1, Conv, [512, 1, 1]], # 101
134 |
135 | [75, 1, RepConv, [256, 3, 1]],
136 | [88, 1, RepConv, [512, 3, 1]],
137 | [101, 1, RepConv, [1024, 3, 1]],
138 |
139 | [[102,103,104], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
140 | ]
141 |
--------------------------------------------------------------------------------
/yolov7/cfg/deploy/yolov7x.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [12,16, 19,36, 40,28] # P3/8
9 | - [36,75, 76,55, 72,146] # P4/16
10 | - [142,110, 192,243, 459,401] # P5/32
11 |
12 | # yolov7x backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [40, 3, 1]], # 0
16 |
17 | [-1, 1, Conv, [80, 3, 2]], # 1-P1/2
18 | [-1, 1, Conv, [80, 3, 1]],
19 |
20 | [-1, 1, Conv, [160, 3, 2]], # 3-P2/4
21 | [-1, 1, Conv, [64, 1, 1]],
22 | [-2, 1, Conv, [64, 1, 1]],
23 | [-1, 1, Conv, [64, 3, 1]],
24 | [-1, 1, Conv, [64, 3, 1]],
25 | [-1, 1, Conv, [64, 3, 1]],
26 | [-1, 1, Conv, [64, 3, 1]],
27 | [-1, 1, Conv, [64, 3, 1]],
28 | [-1, 1, Conv, [64, 3, 1]],
29 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
30 | [-1, 1, Conv, [320, 1, 1]], # 13
31 |
32 | [-1, 1, MP, []],
33 | [-1, 1, Conv, [160, 1, 1]],
34 | [-3, 1, Conv, [160, 1, 1]],
35 | [-1, 1, Conv, [160, 3, 2]],
36 | [[-1, -3], 1, Concat, [1]], # 18-P3/8
37 | [-1, 1, Conv, [128, 1, 1]],
38 | [-2, 1, Conv, [128, 1, 1]],
39 | [-1, 1, Conv, [128, 3, 1]],
40 | [-1, 1, Conv, [128, 3, 1]],
41 | [-1, 1, Conv, [128, 3, 1]],
42 | [-1, 1, Conv, [128, 3, 1]],
43 | [-1, 1, Conv, [128, 3, 1]],
44 | [-1, 1, Conv, [128, 3, 1]],
45 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
46 | [-1, 1, Conv, [640, 1, 1]], # 28
47 |
48 | [-1, 1, MP, []],
49 | [-1, 1, Conv, [320, 1, 1]],
50 | [-3, 1, Conv, [320, 1, 1]],
51 | [-1, 1, Conv, [320, 3, 2]],
52 | [[-1, -3], 1, Concat, [1]], # 33-P4/16
53 | [-1, 1, Conv, [256, 1, 1]],
54 | [-2, 1, Conv, [256, 1, 1]],
55 | [-1, 1, Conv, [256, 3, 1]],
56 | [-1, 1, Conv, [256, 3, 1]],
57 | [-1, 1, Conv, [256, 3, 1]],
58 | [-1, 1, Conv, [256, 3, 1]],
59 | [-1, 1, Conv, [256, 3, 1]],
60 | [-1, 1, Conv, [256, 3, 1]],
61 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
62 | [-1, 1, Conv, [1280, 1, 1]], # 43
63 |
64 | [-1, 1, MP, []],
65 | [-1, 1, Conv, [640, 1, 1]],
66 | [-3, 1, Conv, [640, 1, 1]],
67 | [-1, 1, Conv, [640, 3, 2]],
68 | [[-1, -3], 1, Concat, [1]], # 48-P5/32
69 | [-1, 1, Conv, [256, 1, 1]],
70 | [-2, 1, Conv, [256, 1, 1]],
71 | [-1, 1, Conv, [256, 3, 1]],
72 | [-1, 1, Conv, [256, 3, 1]],
73 | [-1, 1, Conv, [256, 3, 1]],
74 | [-1, 1, Conv, [256, 3, 1]],
75 | [-1, 1, Conv, [256, 3, 1]],
76 | [-1, 1, Conv, [256, 3, 1]],
77 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
78 | [-1, 1, Conv, [1280, 1, 1]], # 58
79 | ]
80 |
81 | # yolov7x head
82 | head:
83 | [[-1, 1, SPPCSPC, [640]], # 59
84 |
85 | [-1, 1, Conv, [320, 1, 1]],
86 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
87 | [43, 1, Conv, [320, 1, 1]], # route backbone P4
88 | [[-1, -2], 1, Concat, [1]],
89 |
90 | [-1, 1, Conv, [256, 1, 1]],
91 | [-2, 1, Conv, [256, 1, 1]],
92 | [-1, 1, Conv, [256, 3, 1]],
93 | [-1, 1, Conv, [256, 3, 1]],
94 | [-1, 1, Conv, [256, 3, 1]],
95 | [-1, 1, Conv, [256, 3, 1]],
96 | [-1, 1, Conv, [256, 3, 1]],
97 | [-1, 1, Conv, [256, 3, 1]],
98 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
99 | [-1, 1, Conv, [320, 1, 1]], # 73
100 |
101 | [-1, 1, Conv, [160, 1, 1]],
102 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
103 | [28, 1, Conv, [160, 1, 1]], # route backbone P3
104 | [[-1, -2], 1, Concat, [1]],
105 |
106 | [-1, 1, Conv, [128, 1, 1]],
107 | [-2, 1, Conv, [128, 1, 1]],
108 | [-1, 1, Conv, [128, 3, 1]],
109 | [-1, 1, Conv, [128, 3, 1]],
110 | [-1, 1, Conv, [128, 3, 1]],
111 | [-1, 1, Conv, [128, 3, 1]],
112 | [-1, 1, Conv, [128, 3, 1]],
113 | [-1, 1, Conv, [128, 3, 1]],
114 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
115 | [-1, 1, Conv, [160, 1, 1]], # 87
116 |
117 | [-1, 1, MP, []],
118 | [-1, 1, Conv, [160, 1, 1]],
119 | [-3, 1, Conv, [160, 1, 1]],
120 | [-1, 1, Conv, [160, 3, 2]],
121 | [[-1, -3, 73], 1, Concat, [1]],
122 |
123 | [-1, 1, Conv, [256, 1, 1]],
124 | [-2, 1, Conv, [256, 1, 1]],
125 | [-1, 1, Conv, [256, 3, 1]],
126 | [-1, 1, Conv, [256, 3, 1]],
127 | [-1, 1, Conv, [256, 3, 1]],
128 | [-1, 1, Conv, [256, 3, 1]],
129 | [-1, 1, Conv, [256, 3, 1]],
130 | [-1, 1, Conv, [256, 3, 1]],
131 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
132 | [-1, 1, Conv, [320, 1, 1]], # 102
133 |
134 | [-1, 1, MP, []],
135 | [-1, 1, Conv, [320, 1, 1]],
136 | [-3, 1, Conv, [320, 1, 1]],
137 | [-1, 1, Conv, [320, 3, 2]],
138 | [[-1, -3, 59], 1, Concat, [1]],
139 |
140 | [-1, 1, Conv, [512, 1, 1]],
141 | [-2, 1, Conv, [512, 1, 1]],
142 | [-1, 1, Conv, [512, 3, 1]],
143 | [-1, 1, Conv, [512, 3, 1]],
144 | [-1, 1, Conv, [512, 3, 1]],
145 | [-1, 1, Conv, [512, 3, 1]],
146 | [-1, 1, Conv, [512, 3, 1]],
147 | [-1, 1, Conv, [512, 3, 1]],
148 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
149 | [-1, 1, Conv, [640, 1, 1]], # 117
150 |
151 | [87, 1, Conv, [320, 3, 1]],
152 | [102, 1, Conv, [640, 3, 1]],
153 | [117, 1, Conv, [1280, 3, 1]],
154 |
155 | [[118,119,120], 1, Detect, [nc, anchors]], # Detect(P3, P4, P5)
156 | ]
157 |
--------------------------------------------------------------------------------
/yolov7/cfg/training/yolov7-d6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # yolov7 backbone
14 | backbone:
15 | # [from, number, module, args],
16 | [[-1, 1, ReOrg, []], # 0
17 | [-1, 1, Conv, [96, 3, 1]], # 1-P1/2
18 |
19 | [-1, 1, DownC, [192]], # 2-P2/4
20 | [-1, 1, Conv, [64, 1, 1]],
21 | [-2, 1, Conv, [64, 1, 1]],
22 | [-1, 1, Conv, [64, 3, 1]],
23 | [-1, 1, Conv, [64, 3, 1]],
24 | [-1, 1, Conv, [64, 3, 1]],
25 | [-1, 1, Conv, [64, 3, 1]],
26 | [-1, 1, Conv, [64, 3, 1]],
27 | [-1, 1, Conv, [64, 3, 1]],
28 | [-1, 1, Conv, [64, 3, 1]],
29 | [-1, 1, Conv, [64, 3, 1]],
30 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]],
31 | [-1, 1, Conv, [192, 1, 1]], # 14
32 |
33 | [-1, 1, DownC, [384]], # 15-P3/8
34 | [-1, 1, Conv, [128, 1, 1]],
35 | [-2, 1, Conv, [128, 1, 1]],
36 | [-1, 1, Conv, [128, 3, 1]],
37 | [-1, 1, Conv, [128, 3, 1]],
38 | [-1, 1, Conv, [128, 3, 1]],
39 | [-1, 1, Conv, [128, 3, 1]],
40 | [-1, 1, Conv, [128, 3, 1]],
41 | [-1, 1, Conv, [128, 3, 1]],
42 | [-1, 1, Conv, [128, 3, 1]],
43 | [-1, 1, Conv, [128, 3, 1]],
44 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]],
45 | [-1, 1, Conv, [384, 1, 1]], # 27
46 |
47 | [-1, 1, DownC, [768]], # 28-P4/16
48 | [-1, 1, Conv, [256, 1, 1]],
49 | [-2, 1, Conv, [256, 1, 1]],
50 | [-1, 1, Conv, [256, 3, 1]],
51 | [-1, 1, Conv, [256, 3, 1]],
52 | [-1, 1, Conv, [256, 3, 1]],
53 | [-1, 1, Conv, [256, 3, 1]],
54 | [-1, 1, Conv, [256, 3, 1]],
55 | [-1, 1, Conv, [256, 3, 1]],
56 | [-1, 1, Conv, [256, 3, 1]],
57 | [-1, 1, Conv, [256, 3, 1]],
58 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]],
59 | [-1, 1, Conv, [768, 1, 1]], # 40
60 |
61 | [-1, 1, DownC, [1152]], # 41-P5/32
62 | [-1, 1, Conv, [384, 1, 1]],
63 | [-2, 1, Conv, [384, 1, 1]],
64 | [-1, 1, Conv, [384, 3, 1]],
65 | [-1, 1, Conv, [384, 3, 1]],
66 | [-1, 1, Conv, [384, 3, 1]],
67 | [-1, 1, Conv, [384, 3, 1]],
68 | [-1, 1, Conv, [384, 3, 1]],
69 | [-1, 1, Conv, [384, 3, 1]],
70 | [-1, 1, Conv, [384, 3, 1]],
71 | [-1, 1, Conv, [384, 3, 1]],
72 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]],
73 | [-1, 1, Conv, [1152, 1, 1]], # 53
74 |
75 | [-1, 1, DownC, [1536]], # 54-P6/64
76 | [-1, 1, Conv, [512, 1, 1]],
77 | [-2, 1, Conv, [512, 1, 1]],
78 | [-1, 1, Conv, [512, 3, 1]],
79 | [-1, 1, Conv, [512, 3, 1]],
80 | [-1, 1, Conv, [512, 3, 1]],
81 | [-1, 1, Conv, [512, 3, 1]],
82 | [-1, 1, Conv, [512, 3, 1]],
83 | [-1, 1, Conv, [512, 3, 1]],
84 | [-1, 1, Conv, [512, 3, 1]],
85 | [-1, 1, Conv, [512, 3, 1]],
86 | [[-1, -3, -5, -7, -9, -10], 1, Concat, [1]],
87 | [-1, 1, Conv, [1536, 1, 1]], # 66
88 | ]
89 |
90 | # yolov7 head
91 | head:
92 | [[-1, 1, SPPCSPC, [768]], # 67
93 |
94 | [-1, 1, Conv, [576, 1, 1]],
95 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
96 | [53, 1, Conv, [576, 1, 1]], # route backbone P5
97 | [[-1, -2], 1, Concat, [1]],
98 |
99 | [-1, 1, Conv, [384, 1, 1]],
100 | [-2, 1, Conv, [384, 1, 1]],
101 | [-1, 1, Conv, [192, 3, 1]],
102 | [-1, 1, Conv, [192, 3, 1]],
103 | [-1, 1, Conv, [192, 3, 1]],
104 | [-1, 1, Conv, [192, 3, 1]],
105 | [-1, 1, Conv, [192, 3, 1]],
106 | [-1, 1, Conv, [192, 3, 1]],
107 | [-1, 1, Conv, [192, 3, 1]],
108 | [-1, 1, Conv, [192, 3, 1]],
109 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
110 | [-1, 1, Conv, [576, 1, 1]], # 83
111 |
112 | [-1, 1, Conv, [384, 1, 1]],
113 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
114 | [40, 1, Conv, [384, 1, 1]], # route backbone P4
115 | [[-1, -2], 1, Concat, [1]],
116 |
117 | [-1, 1, Conv, [256, 1, 1]],
118 | [-2, 1, Conv, [256, 1, 1]],
119 | [-1, 1, Conv, [128, 3, 1]],
120 | [-1, 1, Conv, [128, 3, 1]],
121 | [-1, 1, Conv, [128, 3, 1]],
122 | [-1, 1, Conv, [128, 3, 1]],
123 | [-1, 1, Conv, [128, 3, 1]],
124 | [-1, 1, Conv, [128, 3, 1]],
125 | [-1, 1, Conv, [128, 3, 1]],
126 | [-1, 1, Conv, [128, 3, 1]],
127 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
128 | [-1, 1, Conv, [384, 1, 1]], # 99
129 |
130 | [-1, 1, Conv, [192, 1, 1]],
131 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
132 | [27, 1, Conv, [192, 1, 1]], # route backbone P3
133 | [[-1, -2], 1, Concat, [1]],
134 |
135 | [-1, 1, Conv, [128, 1, 1]],
136 | [-2, 1, Conv, [128, 1, 1]],
137 | [-1, 1, Conv, [64, 3, 1]],
138 | [-1, 1, Conv, [64, 3, 1]],
139 | [-1, 1, Conv, [64, 3, 1]],
140 | [-1, 1, Conv, [64, 3, 1]],
141 | [-1, 1, Conv, [64, 3, 1]],
142 | [-1, 1, Conv, [64, 3, 1]],
143 | [-1, 1, Conv, [64, 3, 1]],
144 | [-1, 1, Conv, [64, 3, 1]],
145 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
146 | [-1, 1, Conv, [192, 1, 1]], # 115
147 |
148 | [-1, 1, DownC, [384]],
149 | [[-1, 99], 1, Concat, [1]],
150 |
151 | [-1, 1, Conv, [256, 1, 1]],
152 | [-2, 1, Conv, [256, 1, 1]],
153 | [-1, 1, Conv, [128, 3, 1]],
154 | [-1, 1, Conv, [128, 3, 1]],
155 | [-1, 1, Conv, [128, 3, 1]],
156 | [-1, 1, Conv, [128, 3, 1]],
157 | [-1, 1, Conv, [128, 3, 1]],
158 | [-1, 1, Conv, [128, 3, 1]],
159 | [-1, 1, Conv, [128, 3, 1]],
160 | [-1, 1, Conv, [128, 3, 1]],
161 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
162 | [-1, 1, Conv, [384, 1, 1]], # 129
163 |
164 | [-1, 1, DownC, [576]],
165 | [[-1, 83], 1, Concat, [1]],
166 |
167 | [-1, 1, Conv, [384, 1, 1]],
168 | [-2, 1, Conv, [384, 1, 1]],
169 | [-1, 1, Conv, [192, 3, 1]],
170 | [-1, 1, Conv, [192, 3, 1]],
171 | [-1, 1, Conv, [192, 3, 1]],
172 | [-1, 1, Conv, [192, 3, 1]],
173 | [-1, 1, Conv, [192, 3, 1]],
174 | [-1, 1, Conv, [192, 3, 1]],
175 | [-1, 1, Conv, [192, 3, 1]],
176 | [-1, 1, Conv, [192, 3, 1]],
177 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
178 | [-1, 1, Conv, [576, 1, 1]], # 143
179 |
180 | [-1, 1, DownC, [768]],
181 | [[-1, 67], 1, Concat, [1]],
182 |
183 | [-1, 1, Conv, [512, 1, 1]],
184 | [-2, 1, Conv, [512, 1, 1]],
185 | [-1, 1, Conv, [256, 3, 1]],
186 | [-1, 1, Conv, [256, 3, 1]],
187 | [-1, 1, Conv, [256, 3, 1]],
188 | [-1, 1, Conv, [256, 3, 1]],
189 | [-1, 1, Conv, [256, 3, 1]],
190 | [-1, 1, Conv, [256, 3, 1]],
191 | [-1, 1, Conv, [256, 3, 1]],
192 | [-1, 1, Conv, [256, 3, 1]],
193 | [[-1, -2, -3, -4, -5, -6, -7, -8, -9, -10], 1, Concat, [1]],
194 | [-1, 1, Conv, [768, 1, 1]], # 157
195 |
196 | [115, 1, Conv, [384, 3, 1]],
197 | [129, 1, Conv, [768, 3, 1]],
198 | [143, 1, Conv, [1152, 3, 1]],
199 | [157, 1, Conv, [1536, 3, 1]],
200 |
201 | [115, 1, Conv, [384, 3, 1]],
202 | [99, 1, Conv, [768, 3, 1]],
203 | [83, 1, Conv, [1152, 3, 1]],
204 | [67, 1, Conv, [1536, 3, 1]],
205 |
206 | [[158,159,160,161,162,163,164,165], 1, IAuxDetect, [nc, anchors]], # Detect(P3, P4, P5, P6)
207 | ]
208 |
--------------------------------------------------------------------------------
/yolov7/cfg/training/yolov7-e6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # yolov7 backbone
14 | backbone:
15 | # [from, number, module, args],
16 | [[-1, 1, ReOrg, []], # 0
17 | [-1, 1, Conv, [80, 3, 1]], # 1-P1/2
18 |
19 | [-1, 1, DownC, [160]], # 2-P2/4
20 | [-1, 1, Conv, [64, 1, 1]],
21 | [-2, 1, Conv, [64, 1, 1]],
22 | [-1, 1, Conv, [64, 3, 1]],
23 | [-1, 1, Conv, [64, 3, 1]],
24 | [-1, 1, Conv, [64, 3, 1]],
25 | [-1, 1, Conv, [64, 3, 1]],
26 | [-1, 1, Conv, [64, 3, 1]],
27 | [-1, 1, Conv, [64, 3, 1]],
28 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
29 | [-1, 1, Conv, [160, 1, 1]], # 12
30 |
31 | [-1, 1, DownC, [320]], # 13-P3/8
32 | [-1, 1, Conv, [128, 1, 1]],
33 | [-2, 1, Conv, [128, 1, 1]],
34 | [-1, 1, Conv, [128, 3, 1]],
35 | [-1, 1, Conv, [128, 3, 1]],
36 | [-1, 1, Conv, [128, 3, 1]],
37 | [-1, 1, Conv, [128, 3, 1]],
38 | [-1, 1, Conv, [128, 3, 1]],
39 | [-1, 1, Conv, [128, 3, 1]],
40 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
41 | [-1, 1, Conv, [320, 1, 1]], # 23
42 |
43 | [-1, 1, DownC, [640]], # 24-P4/16
44 | [-1, 1, Conv, [256, 1, 1]],
45 | [-2, 1, Conv, [256, 1, 1]],
46 | [-1, 1, Conv, [256, 3, 1]],
47 | [-1, 1, Conv, [256, 3, 1]],
48 | [-1, 1, Conv, [256, 3, 1]],
49 | [-1, 1, Conv, [256, 3, 1]],
50 | [-1, 1, Conv, [256, 3, 1]],
51 | [-1, 1, Conv, [256, 3, 1]],
52 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
53 | [-1, 1, Conv, [640, 1, 1]], # 34
54 |
55 | [-1, 1, DownC, [960]], # 35-P5/32
56 | [-1, 1, Conv, [384, 1, 1]],
57 | [-2, 1, Conv, [384, 1, 1]],
58 | [-1, 1, Conv, [384, 3, 1]],
59 | [-1, 1, Conv, [384, 3, 1]],
60 | [-1, 1, Conv, [384, 3, 1]],
61 | [-1, 1, Conv, [384, 3, 1]],
62 | [-1, 1, Conv, [384, 3, 1]],
63 | [-1, 1, Conv, [384, 3, 1]],
64 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
65 | [-1, 1, Conv, [960, 1, 1]], # 45
66 |
67 | [-1, 1, DownC, [1280]], # 46-P6/64
68 | [-1, 1, Conv, [512, 1, 1]],
69 | [-2, 1, Conv, [512, 1, 1]],
70 | [-1, 1, Conv, [512, 3, 1]],
71 | [-1, 1, Conv, [512, 3, 1]],
72 | [-1, 1, Conv, [512, 3, 1]],
73 | [-1, 1, Conv, [512, 3, 1]],
74 | [-1, 1, Conv, [512, 3, 1]],
75 | [-1, 1, Conv, [512, 3, 1]],
76 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
77 | [-1, 1, Conv, [1280, 1, 1]], # 56
78 | ]
79 |
80 | # yolov7 head
81 | head:
82 | [[-1, 1, SPPCSPC, [640]], # 57
83 |
84 | [-1, 1, Conv, [480, 1, 1]],
85 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
86 | [45, 1, Conv, [480, 1, 1]], # route backbone P5
87 | [[-1, -2], 1, Concat, [1]],
88 |
89 | [-1, 1, Conv, [384, 1, 1]],
90 | [-2, 1, Conv, [384, 1, 1]],
91 | [-1, 1, Conv, [192, 3, 1]],
92 | [-1, 1, Conv, [192, 3, 1]],
93 | [-1, 1, Conv, [192, 3, 1]],
94 | [-1, 1, Conv, [192, 3, 1]],
95 | [-1, 1, Conv, [192, 3, 1]],
96 | [-1, 1, Conv, [192, 3, 1]],
97 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
98 | [-1, 1, Conv, [480, 1, 1]], # 71
99 |
100 | [-1, 1, Conv, [320, 1, 1]],
101 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
102 | [34, 1, Conv, [320, 1, 1]], # route backbone P4
103 | [[-1, -2], 1, Concat, [1]],
104 |
105 | [-1, 1, Conv, [256, 1, 1]],
106 | [-2, 1, Conv, [256, 1, 1]],
107 | [-1, 1, Conv, [128, 3, 1]],
108 | [-1, 1, Conv, [128, 3, 1]],
109 | [-1, 1, Conv, [128, 3, 1]],
110 | [-1, 1, Conv, [128, 3, 1]],
111 | [-1, 1, Conv, [128, 3, 1]],
112 | [-1, 1, Conv, [128, 3, 1]],
113 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
114 | [-1, 1, Conv, [320, 1, 1]], # 85
115 |
116 | [-1, 1, Conv, [160, 1, 1]],
117 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
118 | [23, 1, Conv, [160, 1, 1]], # route backbone P3
119 | [[-1, -2], 1, Concat, [1]],
120 |
121 | [-1, 1, Conv, [128, 1, 1]],
122 | [-2, 1, Conv, [128, 1, 1]],
123 | [-1, 1, Conv, [64, 3, 1]],
124 | [-1, 1, Conv, [64, 3, 1]],
125 | [-1, 1, Conv, [64, 3, 1]],
126 | [-1, 1, Conv, [64, 3, 1]],
127 | [-1, 1, Conv, [64, 3, 1]],
128 | [-1, 1, Conv, [64, 3, 1]],
129 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
130 | [-1, 1, Conv, [160, 1, 1]], # 99
131 |
132 | [-1, 1, DownC, [320]],
133 | [[-1, 85], 1, Concat, [1]],
134 |
135 | [-1, 1, Conv, [256, 1, 1]],
136 | [-2, 1, Conv, [256, 1, 1]],
137 | [-1, 1, Conv, [128, 3, 1]],
138 | [-1, 1, Conv, [128, 3, 1]],
139 | [-1, 1, Conv, [128, 3, 1]],
140 | [-1, 1, Conv, [128, 3, 1]],
141 | [-1, 1, Conv, [128, 3, 1]],
142 | [-1, 1, Conv, [128, 3, 1]],
143 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
144 | [-1, 1, Conv, [320, 1, 1]], # 111
145 |
146 | [-1, 1, DownC, [480]],
147 | [[-1, 71], 1, Concat, [1]],
148 |
149 | [-1, 1, Conv, [384, 1, 1]],
150 | [-2, 1, Conv, [384, 1, 1]],
151 | [-1, 1, Conv, [192, 3, 1]],
152 | [-1, 1, Conv, [192, 3, 1]],
153 | [-1, 1, Conv, [192, 3, 1]],
154 | [-1, 1, Conv, [192, 3, 1]],
155 | [-1, 1, Conv, [192, 3, 1]],
156 | [-1, 1, Conv, [192, 3, 1]],
157 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
158 | [-1, 1, Conv, [480, 1, 1]], # 123
159 |
160 | [-1, 1, DownC, [640]],
161 | [[-1, 57], 1, Concat, [1]],
162 |
163 | [-1, 1, Conv, [512, 1, 1]],
164 | [-2, 1, Conv, [512, 1, 1]],
165 | [-1, 1, Conv, [256, 3, 1]],
166 | [-1, 1, Conv, [256, 3, 1]],
167 | [-1, 1, Conv, [256, 3, 1]],
168 | [-1, 1, Conv, [256, 3, 1]],
169 | [-1, 1, Conv, [256, 3, 1]],
170 | [-1, 1, Conv, [256, 3, 1]],
171 | [[-1, -2, -3, -4, -5, -6, -7, -8], 1, Concat, [1]],
172 | [-1, 1, Conv, [640, 1, 1]], # 135
173 |
174 | [99, 1, Conv, [320, 3, 1]],
175 | [111, 1, Conv, [640, 3, 1]],
176 | [123, 1, Conv, [960, 3, 1]],
177 | [135, 1, Conv, [1280, 3, 1]],
178 |
179 | [99, 1, Conv, [320, 3, 1]],
180 | [85, 1, Conv, [640, 3, 1]],
181 | [71, 1, Conv, [960, 3, 1]],
182 | [57, 1, Conv, [1280, 3, 1]],
183 |
184 | [[136,137,138,139,140,141,142,143], 1, IAuxDetect, [nc, anchors]], # Detect(P3, P4, P5, P6)
185 | ]
186 |
--------------------------------------------------------------------------------
/yolov7/cfg/training/yolov7-tiny.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [10,13, 16,30, 33,23] # P3/8
9 | - [30,61, 62,45, 59,119] # P4/16
10 | - [116,90, 156,198, 373,326] # P5/32
11 |
12 | # yolov7-tiny backbone
13 | backbone:
14 | # [from, number, module, args] c2, k=1, s=1, p=None, g=1, act=True
15 | [[-1, 1, Conv, [32, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 0-P1/2
16 |
17 | [-1, 1, Conv, [64, 3, 2, None, 1, nn.LeakyReLU(0.1)]], # 1-P2/4
18 |
19 | [-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
20 | [-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
21 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
22 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
23 | [[-1, -2, -3, -4], 1, Concat, [1]],
24 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 7
25 |
26 | [-1, 1, MP, []], # 8-P3/8
27 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
28 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
29 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
30 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
31 | [[-1, -2, -3, -4], 1, Concat, [1]],
32 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 14
33 |
34 | [-1, 1, MP, []], # 15-P4/16
35 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
36 | [-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
37 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
38 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
39 | [[-1, -2, -3, -4], 1, Concat, [1]],
40 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 21
41 |
42 | [-1, 1, MP, []], # 22-P5/32
43 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
44 | [-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
45 | [-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
46 | [-1, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
47 | [[-1, -2, -3, -4], 1, Concat, [1]],
48 | [-1, 1, Conv, [512, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 28
49 | ]
50 |
51 | # yolov7-tiny head
52 | head:
53 | [[-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
54 | [-2, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
55 | [-1, 1, SP, [5]],
56 | [-2, 1, SP, [9]],
57 | [-3, 1, SP, [13]],
58 | [[-1, -2, -3, -4], 1, Concat, [1]],
59 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
60 | [[-1, -7], 1, Concat, [1]],
61 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 37
62 |
63 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
64 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
65 | [21, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P4
66 | [[-1, -2], 1, Concat, [1]],
67 |
68 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
69 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
70 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
71 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
72 | [[-1, -2, -3, -4], 1, Concat, [1]],
73 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 47
74 |
75 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
76 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
77 | [14, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # route backbone P3
78 | [[-1, -2], 1, Concat, [1]],
79 |
80 | [-1, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
81 | [-2, 1, Conv, [32, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
82 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
83 | [-1, 1, Conv, [32, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
84 | [[-1, -2, -3, -4], 1, Concat, [1]],
85 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 57
86 |
87 | [-1, 1, Conv, [128, 3, 2, None, 1, nn.LeakyReLU(0.1)]],
88 | [[-1, 47], 1, Concat, [1]],
89 |
90 | [-1, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
91 | [-2, 1, Conv, [64, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
92 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
93 | [-1, 1, Conv, [64, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
94 | [[-1, -2, -3, -4], 1, Concat, [1]],
95 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 65
96 |
97 | [-1, 1, Conv, [256, 3, 2, None, 1, nn.LeakyReLU(0.1)]],
98 | [[-1, 37], 1, Concat, [1]],
99 |
100 | [-1, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
101 | [-2, 1, Conv, [128, 1, 1, None, 1, nn.LeakyReLU(0.1)]],
102 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
103 | [-1, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
104 | [[-1, -2, -3, -4], 1, Concat, [1]],
105 | [-1, 1, Conv, [256, 1, 1, None, 1, nn.LeakyReLU(0.1)]], # 73
106 |
107 | [57, 1, Conv, [128, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
108 | [65, 1, Conv, [256, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
109 | [73, 1, Conv, [512, 3, 1, None, 1, nn.LeakyReLU(0.1)]],
110 |
111 | [[74,75,76], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5)
112 | ]
113 |
--------------------------------------------------------------------------------
/yolov7/cfg/training/yolov7-w6.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [ 19,27, 44,40, 38,94 ] # P3/8
9 | - [ 96,68, 86,152, 180,137 ] # P4/16
10 | - [ 140,301, 303,264, 238,542 ] # P5/32
11 | - [ 436,615, 739,380, 925,792 ] # P6/64
12 |
13 | # yolov7 backbone
14 | backbone:
15 | # [from, number, module, args]
16 | [[-1, 1, ReOrg, []], # 0
17 | [-1, 1, Conv, [64, 3, 1]], # 1-P1/2
18 |
19 | [-1, 1, Conv, [128, 3, 2]], # 2-P2/4
20 | [-1, 1, Conv, [64, 1, 1]],
21 | [-2, 1, Conv, [64, 1, 1]],
22 | [-1, 1, Conv, [64, 3, 1]],
23 | [-1, 1, Conv, [64, 3, 1]],
24 | [-1, 1, Conv, [64, 3, 1]],
25 | [-1, 1, Conv, [64, 3, 1]],
26 | [[-1, -3, -5, -6], 1, Concat, [1]],
27 | [-1, 1, Conv, [128, 1, 1]], # 10
28 |
29 | [-1, 1, Conv, [256, 3, 2]], # 11-P3/8
30 | [-1, 1, Conv, [128, 1, 1]],
31 | [-2, 1, Conv, [128, 1, 1]],
32 | [-1, 1, Conv, [128, 3, 1]],
33 | [-1, 1, Conv, [128, 3, 1]],
34 | [-1, 1, Conv, [128, 3, 1]],
35 | [-1, 1, Conv, [128, 3, 1]],
36 | [[-1, -3, -5, -6], 1, Concat, [1]],
37 | [-1, 1, Conv, [256, 1, 1]], # 19
38 |
39 | [-1, 1, Conv, [512, 3, 2]], # 20-P4/16
40 | [-1, 1, Conv, [256, 1, 1]],
41 | [-2, 1, Conv, [256, 1, 1]],
42 | [-1, 1, Conv, [256, 3, 1]],
43 | [-1, 1, Conv, [256, 3, 1]],
44 | [-1, 1, Conv, [256, 3, 1]],
45 | [-1, 1, Conv, [256, 3, 1]],
46 | [[-1, -3, -5, -6], 1, Concat, [1]],
47 | [-1, 1, Conv, [512, 1, 1]], # 28
48 |
49 | [-1, 1, Conv, [768, 3, 2]], # 29-P5/32
50 | [-1, 1, Conv, [384, 1, 1]],
51 | [-2, 1, Conv, [384, 1, 1]],
52 | [-1, 1, Conv, [384, 3, 1]],
53 | [-1, 1, Conv, [384, 3, 1]],
54 | [-1, 1, Conv, [384, 3, 1]],
55 | [-1, 1, Conv, [384, 3, 1]],
56 | [[-1, -3, -5, -6], 1, Concat, [1]],
57 | [-1, 1, Conv, [768, 1, 1]], # 37
58 |
59 | [-1, 1, Conv, [1024, 3, 2]], # 38-P6/64
60 | [-1, 1, Conv, [512, 1, 1]],
61 | [-2, 1, Conv, [512, 1, 1]],
62 | [-1, 1, Conv, [512, 3, 1]],
63 | [-1, 1, Conv, [512, 3, 1]],
64 | [-1, 1, Conv, [512, 3, 1]],
65 | [-1, 1, Conv, [512, 3, 1]],
66 | [[-1, -3, -5, -6], 1, Concat, [1]],
67 | [-1, 1, Conv, [1024, 1, 1]], # 46
68 | ]
69 |
70 | # yolov7 head
71 | head:
72 | [[-1, 1, SPPCSPC, [512]], # 47
73 |
74 | [-1, 1, Conv, [384, 1, 1]],
75 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
76 | [37, 1, Conv, [384, 1, 1]], # route backbone P5
77 | [[-1, -2], 1, Concat, [1]],
78 |
79 | [-1, 1, Conv, [384, 1, 1]],
80 | [-2, 1, Conv, [384, 1, 1]],
81 | [-1, 1, Conv, [192, 3, 1]],
82 | [-1, 1, Conv, [192, 3, 1]],
83 | [-1, 1, Conv, [192, 3, 1]],
84 | [-1, 1, Conv, [192, 3, 1]],
85 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
86 | [-1, 1, Conv, [384, 1, 1]], # 59
87 |
88 | [-1, 1, Conv, [256, 1, 1]],
89 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
90 | [28, 1, Conv, [256, 1, 1]], # route backbone P4
91 | [[-1, -2], 1, Concat, [1]],
92 |
93 | [-1, 1, Conv, [256, 1, 1]],
94 | [-2, 1, Conv, [256, 1, 1]],
95 | [-1, 1, Conv, [128, 3, 1]],
96 | [-1, 1, Conv, [128, 3, 1]],
97 | [-1, 1, Conv, [128, 3, 1]],
98 | [-1, 1, Conv, [128, 3, 1]],
99 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
100 | [-1, 1, Conv, [256, 1, 1]], # 71
101 |
102 | [-1, 1, Conv, [128, 1, 1]],
103 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
104 | [19, 1, Conv, [128, 1, 1]], # route backbone P3
105 | [[-1, -2], 1, Concat, [1]],
106 |
107 | [-1, 1, Conv, [128, 1, 1]],
108 | [-2, 1, Conv, [128, 1, 1]],
109 | [-1, 1, Conv, [64, 3, 1]],
110 | [-1, 1, Conv, [64, 3, 1]],
111 | [-1, 1, Conv, [64, 3, 1]],
112 | [-1, 1, Conv, [64, 3, 1]],
113 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
114 | [-1, 1, Conv, [128, 1, 1]], # 83
115 |
116 | [-1, 1, Conv, [256, 3, 2]],
117 | [[-1, 71], 1, Concat, [1]], # cat
118 |
119 | [-1, 1, Conv, [256, 1, 1]],
120 | [-2, 1, Conv, [256, 1, 1]],
121 | [-1, 1, Conv, [128, 3, 1]],
122 | [-1, 1, Conv, [128, 3, 1]],
123 | [-1, 1, Conv, [128, 3, 1]],
124 | [-1, 1, Conv, [128, 3, 1]],
125 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
126 | [-1, 1, Conv, [256, 1, 1]], # 93
127 |
128 | [-1, 1, Conv, [384, 3, 2]],
129 | [[-1, 59], 1, Concat, [1]], # cat
130 |
131 | [-1, 1, Conv, [384, 1, 1]],
132 | [-2, 1, Conv, [384, 1, 1]],
133 | [-1, 1, Conv, [192, 3, 1]],
134 | [-1, 1, Conv, [192, 3, 1]],
135 | [-1, 1, Conv, [192, 3, 1]],
136 | [-1, 1, Conv, [192, 3, 1]],
137 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
138 | [-1, 1, Conv, [384, 1, 1]], # 103
139 |
140 | [-1, 1, Conv, [512, 3, 2]],
141 | [[-1, 47], 1, Concat, [1]], # cat
142 |
143 | [-1, 1, Conv, [512, 1, 1]],
144 | [-2, 1, Conv, [512, 1, 1]],
145 | [-1, 1, Conv, [256, 3, 1]],
146 | [-1, 1, Conv, [256, 3, 1]],
147 | [-1, 1, Conv, [256, 3, 1]],
148 | [-1, 1, Conv, [256, 3, 1]],
149 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
150 | [-1, 1, Conv, [512, 1, 1]], # 113
151 |
152 | [83, 1, Conv, [256, 3, 1]],
153 | [93, 1, Conv, [512, 3, 1]],
154 | [103, 1, Conv, [768, 3, 1]],
155 | [113, 1, Conv, [1024, 3, 1]],
156 |
157 | [83, 1, Conv, [320, 3, 1]],
158 | [71, 1, Conv, [640, 3, 1]],
159 | [59, 1, Conv, [960, 3, 1]],
160 | [47, 1, Conv, [1280, 3, 1]],
161 |
162 | [[114,115,116,117,118,119,120,121], 1, IAuxDetect, [nc, anchors]], # Detect(P3, P4, P5, P6)
163 | ]
164 |
--------------------------------------------------------------------------------
/yolov7/cfg/training/yolov7.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [12,16, 19,36, 40,28] # P3/8
9 | - [36,75, 76,55, 72,146] # P4/16
10 | - [142,110, 192,243, 459,401] # P5/32
11 |
12 | # yolov7 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [32, 3, 1]], # 0
16 |
17 | [-1, 1, Conv, [64, 3, 2]], # 1-P1/2
18 | [-1, 1, Conv, [64, 3, 1]],
19 |
20 | [-1, 1, Conv, [128, 3, 2]], # 3-P2/4
21 | [-1, 1, Conv, [64, 1, 1]],
22 | [-2, 1, Conv, [64, 1, 1]],
23 | [-1, 1, Conv, [64, 3, 1]],
24 | [-1, 1, Conv, [64, 3, 1]],
25 | [-1, 1, Conv, [64, 3, 1]],
26 | [-1, 1, Conv, [64, 3, 1]],
27 | [[-1, -3, -5, -6], 1, Concat, [1]],
28 | [-1, 1, Conv, [256, 1, 1]], # 11
29 |
30 | [-1, 1, MP, []],
31 | [-1, 1, Conv, [128, 1, 1]],
32 | [-3, 1, Conv, [128, 1, 1]],
33 | [-1, 1, Conv, [128, 3, 2]],
34 | [[-1, -3], 1, Concat, [1]], # 16-P3/8
35 | [-1, 1, Conv, [128, 1, 1]],
36 | [-2, 1, Conv, [128, 1, 1]],
37 | [-1, 1, Conv, [128, 3, 1]],
38 | [-1, 1, Conv, [128, 3, 1]],
39 | [-1, 1, Conv, [128, 3, 1]],
40 | [-1, 1, Conv, [128, 3, 1]],
41 | [[-1, -3, -5, -6], 1, Concat, [1]],
42 | [-1, 1, Conv, [512, 1, 1]], # 24
43 |
44 | [-1, 1, MP, []],
45 | [-1, 1, Conv, [256, 1, 1]],
46 | [-3, 1, Conv, [256, 1, 1]],
47 | [-1, 1, Conv, [256, 3, 2]],
48 | [[-1, -3], 1, Concat, [1]], # 29-P4/16
49 | [-1, 1, Conv, [256, 1, 1]],
50 | [-2, 1, Conv, [256, 1, 1]],
51 | [-1, 1, Conv, [256, 3, 1]],
52 | [-1, 1, Conv, [256, 3, 1]],
53 | [-1, 1, Conv, [256, 3, 1]],
54 | [-1, 1, Conv, [256, 3, 1]],
55 | [[-1, -3, -5, -6], 1, Concat, [1]],
56 | [-1, 1, Conv, [1024, 1, 1]], # 37
57 |
58 | [-1, 1, MP, []],
59 | [-1, 1, Conv, [512, 1, 1]],
60 | [-3, 1, Conv, [512, 1, 1]],
61 | [-1, 1, Conv, [512, 3, 2]],
62 | [[-1, -3], 1, Concat, [1]], # 42-P5/32
63 | [-1, 1, Conv, [256, 1, 1]],
64 | [-2, 1, Conv, [256, 1, 1]],
65 | [-1, 1, Conv, [256, 3, 1]],
66 | [-1, 1, Conv, [256, 3, 1]],
67 | [-1, 1, Conv, [256, 3, 1]],
68 | [-1, 1, Conv, [256, 3, 1]],
69 | [[-1, -3, -5, -6], 1, Concat, [1]],
70 | [-1, 1, Conv, [1024, 1, 1]], # 50
71 | ]
72 |
73 | # yolov7 head
74 | head:
75 | [[-1, 1, SPPCSPC, [512]], # 51
76 |
77 | [-1, 1, Conv, [256, 1, 1]],
78 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
79 | [37, 1, Conv, [256, 1, 1]], # route backbone P4
80 | [[-1, -2], 1, Concat, [1]],
81 |
82 | [-1, 1, Conv, [256, 1, 1]],
83 | [-2, 1, Conv, [256, 1, 1]],
84 | [-1, 1, Conv, [128, 3, 1]],
85 | [-1, 1, Conv, [128, 3, 1]],
86 | [-1, 1, Conv, [128, 3, 1]],
87 | [-1, 1, Conv, [128, 3, 1]],
88 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
89 | [-1, 1, Conv, [256, 1, 1]], # 63
90 |
91 | [-1, 1, Conv, [128, 1, 1]],
92 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
93 | [24, 1, Conv, [128, 1, 1]], # route backbone P3
94 | [[-1, -2], 1, Concat, [1]],
95 |
96 | [-1, 1, Conv, [128, 1, 1]],
97 | [-2, 1, Conv, [128, 1, 1]],
98 | [-1, 1, Conv, [64, 3, 1]],
99 | [-1, 1, Conv, [64, 3, 1]],
100 | [-1, 1, Conv, [64, 3, 1]],
101 | [-1, 1, Conv, [64, 3, 1]],
102 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
103 | [-1, 1, Conv, [128, 1, 1]], # 75
104 |
105 | [-1, 1, MP, []],
106 | [-1, 1, Conv, [128, 1, 1]],
107 | [-3, 1, Conv, [128, 1, 1]],
108 | [-1, 1, Conv, [128, 3, 2]],
109 | [[-1, -3, 63], 1, Concat, [1]],
110 |
111 | [-1, 1, Conv, [256, 1, 1]],
112 | [-2, 1, Conv, [256, 1, 1]],
113 | [-1, 1, Conv, [128, 3, 1]],
114 | [-1, 1, Conv, [128, 3, 1]],
115 | [-1, 1, Conv, [128, 3, 1]],
116 | [-1, 1, Conv, [128, 3, 1]],
117 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
118 | [-1, 1, Conv, [256, 1, 1]], # 88
119 |
120 | [-1, 1, MP, []],
121 | [-1, 1, Conv, [256, 1, 1]],
122 | [-3, 1, Conv, [256, 1, 1]],
123 | [-1, 1, Conv, [256, 3, 2]],
124 | [[-1, -3, 51], 1, Concat, [1]],
125 |
126 | [-1, 1, Conv, [512, 1, 1]],
127 | [-2, 1, Conv, [512, 1, 1]],
128 | [-1, 1, Conv, [256, 3, 1]],
129 | [-1, 1, Conv, [256, 3, 1]],
130 | [-1, 1, Conv, [256, 3, 1]],
131 | [-1, 1, Conv, [256, 3, 1]],
132 | [[-1, -2, -3, -4, -5, -6], 1, Concat, [1]],
133 | [-1, 1, Conv, [512, 1, 1]], # 101
134 |
135 | [75, 1, RepConv, [256, 3, 1]],
136 | [88, 1, RepConv, [512, 3, 1]],
137 | [101, 1, RepConv, [1024, 3, 1]],
138 |
139 | [[102,103,104], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5)
140 | ]
141 |
--------------------------------------------------------------------------------
/yolov7/cfg/training/yolov7x.yaml:
--------------------------------------------------------------------------------
1 | # parameters
2 | nc: 80 # number of classes
3 | depth_multiple: 1.0 # model depth multiple
4 | width_multiple: 1.0 # layer channel multiple
5 |
6 | # anchors
7 | anchors:
8 | - [12,16, 19,36, 40,28] # P3/8
9 | - [36,75, 76,55, 72,146] # P4/16
10 | - [142,110, 192,243, 459,401] # P5/32
11 |
12 | # yolov7 backbone
13 | backbone:
14 | # [from, number, module, args]
15 | [[-1, 1, Conv, [40, 3, 1]], # 0
16 |
17 | [-1, 1, Conv, [80, 3, 2]], # 1-P1/2
18 | [-1, 1, Conv, [80, 3, 1]],
19 |
20 | [-1, 1, Conv, [160, 3, 2]], # 3-P2/4
21 | [-1, 1, Conv, [64, 1, 1]],
22 | [-2, 1, Conv, [64, 1, 1]],
23 | [-1, 1, Conv, [64, 3, 1]],
24 | [-1, 1, Conv, [64, 3, 1]],
25 | [-1, 1, Conv, [64, 3, 1]],
26 | [-1, 1, Conv, [64, 3, 1]],
27 | [-1, 1, Conv, [64, 3, 1]],
28 | [-1, 1, Conv, [64, 3, 1]],
29 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
30 | [-1, 1, Conv, [320, 1, 1]], # 13
31 |
32 | [-1, 1, MP, []],
33 | [-1, 1, Conv, [160, 1, 1]],
34 | [-3, 1, Conv, [160, 1, 1]],
35 | [-1, 1, Conv, [160, 3, 2]],
36 | [[-1, -3], 1, Concat, [1]], # 18-P3/8
37 | [-1, 1, Conv, [128, 1, 1]],
38 | [-2, 1, Conv, [128, 1, 1]],
39 | [-1, 1, Conv, [128, 3, 1]],
40 | [-1, 1, Conv, [128, 3, 1]],
41 | [-1, 1, Conv, [128, 3, 1]],
42 | [-1, 1, Conv, [128, 3, 1]],
43 | [-1, 1, Conv, [128, 3, 1]],
44 | [-1, 1, Conv, [128, 3, 1]],
45 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
46 | [-1, 1, Conv, [640, 1, 1]], # 28
47 |
48 | [-1, 1, MP, []],
49 | [-1, 1, Conv, [320, 1, 1]],
50 | [-3, 1, Conv, [320, 1, 1]],
51 | [-1, 1, Conv, [320, 3, 2]],
52 | [[-1, -3], 1, Concat, [1]], # 33-P4/16
53 | [-1, 1, Conv, [256, 1, 1]],
54 | [-2, 1, Conv, [256, 1, 1]],
55 | [-1, 1, Conv, [256, 3, 1]],
56 | [-1, 1, Conv, [256, 3, 1]],
57 | [-1, 1, Conv, [256, 3, 1]],
58 | [-1, 1, Conv, [256, 3, 1]],
59 | [-1, 1, Conv, [256, 3, 1]],
60 | [-1, 1, Conv, [256, 3, 1]],
61 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
62 | [-1, 1, Conv, [1280, 1, 1]], # 43
63 |
64 | [-1, 1, MP, []],
65 | [-1, 1, Conv, [640, 1, 1]],
66 | [-3, 1, Conv, [640, 1, 1]],
67 | [-1, 1, Conv, [640, 3, 2]],
68 | [[-1, -3], 1, Concat, [1]], # 48-P5/32
69 | [-1, 1, Conv, [256, 1, 1]],
70 | [-2, 1, Conv, [256, 1, 1]],
71 | [-1, 1, Conv, [256, 3, 1]],
72 | [-1, 1, Conv, [256, 3, 1]],
73 | [-1, 1, Conv, [256, 3, 1]],
74 | [-1, 1, Conv, [256, 3, 1]],
75 | [-1, 1, Conv, [256, 3, 1]],
76 | [-1, 1, Conv, [256, 3, 1]],
77 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
78 | [-1, 1, Conv, [1280, 1, 1]], # 58
79 | ]
80 |
81 | # yolov7 head
82 | head:
83 | [[-1, 1, SPPCSPC, [640]], # 59
84 |
85 | [-1, 1, Conv, [320, 1, 1]],
86 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
87 | [43, 1, Conv, [320, 1, 1]], # route backbone P4
88 | [[-1, -2], 1, Concat, [1]],
89 |
90 | [-1, 1, Conv, [256, 1, 1]],
91 | [-2, 1, Conv, [256, 1, 1]],
92 | [-1, 1, Conv, [256, 3, 1]],
93 | [-1, 1, Conv, [256, 3, 1]],
94 | [-1, 1, Conv, [256, 3, 1]],
95 | [-1, 1, Conv, [256, 3, 1]],
96 | [-1, 1, Conv, [256, 3, 1]],
97 | [-1, 1, Conv, [256, 3, 1]],
98 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
99 | [-1, 1, Conv, [320, 1, 1]], # 73
100 |
101 | [-1, 1, Conv, [160, 1, 1]],
102 | [-1, 1, nn.Upsample, [None, 2, 'nearest']],
103 | [28, 1, Conv, [160, 1, 1]], # route backbone P3
104 | [[-1, -2], 1, Concat, [1]],
105 |
106 | [-1, 1, Conv, [128, 1, 1]],
107 | [-2, 1, Conv, [128, 1, 1]],
108 | [-1, 1, Conv, [128, 3, 1]],
109 | [-1, 1, Conv, [128, 3, 1]],
110 | [-1, 1, Conv, [128, 3, 1]],
111 | [-1, 1, Conv, [128, 3, 1]],
112 | [-1, 1, Conv, [128, 3, 1]],
113 | [-1, 1, Conv, [128, 3, 1]],
114 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
115 | [-1, 1, Conv, [160, 1, 1]], # 87
116 |
117 | [-1, 1, MP, []],
118 | [-1, 1, Conv, [160, 1, 1]],
119 | [-3, 1, Conv, [160, 1, 1]],
120 | [-1, 1, Conv, [160, 3, 2]],
121 | [[-1, -3, 73], 1, Concat, [1]],
122 |
123 | [-1, 1, Conv, [256, 1, 1]],
124 | [-2, 1, Conv, [256, 1, 1]],
125 | [-1, 1, Conv, [256, 3, 1]],
126 | [-1, 1, Conv, [256, 3, 1]],
127 | [-1, 1, Conv, [256, 3, 1]],
128 | [-1, 1, Conv, [256, 3, 1]],
129 | [-1, 1, Conv, [256, 3, 1]],
130 | [-1, 1, Conv, [256, 3, 1]],
131 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
132 | [-1, 1, Conv, [320, 1, 1]], # 102
133 |
134 | [-1, 1, MP, []],
135 | [-1, 1, Conv, [320, 1, 1]],
136 | [-3, 1, Conv, [320, 1, 1]],
137 | [-1, 1, Conv, [320, 3, 2]],
138 | [[-1, -3, 59], 1, Concat, [1]],
139 |
140 | [-1, 1, Conv, [512, 1, 1]],
141 | [-2, 1, Conv, [512, 1, 1]],
142 | [-1, 1, Conv, [512, 3, 1]],
143 | [-1, 1, Conv, [512, 3, 1]],
144 | [-1, 1, Conv, [512, 3, 1]],
145 | [-1, 1, Conv, [512, 3, 1]],
146 | [-1, 1, Conv, [512, 3, 1]],
147 | [-1, 1, Conv, [512, 3, 1]],
148 | [[-1, -3, -5, -7, -8], 1, Concat, [1]],
149 | [-1, 1, Conv, [640, 1, 1]], # 117
150 |
151 | [87, 1, Conv, [320, 3, 1]],
152 | [102, 1, Conv, [640, 3, 1]],
153 | [117, 1, Conv, [1280, 3, 1]],
154 |
155 | [[118,119,120], 1, IDetect, [nc, anchors]], # Detect(P3, P4, P5)
156 | ]
157 |
--------------------------------------------------------------------------------
/yolov7/deploy/triton-inference-server/README.md:
--------------------------------------------------------------------------------
1 | # YOLOv7 on Triton Inference Server
2 |
3 | Instructions to deploy YOLOv7 as TensorRT engine to [Triton Inference Server](https://github.com/NVIDIA/triton-inference-server).
4 |
5 | Triton Inference Server takes care of model deployment with many out-of-the-box benefits, like a GRPC and HTTP interface, automatic scheduling on multiple GPUs, shared memory (even on GPU), dynamic server-side batching, health metrics and memory resource management.
6 |
7 | There are no additional dependencies needed to run this deployment, except a working docker daemon with GPU support.
8 |
9 | ## Export TensorRT
10 |
11 | See https://github.com/WongKinYiu/yolov7#export for more info.
12 |
13 | ```bash
14 | #install onnx-simplifier not listed in general yolov7 requirements.txt
15 | pip3 install onnx-simplifier
16 |
17 | # Pytorch Yolov7 -> ONNX with grid, EfficientNMS plugin and dynamic batch size
18 | python export.py --weights ./yolov7.pt --grid --end2end --dynamic-batch --simplify --topk-all 100 --iou-thres 0.65 --conf-thres 0.35 --img-size 640 640
19 | # ONNX -> TensorRT with trtexec and docker
20 | docker run -it --rm --gpus=all nvcr.io/nvidia/tensorrt:22.06-py3
21 | # Copy onnx -> container: docker cp yolov7.onnx :/workspace/
22 | # Export with FP16 precision, min batch 1, opt batch 8 and max batch 8
23 | ./tensorrt/bin/trtexec --onnx=yolov7.onnx --minShapes=images:1x3x640x640 --optShapes=images:8x3x640x640 --maxShapes=images:8x3x640x640 --fp16 --workspace=4096 --saveEngine=yolov7-fp16-1x8x8.engine --timingCacheFile=timing.cache
24 | # Test engine
25 | ./tensorrt/bin/trtexec --loadEngine=yolov7-fp16-1x8x8.engine
26 | # Copy engine -> host: docker cp :/workspace/yolov7-fp16-1x8x8.engine .
27 | ```
28 |
29 | Example output of test with RTX 3090.
30 |
31 | ```
32 | [I] === Performance summary ===
33 | [I] Throughput: 73.4985 qps
34 | [I] Latency: min = 14.8578 ms, max = 15.8344 ms, mean = 15.07 ms, median = 15.0422 ms, percentile(99%) = 15.7443 ms
35 | [I] End-to-End Host Latency: min = 25.8715 ms, max = 28.4102 ms, mean = 26.672 ms, median = 26.6082 ms, percentile(99%) = 27.8314 ms
36 | [I] Enqueue Time: min = 0.793701 ms, max = 1.47144 ms, mean = 1.2008 ms, median = 1.28644 ms, percentile(99%) = 1.38965 ms
37 | [I] H2D Latency: min = 1.50073 ms, max = 1.52454 ms, mean = 1.51225 ms, median = 1.51404 ms, percentile(99%) = 1.51941 ms
38 | [I] GPU Compute Time: min = 13.3386 ms, max = 14.3186 ms, mean = 13.5448 ms, median = 13.5178 ms, percentile(99%) = 14.2151 ms
39 | [I] D2H Latency: min = 0.00878906 ms, max = 0.0172729 ms, mean = 0.0128844 ms, median = 0.0125732 ms, percentile(99%) = 0.0166016 ms
40 | [I] Total Host Walltime: 3.04768 s
41 | [I] Total GPU Compute Time: 3.03404 s
42 | [I] Explanations of the performance metrics are printed in the verbose logs.
43 | ```
44 | Note: 73.5 qps x batch 8 = 588 fps @ ~15ms latency.
45 |
46 | ## Model Repository
47 |
48 | See [Triton Model Repository Documentation](https://github.com/triton-inference-server/server/blob/main/docs/model_repository.md#model-repository) for more info.
49 |
50 | ```bash
51 | # Create folder structure
52 | mkdir -p triton-deploy/models/yolov7/1/
53 | touch triton-deploy/models/yolov7/config.pbtxt
54 | # Place model
55 | mv yolov7-fp16-1x8x8.engine triton-deploy/models/yolov7/1/model.plan
56 | ```
57 |
58 | ## Model Configuration
59 |
60 | See [Triton Model Configuration Documentation](https://github.com/triton-inference-server/server/blob/main/docs/model_configuration.md#model-configuration) for more info.
61 |
62 | Minimal configuration for `triton-deploy/models/yolov7/config.pbtxt`:
63 |
64 | ```
65 | name: "yolov7"
66 | platform: "tensorrt_plan"
67 | max_batch_size: 8
68 | dynamic_batching { }
69 | ```
70 |
71 | Example repository:
72 |
73 | ```bash
74 | $ tree triton-deploy/
75 | triton-deploy/
76 | └── models
77 | └── yolov7
78 | ├── 1
79 | │ └── model.plan
80 | └── config.pbtxt
81 |
82 | 3 directories, 2 files
83 | ```
84 |
85 | ## Start Triton Inference Server
86 |
87 | ```
88 | docker run --gpus all --rm --ipc=host --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 -p8000:8000 -p8001:8001 -p8002:8002 -v$(pwd)/triton-deploy/models:/models nvcr.io/nvidia/tritonserver:22.06-py3 tritonserver --model-repository=/models --strict-model-config=false --log-verbose 1
89 | ```
90 |
91 | In the log you should see:
92 |
93 | ```
94 | +--------+---------+--------+
95 | | Model | Version | Status |
96 | +--------+---------+--------+
97 | | yolov7 | 1 | READY |
98 | +--------+---------+--------+
99 | ```
100 |
101 | ## Performance with Model Analyzer
102 |
103 | See [Triton Model Analyzer Documentation](https://github.com/triton-inference-server/server/blob/main/docs/model_analyzer.md#model-analyzer) for more info.
104 |
105 | Performance numbers @ RTX 3090 + AMD Ryzen 9 5950X
106 |
107 | Example test for 16 concurrent clients using shared memory, each with batch size 1 requests:
108 |
109 | ```bash
110 | docker run -it --ipc=host --net=host nvcr.io/nvidia/tritonserver:22.06-py3-sdk /bin/bash
111 |
112 | ./install/bin/perf_analyzer -m yolov7 -u 127.0.0.1:8001 -i grpc --shared-memory system --concurrency-range 16
113 |
114 | # Result (truncated)
115 | Concurrency: 16, throughput: 590.119 infer/sec, latency 27080 usec
116 | ```
117 |
118 | Throughput for 16 clients with batch size 1 is the same as for a single thread running the engine at 16 batch size locally thanks to Triton [Dynamic Batching Strategy](https://github.com/triton-inference-server/server/blob/main/docs/model_configuration.md#dynamic-batcher). Result without dynamic batching (disable in model configuration) considerably worse:
119 |
120 | ```bash
121 | # Result (truncated)
122 | Concurrency: 16, throughput: 335.587 infer/sec, latency 47616 usec
123 | ```
124 |
125 | ## How to run model in your code
126 |
127 | Example client can be found in client.py. It can run dummy input, images and videos.
128 |
129 | ```bash
130 | pip3 install tritonclient[all] opencv-python
131 | python3 client.py image data/dog.jpg
132 | ```
133 |
134 | 
135 |
136 | ```
137 | $ python3 client.py --help
138 | usage: client.py [-h] [-m MODEL] [--width WIDTH] [--height HEIGHT] [-u URL] [-o OUT] [-f FPS] [-i] [-v] [-t CLIENT_TIMEOUT] [-s] [-r ROOT_CERTIFICATES] [-p PRIVATE_KEY] [-x CERTIFICATE_CHAIN] {dummy,image,video} [input]
139 |
140 | positional arguments:
141 | {dummy,image,video} Run mode. 'dummy' will send an emtpy buffer to the server to test if inference works. 'image' will process an image. 'video' will process a video.
142 | input Input file to load from in image or video mode
143 |
144 | optional arguments:
145 | -h, --help show this help message and exit
146 | -m MODEL, --model MODEL
147 | Inference model name, default yolov7
148 | --width WIDTH Inference model input width, default 640
149 | --height HEIGHT Inference model input height, default 640
150 | -u URL, --url URL Inference server URL, default localhost:8001
151 | -o OUT, --out OUT Write output into file instead of displaying it
152 | -f FPS, --fps FPS Video output fps, default 24.0 FPS
153 | -i, --model-info Print model status, configuration and statistics
154 | -v, --verbose Enable verbose client output
155 | -t CLIENT_TIMEOUT, --client-timeout CLIENT_TIMEOUT
156 | Client timeout in seconds, default no timeout
157 | -s, --ssl Enable SSL encrypted channel to the server
158 | -r ROOT_CERTIFICATES, --root-certificates ROOT_CERTIFICATES
159 | File holding PEM-encoded root certificates, default none
160 | -p PRIVATE_KEY, --private-key PRIVATE_KEY
161 | File holding PEM-encoded private key, default is none
162 | -x CERTIFICATE_CHAIN, --certificate-chain CERTIFICATE_CHAIN
163 | File holding PEM-encoded certicate chain default is none
164 | ```
165 |
--------------------------------------------------------------------------------
/yolov7/deploy/triton-inference-server/boundingbox.py:
--------------------------------------------------------------------------------
1 | class BoundingBox:
2 | def __init__(self, classID, confidence, x1, x2, y1, y2, image_width, image_height):
3 | self.classID = classID
4 | self.confidence = confidence
5 | self.x1 = x1
6 | self.x2 = x2
7 | self.y1 = y1
8 | self.y2 = y2
9 | self.u1 = x1 / image_width
10 | self.u2 = x2 / image_width
11 | self.v1 = y1 / image_height
12 | self.v2 = y2 / image_height
13 |
14 | def box(self):
15 | return (self.x1, self.y1, self.x2, self.y2)
16 |
17 | def width(self):
18 | return self.x2 - self.x1
19 |
20 | def height(self):
21 | return self.y2 - self.y1
22 |
23 | def center_absolute(self):
24 | return (0.5 * (self.x1 + self.x2), 0.5 * (self.y1 + self.y2))
25 |
26 | def center_normalized(self):
27 | return (0.5 * (self.u1 + self.u2), 0.5 * (self.v1 + self.v2))
28 |
29 | def size_absolute(self):
30 | return (self.x2 - self.x1, self.y2 - self.y1)
31 |
32 | def size_normalized(self):
33 | return (self.u2 - self.u1, self.v2 - self.v1)
34 |
--------------------------------------------------------------------------------
/yolov7/deploy/triton-inference-server/labels.py:
--------------------------------------------------------------------------------
1 | from enum import Enum
2 |
3 | class COCOLabels(Enum):
4 | PERSON = 0
5 | BICYCLE = 1
6 | CAR = 2
7 | MOTORBIKE = 3
8 | AEROPLANE = 4
9 | BUS = 5
10 | TRAIN = 6
11 | TRUCK = 7
12 | BOAT = 8
13 | TRAFFIC_LIGHT = 9
14 | FIRE_HYDRANT = 10
15 | STOP_SIGN = 11
16 | PARKING_METER = 12
17 | BENCH = 13
18 | BIRD = 14
19 | CAT = 15
20 | DOG = 16
21 | HORSE = 17
22 | SHEEP = 18
23 | COW = 19
24 | ELEPHANT = 20
25 | BEAR = 21
26 | ZEBRA = 22
27 | GIRAFFE = 23
28 | BACKPACK = 24
29 | UMBRELLA = 25
30 | HANDBAG = 26
31 | TIE = 27
32 | SUITCASE = 28
33 | FRISBEE = 29
34 | SKIS = 30
35 | SNOWBOARD = 31
36 | SPORTS_BALL = 32
37 | KITE = 33
38 | BASEBALL_BAT = 34
39 | BASEBALL_GLOVE = 35
40 | SKATEBOARD = 36
41 | SURFBOARD = 37
42 | TENNIS_RACKET = 38
43 | BOTTLE = 39
44 | WINE_GLASS = 40
45 | CUP = 41
46 | FORK = 42
47 | KNIFE = 43
48 | SPOON = 44
49 | BOWL = 45
50 | BANANA = 46
51 | APPLE = 47
52 | SANDWICH = 48
53 | ORANGE = 49
54 | BROCCOLI = 50
55 | CARROT = 51
56 | HOT_DOG = 52
57 | PIZZA = 53
58 | DONUT = 54
59 | CAKE = 55
60 | CHAIR = 56
61 | SOFA = 57
62 | POTTEDPLANT = 58
63 | BED = 59
64 | DININGTABLE = 60
65 | TOILET = 61
66 | TVMONITOR = 62
67 | LAPTOP = 63
68 | MOUSE = 64
69 | REMOTE = 65
70 | KEYBOARD = 66
71 | CELL_PHONE = 67
72 | MICROWAVE = 68
73 | OVEN = 69
74 | TOASTER = 70
75 | SINK = 71
76 | REFRIGERATOR = 72
77 | BOOK = 73
78 | CLOCK = 74
79 | VASE = 75
80 | SCISSORS = 76
81 | TEDDY_BEAR = 77
82 | HAIR_DRIER = 78
83 | TOOTHBRUSH = 79
84 |
--------------------------------------------------------------------------------
/yolov7/deploy/triton-inference-server/processing.py:
--------------------------------------------------------------------------------
1 | from boundingbox import BoundingBox
2 |
3 | import cv2
4 | import numpy as np
5 |
6 | def preprocess(img, input_shape, letter_box=True):
7 | if letter_box:
8 | img_h, img_w, _ = img.shape
9 | new_h, new_w = input_shape[0], input_shape[1]
10 | offset_h, offset_w = 0, 0
11 | if (new_w / img_w) <= (new_h / img_h):
12 | new_h = int(img_h * new_w / img_w)
13 | offset_h = (input_shape[0] - new_h) // 2
14 | else:
15 | new_w = int(img_w * new_h / img_h)
16 | offset_w = (input_shape[1] - new_w) // 2
17 | resized = cv2.resize(img, (new_w, new_h))
18 | img = np.full((input_shape[0], input_shape[1], 3), 127, dtype=np.uint8)
19 | img[offset_h:(offset_h + new_h), offset_w:(offset_w + new_w), :] = resized
20 | else:
21 | img = cv2.resize(img, (input_shape[1], input_shape[0]))
22 |
23 | img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
24 | img = img.transpose((2, 0, 1)).astype(np.float32)
25 | img /= 255.0
26 | return img
27 |
28 | def postprocess(num_dets, det_boxes, det_scores, det_classes, img_w, img_h, input_shape, letter_box=True):
29 | boxes = det_boxes[0, :num_dets[0][0]] / np.array([input_shape[0], input_shape[1], input_shape[0], input_shape[1]], dtype=np.float32)
30 | scores = det_scores[0, :num_dets[0][0]]
31 | classes = det_classes[0, :num_dets[0][0]].astype(np.int)
32 |
33 | old_h, old_w = img_h, img_w
34 | offset_h, offset_w = 0, 0
35 | if letter_box:
36 | if (img_w / input_shape[1]) >= (img_h / input_shape[0]):
37 | old_h = int(input_shape[0] * img_w / input_shape[1])
38 | offset_h = (old_h - img_h) // 2
39 | else:
40 | old_w = int(input_shape[1] * img_h / input_shape[0])
41 | offset_w = (old_w - img_w) // 2
42 |
43 | boxes = boxes * np.array([old_w, old_h, old_w, old_h], dtype=np.float32)
44 | if letter_box:
45 | boxes -= np.array([offset_w, offset_h, offset_w, offset_h], dtype=np.float32)
46 | boxes = boxes.astype(np.int)
47 |
48 | detected_objects = []
49 | for box, score, label in zip(boxes, scores, classes):
50 | detected_objects.append(BoundingBox(label, score, box[0], box[2], box[1], box[3], img_w, img_h))
51 | return detected_objects
52 |
--------------------------------------------------------------------------------
/yolov7/deploy/triton-inference-server/render.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 |
3 | import cv2
4 |
5 | from math import sqrt
6 |
7 | _LINE_THICKNESS_SCALING = 500.0
8 |
9 | np.random.seed(0)
10 | RAND_COLORS = np.random.randint(50, 255, (64, 3), "int") # used for class visu
11 | RAND_COLORS[0] = [220, 220, 220]
12 |
13 | def render_box(img, box, color=(200, 200, 200)):
14 | """
15 | Render a box. Calculates scaling and thickness automatically.
16 | :param img: image to render into
17 | :param box: (x1, y1, x2, y2) - box coordinates
18 | :param color: (b, g, r) - box color
19 | :return: updated image
20 | """
21 | x1, y1, x2, y2 = box
22 | thickness = int(
23 | round(
24 | (img.shape[0] * img.shape[1])
25 | / (_LINE_THICKNESS_SCALING * _LINE_THICKNESS_SCALING)
26 | )
27 | )
28 | thickness = max(1, thickness)
29 | img = cv2.rectangle(
30 | img,
31 | (int(x1), int(y1)),
32 | (int(x2), int(y2)),
33 | color,
34 | thickness=thickness
35 | )
36 | return img
37 |
38 | def render_filled_box(img, box, color=(200, 200, 200)):
39 | """
40 | Render a box. Calculates scaling and thickness automatically.
41 | :param img: image to render into
42 | :param box: (x1, y1, x2, y2) - box coordinates
43 | :param color: (b, g, r) - box color
44 | :return: updated image
45 | """
46 | x1, y1, x2, y2 = box
47 | img = cv2.rectangle(
48 | img,
49 | (int(x1), int(y1)),
50 | (int(x2), int(y2)),
51 | color,
52 | thickness=cv2.FILLED
53 | )
54 | return img
55 |
56 | _TEXT_THICKNESS_SCALING = 700.0
57 | _TEXT_SCALING = 520.0
58 |
59 |
60 | def get_text_size(img, text, normalised_scaling=1.0):
61 | """
62 | Get calculated text size (as box width and height)
63 | :param img: image reference, used to determine appropriate text scaling
64 | :param text: text to display
65 | :param normalised_scaling: additional normalised scaling. Default 1.0.
66 | :return: (width, height) - width and height of text box
67 | """
68 | thickness = int(
69 | round(
70 | (img.shape[0] * img.shape[1])
71 | / (_TEXT_THICKNESS_SCALING * _TEXT_THICKNESS_SCALING)
72 | )
73 | * normalised_scaling
74 | )
75 | thickness = max(1, thickness)
76 | scaling = img.shape[0] / _TEXT_SCALING * normalised_scaling
77 | return cv2.getTextSize(text, cv2.FONT_HERSHEY_SIMPLEX, scaling, thickness)[0]
78 |
79 |
80 | def render_text(img, text, pos, color=(200, 200, 200), normalised_scaling=1.0):
81 | """
82 | Render a text into the image. Calculates scaling and thickness automatically.
83 | :param img: image to render into
84 | :param text: text to display
85 | :param pos: (x, y) - upper left coordinates of render position
86 | :param color: (b, g, r) - text color
87 | :param normalised_scaling: additional normalised scaling. Default 1.0.
88 | :return: updated image
89 | """
90 | x, y = pos
91 | thickness = int(
92 | round(
93 | (img.shape[0] * img.shape[1])
94 | / (_TEXT_THICKNESS_SCALING * _TEXT_THICKNESS_SCALING)
95 | )
96 | * normalised_scaling
97 | )
98 | thickness = max(1, thickness)
99 | scaling = img.shape[0] / _TEXT_SCALING * normalised_scaling
100 | size = get_text_size(img, text, normalised_scaling)
101 | cv2.putText(
102 | img,
103 | text,
104 | (int(x), int(y + size[1])),
105 | cv2.FONT_HERSHEY_SIMPLEX,
106 | scaling,
107 | color,
108 | thickness=thickness,
109 | )
110 | return img
111 |
--------------------------------------------------------------------------------
/yolov7/hubconf.py:
--------------------------------------------------------------------------------
1 | """PyTorch Hub models
2 |
3 | Usage:
4 | import torch
5 | model = torch.hub.load('repo', 'model')
6 | """
7 |
8 | from pathlib import Path
9 |
10 | import torch
11 |
12 | from models.yolo import Model
13 | from utils.general import check_requirements, set_logging
14 | from utils.google_utils import attempt_download
15 | from utils.torch_utils import select_device
16 |
17 | dependencies = ['torch', 'yaml']
18 | check_requirements(Path(__file__).parent / 'requirements.txt', exclude=('pycocotools', 'thop'))
19 | set_logging()
20 |
21 |
22 | def create(name, pretrained, channels, classes, autoshape):
23 | """Creates a specified model
24 |
25 | Arguments:
26 | name (str): name of model, i.e. 'yolov7'
27 | pretrained (bool): load pretrained weights into the model
28 | channels (int): number of input channels
29 | classes (int): number of model classes
30 |
31 | Returns:
32 | pytorch model
33 | """
34 | try:
35 | cfg = list((Path(__file__).parent / 'cfg').rglob(f'{name}.yaml'))[0] # model.yaml path
36 | model = Model(cfg, channels, classes)
37 | if pretrained:
38 | fname = f'{name}.pt' # checkpoint filename
39 | attempt_download(fname) # download if not found locally
40 | ckpt = torch.load(fname, map_location=torch.device('cpu')) # load
41 | msd = model.state_dict() # model state_dict
42 | csd = ckpt['model'].float().state_dict() # checkpoint state_dict as FP32
43 | csd = {k: v for k, v in csd.items() if msd[k].shape == v.shape} # filter
44 | model.load_state_dict(csd, strict=False) # load
45 | if len(ckpt['model'].names) == classes:
46 | model.names = ckpt['model'].names # set class names attribute
47 | if autoshape:
48 | model = model.autoshape() # for file/URI/PIL/cv2/np inputs and NMS
49 | device = select_device('0' if torch.cuda.is_available() else 'cpu') # default to GPU if available
50 | return model.to(device)
51 |
52 | except Exception as e:
53 | s = 'Cache maybe be out of date, try force_reload=True.'
54 | raise Exception(s) from e
55 |
56 |
57 | def custom(path_or_model='path/to/model.pt', autoshape=True):
58 | """custom mode
59 |
60 | Arguments (3 options):
61 | path_or_model (str): 'path/to/model.pt'
62 | path_or_model (dict): torch.load('path/to/model.pt')
63 | path_or_model (nn.Module): torch.load('path/to/model.pt')['model']
64 |
65 | Returns:
66 | pytorch model
67 | """
68 | model = torch.load(path_or_model, map_location=torch.device('cpu')) if isinstance(path_or_model, str) else path_or_model # load checkpoint
69 | if isinstance(model, dict):
70 | model = model['ema' if model.get('ema') else 'model'] # load model
71 |
72 | hub_model = Model(model.yaml).to(next(model.parameters()).device) # create
73 | hub_model.load_state_dict(model.float().state_dict()) # load state_dict
74 | hub_model.names = model.names # class names
75 | if autoshape:
76 | hub_model = hub_model.autoshape() # for file/URI/PIL/cv2/np inputs and NMS
77 | device = select_device('0' if torch.cuda.is_available() else 'cpu') # default to GPU if available
78 | return hub_model.to(device)
79 |
80 |
81 | def yolov7(pretrained=True, channels=3, classes=80, autoshape=True):
82 | return create('yolov7', pretrained, channels, classes, autoshape)
83 |
84 |
85 | if __name__ == '__main__':
86 | model = custom(path_or_model='yolov7.pt') # custom example
87 | # model = create(name='yolov7', pretrained=True, channels=3, classes=80, autoshape=True) # pretrained example
88 |
89 | # Verify inference
90 | import numpy as np
91 | from PIL import Image
92 |
93 | imgs = [np.zeros((640, 480, 3))]
94 |
95 | results = model(imgs) # batched inference
96 | results.print()
97 | results.save()
98 |
--------------------------------------------------------------------------------
/yolov7/models/__init__.py:
--------------------------------------------------------------------------------
1 | # init
--------------------------------------------------------------------------------
/yolov7/paper/yolov7.pdf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Priler/csgobot/1993ae7644527c84c7c891b8b6ebbcad2e5075f1/yolov7/paper/yolov7.pdf
--------------------------------------------------------------------------------
/yolov7/requirements.txt:
--------------------------------------------------------------------------------
1 | # Usage: pip install -r requirements.txt
2 |
3 | # Base ----------------------------------------
4 | matplotlib>=3.2.2
5 | numpy>=1.18.5
6 | opencv-python>=4.1.1
7 | Pillow>=7.1.2
8 | PyYAML>=5.3.1
9 | requests>=2.23.0
10 | scipy>=1.4.1
11 | torch>=1.7.0,!=1.12.0
12 | torchvision>=0.8.1,!=0.13.0
13 | tqdm>=4.41.0
14 | protobuf<4.21.3
15 |
16 | # Logging -------------------------------------
17 | tensorboard>=2.4.1
18 | # wandb
19 |
20 | # Plotting ------------------------------------
21 | pandas>=1.1.4
22 | seaborn>=0.11.0
23 |
24 | # Export --------------------------------------
25 | # coremltools>=4.1 # CoreML export
26 | # onnx>=1.9.0 # ONNX export
27 | # onnx-simplifier>=0.3.6 # ONNX simplifier
28 | # scikit-learn==0.19.2 # CoreML quantization
29 | # tensorflow>=2.4.1 # TFLite export
30 | # tensorflowjs>=3.9.0 # TF.js export
31 | # openvino-dev # OpenVINO export
32 |
33 | # Extras --------------------------------------
34 | ipython # interactive notebook
35 | psutil # system utilization
36 | thop # FLOPs computation
37 | # albumentations>=1.0.3
38 | # pycocotools>=2.0 # COCO mAP
39 | # roboflow
40 |
--------------------------------------------------------------------------------
/yolov7/utils/__init__.py:
--------------------------------------------------------------------------------
1 | # init
--------------------------------------------------------------------------------
/yolov7/utils/activations.py:
--------------------------------------------------------------------------------
1 | # Activation functions
2 |
3 | import torch
4 | import torch.nn as nn
5 | import torch.nn.functional as F
6 |
7 |
8 | # SiLU https://arxiv.org/pdf/1606.08415.pdf ----------------------------------------------------------------------------
9 | class SiLU(nn.Module): # export-friendly version of nn.SiLU()
10 | @staticmethod
11 | def forward(x):
12 | return x * torch.sigmoid(x)
13 |
14 |
15 | class Hardswish(nn.Module): # export-friendly version of nn.Hardswish()
16 | @staticmethod
17 | def forward(x):
18 | # return x * F.hardsigmoid(x) # for torchscript and CoreML
19 | return x * F.hardtanh(x + 3, 0., 6.) / 6. # for torchscript, CoreML and ONNX
20 |
21 |
22 | class MemoryEfficientSwish(nn.Module):
23 | class F(torch.autograd.Function):
24 | @staticmethod
25 | def forward(ctx, x):
26 | ctx.save_for_backward(x)
27 | return x * torch.sigmoid(x)
28 |
29 | @staticmethod
30 | def backward(ctx, grad_output):
31 | x = ctx.saved_tensors[0]
32 | sx = torch.sigmoid(x)
33 | return grad_output * (sx * (1 + x * (1 - sx)))
34 |
35 | def forward(self, x):
36 | return self.F.apply(x)
37 |
38 |
39 | # Mish https://github.com/digantamisra98/Mish --------------------------------------------------------------------------
40 | class Mish(nn.Module):
41 | @staticmethod
42 | def forward(x):
43 | return x * F.softplus(x).tanh()
44 |
45 |
46 | class MemoryEfficientMish(nn.Module):
47 | class F(torch.autograd.Function):
48 | @staticmethod
49 | def forward(ctx, x):
50 | ctx.save_for_backward(x)
51 | return x.mul(torch.tanh(F.softplus(x))) # x * tanh(ln(1 + exp(x)))
52 |
53 | @staticmethod
54 | def backward(ctx, grad_output):
55 | x = ctx.saved_tensors[0]
56 | sx = torch.sigmoid(x)
57 | fx = F.softplus(x).tanh()
58 | return grad_output * (fx + x * sx * (1 - fx * fx))
59 |
60 | def forward(self, x):
61 | return self.F.apply(x)
62 |
63 |
64 | # FReLU https://arxiv.org/abs/2007.11824 -------------------------------------------------------------------------------
65 | class FReLU(nn.Module):
66 | def __init__(self, c1, k=3): # ch_in, kernel
67 | super().__init__()
68 | self.conv = nn.Conv2d(c1, c1, k, 1, 1, groups=c1, bias=False)
69 | self.bn = nn.BatchNorm2d(c1)
70 |
71 | def forward(self, x):
72 | return torch.max(x, self.bn(self.conv(x)))
73 |
--------------------------------------------------------------------------------
/yolov7/utils/add_nms.py:
--------------------------------------------------------------------------------
1 | import numpy as np
2 | import onnx
3 | from onnx import shape_inference
4 | try:
5 | import onnx_graphsurgeon as gs
6 | except Exception as e:
7 | print('Import onnx_graphsurgeon failure: %s' % e)
8 |
9 | import logging
10 |
11 | LOGGER = logging.getLogger(__name__)
12 |
13 | class RegisterNMS(object):
14 | def __init__(
15 | self,
16 | onnx_model_path: str,
17 | precision: str = "fp32",
18 | ):
19 |
20 | self.graph = gs.import_onnx(onnx.load(onnx_model_path))
21 | assert self.graph
22 | LOGGER.info("ONNX graph created successfully")
23 | # Fold constants via ONNX-GS that PyTorch2ONNX may have missed
24 | self.graph.fold_constants()
25 | self.precision = precision
26 | self.batch_size = 1
27 | def infer(self):
28 | """
29 | Sanitize the graph by cleaning any unconnected nodes, do a topological resort,
30 | and fold constant inputs values. When possible, run shape inference on the
31 | ONNX graph to determine tensor shapes.
32 | """
33 | for _ in range(3):
34 | count_before = len(self.graph.nodes)
35 |
36 | self.graph.cleanup().toposort()
37 | try:
38 | for node in self.graph.nodes:
39 | for o in node.outputs:
40 | o.shape = None
41 | model = gs.export_onnx(self.graph)
42 | model = shape_inference.infer_shapes(model)
43 | self.graph = gs.import_onnx(model)
44 | except Exception as e:
45 | LOGGER.info(f"Shape inference could not be performed at this time:\n{e}")
46 | try:
47 | self.graph.fold_constants(fold_shapes=True)
48 | except TypeError as e:
49 | LOGGER.error(
50 | "This version of ONNX GraphSurgeon does not support folding shapes, "
51 | f"please upgrade your onnx_graphsurgeon module. Error:\n{e}"
52 | )
53 | raise
54 |
55 | count_after = len(self.graph.nodes)
56 | if count_before == count_after:
57 | # No new folding occurred in this iteration, so we can stop for now.
58 | break
59 |
60 | def save(self, output_path):
61 | """
62 | Save the ONNX model to the given location.
63 | Args:
64 | output_path: Path pointing to the location where to write
65 | out the updated ONNX model.
66 | """
67 | self.graph.cleanup().toposort()
68 | model = gs.export_onnx(self.graph)
69 | onnx.save(model, output_path)
70 | LOGGER.info(f"Saved ONNX model to {output_path}")
71 |
72 | def register_nms(
73 | self,
74 | *,
75 | score_thresh: float = 0.25,
76 | nms_thresh: float = 0.45,
77 | detections_per_img: int = 100,
78 | ):
79 | """
80 | Register the ``EfficientNMS_TRT`` plugin node.
81 | NMS expects these shapes for its input tensors:
82 | - box_net: [batch_size, number_boxes, 4]
83 | - class_net: [batch_size, number_boxes, number_labels]
84 | Args:
85 | score_thresh (float): The scalar threshold for score (low scoring boxes are removed).
86 | nms_thresh (float): The scalar threshold for IOU (new boxes that have high IOU
87 | overlap with previously selected boxes are removed).
88 | detections_per_img (int): Number of best detections to keep after NMS.
89 | """
90 |
91 | self.infer()
92 | # Find the concat node at the end of the network
93 | op_inputs = self.graph.outputs
94 | op = "EfficientNMS_TRT"
95 | attrs = {
96 | "plugin_version": "1",
97 | "background_class": -1, # no background class
98 | "max_output_boxes": detections_per_img,
99 | "score_threshold": score_thresh,
100 | "iou_threshold": nms_thresh,
101 | "score_activation": False,
102 | "box_coding": 0,
103 | }
104 |
105 | if self.precision == "fp32":
106 | dtype_output = np.float32
107 | elif self.precision == "fp16":
108 | dtype_output = np.float16
109 | else:
110 | raise NotImplementedError(f"Currently not supports precision: {self.precision}")
111 |
112 | # NMS Outputs
113 | output_num_detections = gs.Variable(
114 | name="num_dets",
115 | dtype=np.int32,
116 | shape=[self.batch_size, 1],
117 | ) # A scalar indicating the number of valid detections per batch image.
118 | output_boxes = gs.Variable(
119 | name="det_boxes",
120 | dtype=dtype_output,
121 | shape=[self.batch_size, detections_per_img, 4],
122 | )
123 | output_scores = gs.Variable(
124 | name="det_scores",
125 | dtype=dtype_output,
126 | shape=[self.batch_size, detections_per_img],
127 | )
128 | output_labels = gs.Variable(
129 | name="det_classes",
130 | dtype=np.int32,
131 | shape=[self.batch_size, detections_per_img],
132 | )
133 |
134 | op_outputs = [output_num_detections, output_boxes, output_scores, output_labels]
135 |
136 | # Create the NMS Plugin node with the selected inputs. The outputs of the node will also
137 | # become the final outputs of the graph.
138 | self.graph.layer(op=op, name="batched_nms", inputs=op_inputs, outputs=op_outputs, attrs=attrs)
139 | LOGGER.info(f"Created NMS plugin '{op}' with attributes: {attrs}")
140 |
141 | self.graph.outputs = op_outputs
142 |
143 | self.infer()
144 |
145 | def save(self, output_path):
146 | """
147 | Save the ONNX model to the given location.
148 | Args:
149 | output_path: Path pointing to the location where to write
150 | out the updated ONNX model.
151 | """
152 | self.graph.cleanup().toposort()
153 | model = gs.export_onnx(self.graph)
154 | onnx.save(model, output_path)
155 | LOGGER.info(f"Saved ONNX model to {output_path}")
156 |
--------------------------------------------------------------------------------
/yolov7/utils/autoanchor.py:
--------------------------------------------------------------------------------
1 | # Auto-anchor utils
2 |
3 | import numpy as np
4 | import torch
5 | import yaml
6 | from scipy.cluster.vq import kmeans
7 | from tqdm import tqdm
8 |
9 | from utils.general import colorstr
10 |
11 |
12 | def check_anchor_order(m):
13 | # Check anchor order against stride order for YOLO Detect() module m, and correct if necessary
14 | a = m.anchor_grid.prod(-1).view(-1) # anchor area
15 | da = a[-1] - a[0] # delta a
16 | ds = m.stride[-1] - m.stride[0] # delta s
17 | if da.sign() != ds.sign(): # same order
18 | print('Reversing anchor order')
19 | m.anchors[:] = m.anchors.flip(0)
20 | m.anchor_grid[:] = m.anchor_grid.flip(0)
21 |
22 |
23 | def check_anchors(dataset, model, thr=4.0, imgsz=640):
24 | # Check anchor fit to data, recompute if necessary
25 | prefix = colorstr('autoanchor: ')
26 | print(f'\n{prefix}Analyzing anchors... ', end='')
27 | m = model.module.model[-1] if hasattr(model, 'module') else model.model[-1] # Detect()
28 | shapes = imgsz * dataset.shapes / dataset.shapes.max(1, keepdims=True)
29 | scale = np.random.uniform(0.9, 1.1, size=(shapes.shape[0], 1)) # augment scale
30 | wh = torch.tensor(np.concatenate([l[:, 3:5] * s for s, l in zip(shapes * scale, dataset.labels)])).float() # wh
31 |
32 | def metric(k): # compute metric
33 | r = wh[:, None] / k[None]
34 | x = torch.min(r, 1. / r).min(2)[0] # ratio metric
35 | best = x.max(1)[0] # best_x
36 | aat = (x > 1. / thr).float().sum(1).mean() # anchors above threshold
37 | bpr = (best > 1. / thr).float().mean() # best possible recall
38 | return bpr, aat
39 |
40 | anchors = m.anchor_grid.clone().cpu().view(-1, 2) # current anchors
41 | bpr, aat = metric(anchors)
42 | print(f'anchors/target = {aat:.2f}, Best Possible Recall (BPR) = {bpr:.4f}', end='')
43 | if bpr < 0.98: # threshold to recompute
44 | print('. Attempting to improve anchors, please wait...')
45 | na = m.anchor_grid.numel() // 2 # number of anchors
46 | try:
47 | anchors = kmean_anchors(dataset, n=na, img_size=imgsz, thr=thr, gen=1000, verbose=False)
48 | except Exception as e:
49 | print(f'{prefix}ERROR: {e}')
50 | new_bpr = metric(anchors)[0]
51 | if new_bpr > bpr: # replace anchors
52 | anchors = torch.tensor(anchors, device=m.anchors.device).type_as(m.anchors)
53 | m.anchor_grid[:] = anchors.clone().view_as(m.anchor_grid) # for inference
54 | check_anchor_order(m)
55 | m.anchors[:] = anchors.clone().view_as(m.anchors) / m.stride.to(m.anchors.device).view(-1, 1, 1) # loss
56 | print(f'{prefix}New anchors saved to model. Update model *.yaml to use these anchors in the future.')
57 | else:
58 | print(f'{prefix}Original anchors better than new anchors. Proceeding with original anchors.')
59 | print('') # newline
60 |
61 |
62 | def kmean_anchors(path='./data/coco.yaml', n=9, img_size=640, thr=4.0, gen=1000, verbose=True):
63 | """ Creates kmeans-evolved anchors from training dataset
64 |
65 | Arguments:
66 | path: path to dataset *.yaml, or a loaded dataset
67 | n: number of anchors
68 | img_size: image size used for training
69 | thr: anchor-label wh ratio threshold hyperparameter hyp['anchor_t'] used for training, default=4.0
70 | gen: generations to evolve anchors using genetic algorithm
71 | verbose: print all results
72 |
73 | Return:
74 | k: kmeans evolved anchors
75 |
76 | Usage:
77 | from utils.autoanchor import *; _ = kmean_anchors()
78 | """
79 | thr = 1. / thr
80 | prefix = colorstr('autoanchor: ')
81 |
82 | def metric(k, wh): # compute metrics
83 | r = wh[:, None] / k[None]
84 | x = torch.min(r, 1. / r).min(2)[0] # ratio metric
85 | # x = wh_iou(wh, torch.tensor(k)) # iou metric
86 | return x, x.max(1)[0] # x, best_x
87 |
88 | def anchor_fitness(k): # mutation fitness
89 | _, best = metric(torch.tensor(k, dtype=torch.float32), wh)
90 | return (best * (best > thr).float()).mean() # fitness
91 |
92 | def print_results(k):
93 | k = k[np.argsort(k.prod(1))] # sort small to large
94 | x, best = metric(k, wh0)
95 | bpr, aat = (best > thr).float().mean(), (x > thr).float().mean() * n # best possible recall, anch > thr
96 | print(f'{prefix}thr={thr:.2f}: {bpr:.4f} best possible recall, {aat:.2f} anchors past thr')
97 | print(f'{prefix}n={n}, img_size={img_size}, metric_all={x.mean():.3f}/{best.mean():.3f}-mean/best, '
98 | f'past_thr={x[x > thr].mean():.3f}-mean: ', end='')
99 | for i, x in enumerate(k):
100 | print('%i,%i' % (round(x[0]), round(x[1])), end=', ' if i < len(k) - 1 else '\n') # use in *.cfg
101 | return k
102 |
103 | if isinstance(path, str): # *.yaml file
104 | with open(path) as f:
105 | data_dict = yaml.load(f, Loader=yaml.SafeLoader) # model dict
106 | from utils.datasets import LoadImagesAndLabels
107 | dataset = LoadImagesAndLabels(data_dict['train'], augment=True, rect=True)
108 | else:
109 | dataset = path # dataset
110 |
111 | # Get label wh
112 | shapes = img_size * dataset.shapes / dataset.shapes.max(1, keepdims=True)
113 | wh0 = np.concatenate([l[:, 3:5] * s for s, l in zip(shapes, dataset.labels)]) # wh
114 |
115 | # Filter
116 | i = (wh0 < 3.0).any(1).sum()
117 | if i:
118 | print(f'{prefix}WARNING: Extremely small objects found. {i} of {len(wh0)} labels are < 3 pixels in size.')
119 | wh = wh0[(wh0 >= 2.0).any(1)] # filter > 2 pixels
120 | # wh = wh * (np.random.rand(wh.shape[0], 1) * 0.9 + 0.1) # multiply by random scale 0-1
121 |
122 | # Kmeans calculation
123 | print(f'{prefix}Running kmeans for {n} anchors on {len(wh)} points...')
124 | s = wh.std(0) # sigmas for whitening
125 | k, dist = kmeans(wh / s, n, iter=30) # points, mean distance
126 | assert len(k) == n, print(f'{prefix}ERROR: scipy.cluster.vq.kmeans requested {n} points but returned only {len(k)}')
127 | k *= s
128 | wh = torch.tensor(wh, dtype=torch.float32) # filtered
129 | wh0 = torch.tensor(wh0, dtype=torch.float32) # unfiltered
130 | k = print_results(k)
131 |
132 | # Plot
133 | # k, d = [None] * 20, [None] * 20
134 | # for i in tqdm(range(1, 21)):
135 | # k[i-1], d[i-1] = kmeans(wh / s, i) # points, mean distance
136 | # fig, ax = plt.subplots(1, 2, figsize=(14, 7), tight_layout=True)
137 | # ax = ax.ravel()
138 | # ax[0].plot(np.arange(1, 21), np.array(d) ** 2, marker='.')
139 | # fig, ax = plt.subplots(1, 2, figsize=(14, 7)) # plot wh
140 | # ax[0].hist(wh[wh[:, 0]<100, 0],400)
141 | # ax[1].hist(wh[wh[:, 1]<100, 1],400)
142 | # fig.savefig('wh.png', dpi=200)
143 |
144 | # Evolve
145 | npr = np.random
146 | f, sh, mp, s = anchor_fitness(k), k.shape, 0.9, 0.1 # fitness, generations, mutation prob, sigma
147 | pbar = tqdm(range(gen), desc=f'{prefix}Evolving anchors with Genetic Algorithm:') # progress bar
148 | for _ in pbar:
149 | v = np.ones(sh)
150 | while (v == 1).all(): # mutate until a change occurs (prevent duplicates)
151 | v = ((npr.random(sh) < mp) * npr.random() * npr.randn(*sh) * s + 1).clip(0.3, 3.0)
152 | kg = (k.copy() * v).clip(min=2.0)
153 | fg = anchor_fitness(kg)
154 | if fg > f:
155 | f, k = fg, kg.copy()
156 | pbar.desc = f'{prefix}Evolving anchors with Genetic Algorithm: fitness = {f:.4f}'
157 | if verbose:
158 | print_results(k)
159 |
160 | return print_results(k)
161 |
--------------------------------------------------------------------------------
/yolov7/utils/aws/__init__.py:
--------------------------------------------------------------------------------
1 | #init
--------------------------------------------------------------------------------
/yolov7/utils/aws/mime.sh:
--------------------------------------------------------------------------------
1 | # AWS EC2 instance startup 'MIME' script https://aws.amazon.com/premiumsupport/knowledge-center/execute-user-data-ec2/
2 | # This script will run on every instance restart, not only on first start
3 | # --- DO NOT COPY ABOVE COMMENTS WHEN PASTING INTO USERDATA ---
4 |
5 | Content-Type: multipart/mixed; boundary="//"
6 | MIME-Version: 1.0
7 |
8 | --//
9 | Content-Type: text/cloud-config; charset="us-ascii"
10 | MIME-Version: 1.0
11 | Content-Transfer-Encoding: 7bit
12 | Content-Disposition: attachment; filename="cloud-config.txt"
13 |
14 | #cloud-config
15 | cloud_final_modules:
16 | - [scripts-user, always]
17 |
18 | --//
19 | Content-Type: text/x-shellscript; charset="us-ascii"
20 | MIME-Version: 1.0
21 | Content-Transfer-Encoding: 7bit
22 | Content-Disposition: attachment; filename="userdata.txt"
23 |
24 | #!/bin/bash
25 | # --- paste contents of userdata.sh here ---
26 | --//
27 |
--------------------------------------------------------------------------------
/yolov7/utils/aws/resume.py:
--------------------------------------------------------------------------------
1 | # Resume all interrupted trainings in yolor/ dir including DDP trainings
2 | # Usage: $ python utils/aws/resume.py
3 |
4 | import os
5 | import sys
6 | from pathlib import Path
7 |
8 | import torch
9 | import yaml
10 |
11 | sys.path.append('./') # to run '$ python *.py' files in subdirectories
12 |
13 | port = 0 # --master_port
14 | path = Path('').resolve()
15 | for last in path.rglob('*/**/last.pt'):
16 | ckpt = torch.load(last)
17 | if ckpt['optimizer'] is None:
18 | continue
19 |
20 | # Load opt.yaml
21 | with open(last.parent.parent / 'opt.yaml') as f:
22 | opt = yaml.load(f, Loader=yaml.SafeLoader)
23 |
24 | # Get device count
25 | d = opt['device'].split(',') # devices
26 | nd = len(d) # number of devices
27 | ddp = nd > 1 or (nd == 0 and torch.cuda.device_count() > 1) # distributed data parallel
28 |
29 | if ddp: # multi-GPU
30 | port += 1
31 | cmd = f'python -m torch.distributed.launch --nproc_per_node {nd} --master_port {port} train.py --resume {last}'
32 | else: # single-GPU
33 | cmd = f'python train.py --resume {last}'
34 |
35 | cmd += ' > /dev/null 2>&1 &' # redirect output to dev/null and run in daemon thread
36 | print(cmd)
37 | os.system(cmd)
38 |
--------------------------------------------------------------------------------
/yolov7/utils/aws/userdata.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # AWS EC2 instance startup script https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/user-data.html
3 | # This script will run only once on first instance start (for a re-start script see mime.sh)
4 | # /home/ubuntu (ubuntu) or /home/ec2-user (amazon-linux) is working dir
5 | # Use >300 GB SSD
6 |
7 | cd home/ubuntu
8 | if [ ! -d yolor ]; then
9 | echo "Running first-time script." # install dependencies, download COCO, pull Docker
10 | git clone -b main https://github.com/WongKinYiu/yolov7 && sudo chmod -R 777 yolov7
11 | cd yolov7
12 | bash data/scripts/get_coco.sh && echo "Data done." &
13 | sudo docker pull nvcr.io/nvidia/pytorch:21.08-py3 && echo "Docker done." &
14 | python -m pip install --upgrade pip && pip install -r requirements.txt && python detect.py && echo "Requirements done." &
15 | wait && echo "All tasks done." # finish background tasks
16 | else
17 | echo "Running re-start script." # resume interrupted runs
18 | i=0
19 | list=$(sudo docker ps -qa) # container list i.e. $'one\ntwo\nthree\nfour'
20 | while IFS= read -r id; do
21 | ((i++))
22 | echo "restarting container $i: $id"
23 | sudo docker start $id
24 | # sudo docker exec -it $id python train.py --resume # single-GPU
25 | sudo docker exec -d $id python utils/aws/resume.py # multi-scenario
26 | done <<<"$list"
27 | fi
28 |
--------------------------------------------------------------------------------
/yolov7/utils/google_app_engine/Dockerfile:
--------------------------------------------------------------------------------
1 | FROM gcr.io/google-appengine/python
2 |
3 | # Create a virtualenv for dependencies. This isolates these packages from
4 | # system-level packages.
5 | # Use -p python3 or -p python3.7 to select python version. Default is version 2.
6 | RUN virtualenv /env -p python3
7 |
8 | # Setting these environment variables are the same as running
9 | # source /env/bin/activate.
10 | ENV VIRTUAL_ENV /env
11 | ENV PATH /env/bin:$PATH
12 |
13 | RUN apt-get update && apt-get install -y python-opencv
14 |
15 | # Copy the application's requirements.txt and run pip to install all
16 | # dependencies into the virtualenv.
17 | ADD requirements.txt /app/requirements.txt
18 | RUN pip install -r /app/requirements.txt
19 |
20 | # Add the application source code.
21 | ADD . /app
22 |
23 | # Run a WSGI server to serve the application. gunicorn must be declared as
24 | # a dependency in requirements.txt.
25 | CMD gunicorn -b :$PORT main:app
26 |
--------------------------------------------------------------------------------
/yolov7/utils/google_app_engine/additional_requirements.txt:
--------------------------------------------------------------------------------
1 | # add these requirements in your app on top of the existing ones
2 | pip==18.1
3 | Flask==1.0.2
4 | gunicorn==19.9.0
5 |
--------------------------------------------------------------------------------
/yolov7/utils/google_app_engine/app.yaml:
--------------------------------------------------------------------------------
1 | runtime: custom
2 | env: flex
3 |
4 | service: yolorapp
5 |
6 | liveness_check:
7 | initial_delay_sec: 600
8 |
9 | manual_scaling:
10 | instances: 1
11 | resources:
12 | cpu: 1
13 | memory_gb: 4
14 | disk_size_gb: 20
--------------------------------------------------------------------------------
/yolov7/utils/google_utils.py:
--------------------------------------------------------------------------------
1 | # Google utils: https://cloud.google.com/storage/docs/reference/libraries
2 |
3 | import os
4 | import platform
5 | import subprocess
6 | import time
7 | from pathlib import Path
8 |
9 | import requests
10 | import torch
11 |
12 |
13 | def gsutil_getsize(url=''):
14 | # gs://bucket/file size https://cloud.google.com/storage/docs/gsutil/commands/du
15 | s = subprocess.check_output(f'gsutil du {url}', shell=True).decode('utf-8')
16 | return eval(s.split(' ')[0]) if len(s) else 0 # bytes
17 |
18 |
19 | def attempt_download(file, repo='WongKinYiu/yolov7'):
20 | # Attempt file download if does not exist
21 | file = Path(str(file).strip().replace("'", '').lower())
22 |
23 | if not file.exists():
24 | try:
25 | response = requests.get(f'https://api.github.com/repos/{repo}/releases/latest').json() # github api
26 | assets = [x['name'] for x in response['assets']] # release assets
27 | tag = response['tag_name'] # i.e. 'v1.0'
28 | except: # fallback plan
29 | assets = ['yolov7.pt', 'yolov7-tiny.pt', 'yolov7x.pt', 'yolov7-d6.pt', 'yolov7-e6.pt',
30 | 'yolov7-e6e.pt', 'yolov7-w6.pt']
31 | tag = subprocess.check_output('git tag', shell=True).decode().split()[-1]
32 |
33 | name = file.name
34 | if name in assets:
35 | msg = f'{file} missing, try downloading from https://github.com/{repo}/releases/'
36 | redundant = False # second download option
37 | try: # GitHub
38 | url = f'https://github.com/{repo}/releases/download/{tag}/{name}'
39 | print(f'Downloading {url} to {file}...')
40 | torch.hub.download_url_to_file(url, file)
41 | assert file.exists() and file.stat().st_size > 1E6 # check
42 | except Exception as e: # GCP
43 | print(f'Download error: {e}')
44 | assert redundant, 'No secondary mirror'
45 | url = f'https://storage.googleapis.com/{repo}/ckpt/{name}'
46 | print(f'Downloading {url} to {file}...')
47 | os.system(f'curl -L {url} -o {file}') # torch.hub.download_url_to_file(url, weights)
48 | finally:
49 | if not file.exists() or file.stat().st_size < 1E6: # check
50 | file.unlink(missing_ok=True) # remove partial downloads
51 | print(f'ERROR: Download failure: {msg}')
52 | print('')
53 | return
54 |
55 |
56 | def gdrive_download(id='', file='tmp.zip'):
57 | # Downloads a file from Google Drive. from yolov7.utils.google_utils import *; gdrive_download()
58 | t = time.time()
59 | file = Path(file)
60 | cookie = Path('cookie') # gdrive cookie
61 | print(f'Downloading https://drive.google.com/uc?export=download&id={id} as {file}... ', end='')
62 | file.unlink(missing_ok=True) # remove existing file
63 | cookie.unlink(missing_ok=True) # remove existing cookie
64 |
65 | # Attempt file download
66 | out = "NUL" if platform.system() == "Windows" else "/dev/null"
67 | os.system(f'curl -c ./cookie -s -L "drive.google.com/uc?export=download&id={id}" > {out}')
68 | if os.path.exists('cookie'): # large file
69 | s = f'curl -Lb ./cookie "drive.google.com/uc?export=download&confirm={get_token()}&id={id}" -o {file}'
70 | else: # small file
71 | s = f'curl -s -L -o {file} "drive.google.com/uc?export=download&id={id}"'
72 | r = os.system(s) # execute, capture return
73 | cookie.unlink(missing_ok=True) # remove existing cookie
74 |
75 | # Error check
76 | if r != 0:
77 | file.unlink(missing_ok=True) # remove partial
78 | print('Download error ') # raise Exception('Download error')
79 | return r
80 |
81 | # Unzip if archive
82 | if file.suffix == '.zip':
83 | print('unzipping... ', end='')
84 | os.system(f'unzip -q {file}') # unzip
85 | file.unlink() # remove zip to free space
86 |
87 | print(f'Done ({time.time() - t:.1f}s)')
88 | return r
89 |
90 |
91 | def get_token(cookie="./cookie"):
92 | with open(cookie) as f:
93 | for line in f:
94 | if "download" in line:
95 | return line.split()[-1]
96 | return ""
97 |
98 | # def upload_blob(bucket_name, source_file_name, destination_blob_name):
99 | # # Uploads a file to a bucket
100 | # # https://cloud.google.com/storage/docs/uploading-objects#storage-upload-object-python
101 | #
102 | # storage_client = storage.Client()
103 | # bucket = storage_client.get_bucket(bucket_name)
104 | # blob = bucket.blob(destination_blob_name)
105 | #
106 | # blob.upload_from_filename(source_file_name)
107 | #
108 | # print('File {} uploaded to {}.'.format(
109 | # source_file_name,
110 | # destination_blob_name))
111 | #
112 | #
113 | # def download_blob(bucket_name, source_blob_name, destination_file_name):
114 | # # Uploads a blob from a bucket
115 | # storage_client = storage.Client()
116 | # bucket = storage_client.get_bucket(bucket_name)
117 | # blob = bucket.blob(source_blob_name)
118 | #
119 | # blob.download_to_filename(destination_file_name)
120 | #
121 | # print('Blob {} downloaded to {}.'.format(
122 | # source_blob_name,
123 | # destination_file_name))
124 |
--------------------------------------------------------------------------------
/yolov7/utils/wandb_logging/__init__.py:
--------------------------------------------------------------------------------
1 | # init
--------------------------------------------------------------------------------
/yolov7/utils/wandb_logging/log_dataset.py:
--------------------------------------------------------------------------------
1 | import argparse
2 |
3 | import yaml
4 |
5 | from wandb_utils import WandbLogger
6 |
7 | WANDB_ARTIFACT_PREFIX = 'wandb-artifact://'
8 |
9 |
10 | def create_dataset_artifact(opt):
11 | with open(opt.data) as f:
12 | data = yaml.load(f, Loader=yaml.SafeLoader) # data dict
13 | logger = WandbLogger(opt, '', None, data, job_type='Dataset Creation')
14 |
15 |
16 | if __name__ == '__main__':
17 | parser = argparse.ArgumentParser()
18 | parser.add_argument('--data', type=str, default='data/coco.yaml', help='data.yaml path')
19 | parser.add_argument('--single-cls', action='store_true', help='train as single-class dataset')
20 | parser.add_argument('--project', type=str, default='YOLOR', help='name of W&B Project')
21 | opt = parser.parse_args()
22 | opt.resume = False # Explicitly disallow resume check for dataset upload job
23 |
24 | create_dataset_artifact(opt)
25 |
--------------------------------------------------------------------------------
/yolov8/.gitignore:
--------------------------------------------------------------------------------
1 | lstudio
2 | prepared
3 | prepared-csgo-dataset-24.05.24.zip
4 | runs
--------------------------------------------------------------------------------
/yolov8/YOLOv8/yolov8m/args.yaml:
--------------------------------------------------------------------------------
1 | task: detect
2 | mode: train
3 | model: yolov8m.pt
4 | data: cs2.yaml
5 | epochs: 500
6 | time: null
7 | patience: 50
8 | batch: 128
9 | imgsz: 640
10 | save: true
11 | save_period: -1
12 | cache: disk
13 | device: '0'
14 | workers: 8
15 | project: YOLOv8
16 | name: yolov8m
17 | exist_ok: false
18 | pretrained: false
19 | optimizer: SGD
20 | verbose: false
21 | seed: 0
22 | deterministic: true
23 | single_cls: false
24 | rect: false
25 | cos_lr: false
26 | close_mosaic: 10
27 | resume: yolov8m.pt
28 | amp: true
29 | fraction: 1.0
30 | profile: false
31 | freeze: null
32 | multi_scale: false
33 | overlap_mask: true
34 | mask_ratio: 4
35 | dropout: false
36 | val: true
37 | split: val
38 | save_json: false
39 | save_hybrid: false
40 | conf: 0.001
41 | iou: 0.7
42 | max_det: 300
43 | half: true
44 | dnn: false
45 | plots: false
46 | source: ultralytics/assets/
47 | vid_stride: 1
48 | stream_buffer: false
49 | visualize: false
50 | augment: false
51 | agnostic_nms: false
52 | classes: null
53 | retina_masks: false
54 | embed: null
55 | show: false
56 | save_frames: false
57 | save_txt: false
58 | save_conf: false
59 | save_crop: false
60 | show_labels: true
61 | show_conf: true
62 | show_boxes: true
63 | line_width: null
64 | format: torchscript
65 | keras: false
66 | optimize: false
67 | int8: false
68 | dynamic: false
69 | simplify: false
70 | opset: 17
71 | workspace: 4
72 | nms: false
73 | lr0: 0.01
74 | lrf: 0.01
75 | momentum: 0.937
76 | weight_decay: 0.001
77 | warmup_epochs: 3.0
78 | warmup_momentum: 0.8
79 | warmup_bias_lr: 0.1
80 | box: 7.5
81 | cls: 0.5
82 | dfl: 1.5
83 | pose: 12.0
84 | kobj: 1.0
85 | label_smoothing: 0.0
86 | nbs: 64
87 | hsv_h: 0.015
88 | hsv_s: 0.7
89 | hsv_v: 0.4
90 | degrees: 0.0
91 | translate: 0.1
92 | scale: 0.9
93 | shear: 0.0
94 | perspective: 0.0
95 | flipud: 0.0
96 | fliplr: 0.5
97 | bgr: 0.0
98 | mosaic: 1.0
99 | mixup: 0.1
100 | copy_paste: 0.1
101 | auto_augment: randaugment
102 | erasing: 0.4
103 | crop_fraction: 1.0
104 | cfg: null
105 | tracker: botsort.yaml
106 | image_weights: false
107 | hide_labels: false
108 | hide_conf: false
109 | line_thickness: 3
110 | fl_gamma: 0.0
111 | v5loader: true
112 | save_dir: YOLOv8\yolov8m
113 |
--------------------------------------------------------------------------------
/yolov8/YOLOv8/yolov8s/args.yaml:
--------------------------------------------------------------------------------
1 | task: detect
2 | mode: train
3 | model: yolov8s.pt
4 | data: cs2.yaml
5 | epochs: 500
6 | time: null
7 | patience: 50
8 | batch: 16
9 | imgsz: 416
10 | save: true
11 | save_period: -1
12 | cache: disk
13 | device: '0'
14 | workers: 8
15 | project: YOLOv8
16 | name: yolov8s
17 | exist_ok: false
18 | pretrained: false
19 | optimizer: SGD
20 | verbose: false
21 | seed: 0
22 | deterministic: true
23 | single_cls: false
24 | rect: false
25 | cos_lr: false
26 | close_mosaic: 10
27 | resume: yolov8s.pt
28 | amp: true
29 | fraction: 1.0
30 | profile: false
31 | freeze: null
32 | multi_scale: false
33 | overlap_mask: true
34 | mask_ratio: 4
35 | dropout: false
36 | val: true
37 | split: val
38 | save_json: false
39 | save_hybrid: false
40 | conf: 0.001
41 | iou: 0.7
42 | max_det: 300
43 | half: true
44 | dnn: false
45 | plots: false
46 | source: ultralytics/assets/
47 | vid_stride: 1
48 | stream_buffer: false
49 | visualize: false
50 | augment: false
51 | agnostic_nms: false
52 | classes: null
53 | retina_masks: false
54 | embed: null
55 | show: false
56 | save_frames: false
57 | save_txt: false
58 | save_conf: false
59 | save_crop: false
60 | show_labels: true
61 | show_conf: true
62 | show_boxes: true
63 | line_width: null
64 | format: torchscript
65 | keras: false
66 | optimize: false
67 | int8: false
68 | dynamic: false
69 | simplify: false
70 | opset: 17
71 | workspace: 4
72 | nms: false
73 | lr0: 0.01
74 | lrf: 0.01
75 | momentum: 0.937
76 | weight_decay: 0.001
77 | warmup_epochs: 3.0
78 | warmup_momentum: 0.8
79 | warmup_bias_lr: 0.1
80 | box: 7.5
81 | cls: 0.5
82 | dfl: 1.5
83 | pose: 12.0
84 | kobj: 1.0
85 | label_smoothing: 0.0
86 | nbs: 64
87 | hsv_h: 0.015
88 | hsv_s: 0.7
89 | hsv_v: 0.4
90 | degrees: 0.0
91 | translate: 0.1
92 | scale: 0.5
93 | shear: 0.0
94 | perspective: 0.0
95 | flipud: 0.0
96 | fliplr: 0.5
97 | bgr: 0.0
98 | mosaic: 1.0
99 | mixup: 0.0
100 | copy_paste: 0.0
101 | auto_augment: randaugment
102 | erasing: 0.4
103 | crop_fraction: 1.0
104 | cfg: null
105 | tracker: botsort.yaml
106 | image_weights: false
107 | hide_labels: false
108 | hide_conf: false
109 | line_thickness: 3
110 | fl_gamma: 0.0
111 | v5loader: true
112 | save_dir: YOLOv8\yolov8s
113 |
--------------------------------------------------------------------------------
/yolov8/cs2.yaml:
--------------------------------------------------------------------------------
1 | # train and val data as 1) directory: path/images/, 2) file: path/images.txt, or 3) list: [path1/images/, path2/images/]
2 | train: ./prepared/train # train images
3 | val: ./prepared/val # validate images
4 | test: ./prepared/test # test images
5 |
6 | # number of classes
7 | nc: 4
8 |
9 | # class names
10 | names: [ 'c', 'ch', 't', 'th' ] # person
--------------------------------------------------------------------------------
/yolov8/cs2_yolov8m_640_augmented_v2.pt:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:bf4057a7c2f402c11f8e3f6c5e81ec1822d6cfd2c7fbecb188bf98efa2e05265
3 | size 52036225
4 |
--------------------------------------------------------------------------------
/yolov8/cs2_yolov8m_640_augmented_v3.pt:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:3915a0a98fd6dc389b9cc2104d8a19e60533fffbf9817b8d59949ff7fc1be6f8
3 | size 52048129
4 |
--------------------------------------------------------------------------------
/yolov8/cs2_yolov8m_640_augmented_v4.pt:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:3d64a62f6dc95b8c22883cdd4c97b4a9ffd330948dfb3b319f23c5caf29b2b6b
3 | size 52078401
4 |
--------------------------------------------------------------------------------
/yolov8/cs2_yolov8m_640_clean_base.pt:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:6a614dc5a77c5a5cd7c10bb08bd10f7c718dad45011d7019cdb1a3bd93f87b5c
3 | size 52020865
4 |
--------------------------------------------------------------------------------
/yolov8/cs2_yolov8m_640_clean_base_augmented.pt:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:715d9b7e740f1306856e0f89a3491e0b1cefddefea618409f7565ea21eda115d
3 | size 52020929
4 |
--------------------------------------------------------------------------------
/yolov8/cs2_yolov8s_640.pt:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:6c47d2e2dfe03c7c6b8e040a08fd9f7304ce438ff979ec6f72c17a4ba19ceab4
3 | size 22497945
4 |
--------------------------------------------------------------------------------
/yolov8/datasets/.gitignore:
--------------------------------------------------------------------------------
1 | lstudio
2 | prepared
3 | prepared-csgo-dataset-24.05.24.zip
--------------------------------------------------------------------------------
/yolov8/datasets/Where to get dataset archive.txt:
--------------------------------------------------------------------------------
1 | The size of dataset was too big to upload (even with LFS).
2 | So look for it here https://huggingface.co/datasets/Priler/csgobot
--------------------------------------------------------------------------------
/yolov8/datasets/prepare.py:
--------------------------------------------------------------------------------
1 | import glob, os, sys
2 | from math import *
3 | from tqdm import tqdm
4 | import shutil
5 |
6 | """
7 | @TODO
8 | - Resumable?
9 | - Ask for divide rule?
10 | - Better progress bar.
11 | """
12 |
13 | # input dirs
14 | input_folders = [
15 | './lstudio/allin/',
16 | ]
17 |
18 | # base out dir
19 | BASE_DIR_ABSOLUTE = "D:\\Python\\csgobot\\yolov8\\datasets\\"
20 | OUT_DIR = './prepared/'
21 |
22 | # out dirs
23 | OUT_TRAIN = OUT_DIR + 'train/'
24 | OUT_VAL = OUT_DIR + 'val/'
25 | OUT_TEST = OUT_DIR + 'test/'
26 |
27 | # config
28 | coeff = [80, 10, 10] # train/val/test
29 | exceptions = ['classes'] # .txt files that will be excluded
30 |
31 |
32 | # prepare
33 | if int(coeff[0]) + int(coeff[1]) + int(coeff[2]) > 100:
34 | print("Overall coeff can't exceed 100%.")
35 | exit(1)
36 |
37 |
38 | def chunker(seq, size):
39 | return (seq[pos:pos + size] for pos in range(0, len(seq), size))
40 |
41 | # print some info
42 | print(f"Preparing images data by {coeff[0]}/{coeff[1]}/{coeff[2]} rule.")
43 | print(f"Source folders: {len(input_folders)}")
44 | print("Gathering data ...")
45 |
46 | # collect in
47 | source = {}
48 | total_files = 0
49 | for sf in input_folders:
50 | source.setdefault(sf, [])
51 |
52 | os.chdir(BASE_DIR_ABSOLUTE)
53 | os.chdir(sf)
54 |
55 | for filename in glob.glob("*.txt"):
56 | basename = os.path.splitext(filename)[0]
57 |
58 | if basename in exceptions:
59 | continue
60 |
61 | imgfile = basename + '.png'
62 | if not os.path.isfile(imgfile):
63 | imgfile = basename + '.jpg' # try jpg
64 |
65 | if not os.path.isfile(imgfile):
66 | continue # nothing found, skip
67 |
68 | source[sf].append(imgfile)
69 | total_files += 1
70 |
71 | print(f"Total images: {total_files}")
72 |
73 | # separate by train/val/test rule
74 | train = {}
75 | val = {}
76 | test = {}
77 | for sk, sv in source.items():
78 | chunks = 100
79 | train_chunk = floor(chunks * (coeff[0] / 100))
80 | val_chunk = floor(chunks * (coeff[1] / 100))
81 | test_chunk = floor(chunks * (coeff[2] / 100))
82 | # val_chunk = chunks - train_chunk
83 |
84 | #print(f"t: {train_chunk}\nv: {val_chunk}\nt: {test_chunk}")
85 | #sys.exit(1)
86 |
87 | train.setdefault(sk, [])
88 | val.setdefault(sk, [])
89 | test.setdefault(sk, [])
90 | for item in chunker(sv, chunks):
91 | train[sk].extend(item[0:train_chunk])
92 | val[sk].extend(item[train_chunk:100-test_chunk])
93 | test[sk].extend(item[100-test_chunk:])
94 |
95 | # print(f"Divide info: train({len(train[sk])}) val({len(val[sk])}) test({len(test[sk])})")
96 |
97 | # copy source to prepared
98 | train_sum = 0
99 | val_sum = 0
100 | test_sum = 0
101 |
102 | for sk, sv in train.items():
103 | train_sum += len(sv)
104 |
105 | for sk, sv in val.items():
106 | val_sum += len(sv)
107 |
108 | for sk, sv in test.items():
109 | test_sum += len(sv)
110 |
111 | # print some info
112 | print(f"\nOverall TRAIN images count: {train_sum}")
113 | print(f"Overall VAL images count: {val_sum}")
114 | print(f"Overall TEST images count: {test_sum}")
115 |
116 | os.chdir(BASE_DIR_ABSOLUTE)
117 | print("\nCopying TRAIN source items to prepared folder ...")
118 | for sk, sv in tqdm(train.items()):
119 | for item in tqdm(sv):
120 | basename = os.path.splitext(item)[0]
121 |
122 | imgfile_source = sk + item
123 | txtfile_source = sk + basename + '.txt'
124 |
125 | imgfile_dest = OUT_TRAIN + 'images/' + item
126 | txtfile_dest = OUT_TRAIN + 'labels/' + basename + '.txt'
127 |
128 | shutil.copyfile(imgfile_source, imgfile_dest)
129 | shutil.copyfile(txtfile_source, txtfile_dest)
130 |
131 | os.chdir(BASE_DIR_ABSOLUTE)
132 | print("\nCopying VAL source items to prepared folder ...")
133 | for sk, sv in tqdm(val.items()):
134 | for item in tqdm(sv):
135 | basename = os.path.splitext(item)[0]
136 |
137 | imgfile_source = sk + item
138 | txtfile_source = sk + basename + '.txt'
139 |
140 | imgfile_dest = OUT_VAL + 'images/' + item
141 | txtfile_dest = OUT_VAL + 'labels/' + basename + '.txt'
142 |
143 | shutil.copyfile(imgfile_source, imgfile_dest)
144 | shutil.copyfile(txtfile_source, txtfile_dest)
145 |
146 | os.chdir(BASE_DIR_ABSOLUTE)
147 | print("\nCopying TEST source items to prepared folder ...")
148 | for sk, sv in tqdm(test.items()):
149 | for item in tqdm(sv):
150 | basename = os.path.splitext(item)[0]
151 |
152 | imgfile_source = sk + item
153 | txtfile_source = sk + basename + '.txt'
154 |
155 | imgfile_dest = OUT_TEST + 'images/' + item
156 | txtfile_dest = OUT_TEST + 'labels/' + basename + '.txt'
157 |
158 | shutil.copyfile(imgfile_source, imgfile_dest)
159 | shutil.copyfile(txtfile_source, txtfile_dest)
160 |
161 | # print some info
162 | print("\nDONE!")
--------------------------------------------------------------------------------
/yolov8/train.py:
--------------------------------------------------------------------------------
1 | from ultralytics import YOLO
2 |
3 | # load a pretrained model
4 | model = YOLO('cs2_yolov8m_640_augmented_v4.pt')
5 | # model = YOLO('./runs/detect/cs2_yolov8m_640_augmented_v4/weights/last.pt')
6 |
7 | # training
8 | if __name__ == '__main__':
9 | results = model.train(
10 | data='cs2.yaml',
11 | cfg='cs2_cfg.yaml',
12 | imgsz=640, # 640
13 | epochs=600,
14 | batch=64,
15 | patience=100,
16 | cache="ram",
17 | name='cs2_yolov8m_640_augmented_v4',
18 | device="cuda",
19 | resume=True,
20 | augment=True)
21 | results = model.val()
--------------------------------------------------------------------------------
/yolov8/yolov8m.pt:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:6c25b0b63b1a433843f06d821a9ac1deb8d5805f74f0f38772c7308c5adc55a5
3 | size 52117635
4 |
--------------------------------------------------------------------------------
/yolov8/yolov8n.pt:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:31e20dde3def09e2cf938c7be6fe23d9150bbbe503982af13345706515f2ef95
3 | size 6534387
4 |
--------------------------------------------------------------------------------
/yolov8/yolov8s.pt:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:268e5bb54c640c96c3510224833bc2eeacab4135c6deb41502156e39986b562d
3 | size 22573363
4 |
--------------------------------------------------------------------------------
/yolov8/yolov8s_csgoV1_640.pt:
--------------------------------------------------------------------------------
1 | version https://git-lfs.github.com/spec/v1
2 | oid sha256:91fa61be2b3a05d6d47ded6b81918c023ea4143bc5408712412c1de21d61da95
3 | size 22479800
4 |
--------------------------------------------------------------------------------