bplusplus 0.1.1__py3-none-any.whl → 1.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of bplusplus might be problematic. Click here for more details.
- bplusplus/__init__.py +5 -3
- bplusplus/{collect_images.py → collect.py} +3 -3
- bplusplus/prepare.py +573 -0
- bplusplus/train_validate.py +8 -64
- bplusplus/yolov5detect/__init__.py +1 -0
- bplusplus/yolov5detect/detect.py +444 -0
- bplusplus/yolov5detect/export.py +1530 -0
- bplusplus/yolov5detect/insect.yaml +8 -0
- bplusplus/yolov5detect/models/__init__.py +0 -0
- bplusplus/yolov5detect/models/common.py +1109 -0
- bplusplus/yolov5detect/models/experimental.py +130 -0
- bplusplus/yolov5detect/models/hub/anchors.yaml +56 -0
- bplusplus/yolov5detect/models/hub/yolov3-spp.yaml +52 -0
- bplusplus/yolov5detect/models/hub/yolov3-tiny.yaml +42 -0
- bplusplus/yolov5detect/models/hub/yolov3.yaml +52 -0
- bplusplus/yolov5detect/models/hub/yolov5-bifpn.yaml +49 -0
- bplusplus/yolov5detect/models/hub/yolov5-fpn.yaml +43 -0
- bplusplus/yolov5detect/models/hub/yolov5-p2.yaml +55 -0
- bplusplus/yolov5detect/models/hub/yolov5-p34.yaml +42 -0
- bplusplus/yolov5detect/models/hub/yolov5-p6.yaml +57 -0
- bplusplus/yolov5detect/models/hub/yolov5-p7.yaml +68 -0
- bplusplus/yolov5detect/models/hub/yolov5-panet.yaml +49 -0
- bplusplus/yolov5detect/models/hub/yolov5l6.yaml +61 -0
- bplusplus/yolov5detect/models/hub/yolov5m6.yaml +61 -0
- bplusplus/yolov5detect/models/hub/yolov5n6.yaml +61 -0
- bplusplus/yolov5detect/models/hub/yolov5s-LeakyReLU.yaml +50 -0
- bplusplus/yolov5detect/models/hub/yolov5s-ghost.yaml +49 -0
- bplusplus/yolov5detect/models/hub/yolov5s-transformer.yaml +49 -0
- bplusplus/yolov5detect/models/hub/yolov5s6.yaml +61 -0
- bplusplus/yolov5detect/models/hub/yolov5x6.yaml +61 -0
- bplusplus/yolov5detect/models/segment/yolov5l-seg.yaml +49 -0
- bplusplus/yolov5detect/models/segment/yolov5m-seg.yaml +49 -0
- bplusplus/yolov5detect/models/segment/yolov5n-seg.yaml +49 -0
- bplusplus/yolov5detect/models/segment/yolov5s-seg.yaml +49 -0
- bplusplus/yolov5detect/models/segment/yolov5x-seg.yaml +49 -0
- bplusplus/yolov5detect/models/tf.py +797 -0
- bplusplus/yolov5detect/models/yolo.py +495 -0
- bplusplus/yolov5detect/models/yolov5l.yaml +49 -0
- bplusplus/yolov5detect/models/yolov5m.yaml +49 -0
- bplusplus/yolov5detect/models/yolov5n.yaml +49 -0
- bplusplus/yolov5detect/models/yolov5s.yaml +49 -0
- bplusplus/yolov5detect/models/yolov5x.yaml +49 -0
- bplusplus/yolov5detect/utils/__init__.py +97 -0
- bplusplus/yolov5detect/utils/activations.py +134 -0
- bplusplus/yolov5detect/utils/augmentations.py +448 -0
- bplusplus/yolov5detect/utils/autoanchor.py +175 -0
- bplusplus/yolov5detect/utils/autobatch.py +70 -0
- bplusplus/yolov5detect/utils/aws/__init__.py +0 -0
- bplusplus/yolov5detect/utils/aws/mime.sh +26 -0
- bplusplus/yolov5detect/utils/aws/resume.py +41 -0
- bplusplus/yolov5detect/utils/aws/userdata.sh +27 -0
- bplusplus/yolov5detect/utils/callbacks.py +72 -0
- bplusplus/yolov5detect/utils/dataloaders.py +1385 -0
- bplusplus/yolov5detect/utils/docker/Dockerfile +73 -0
- bplusplus/yolov5detect/utils/docker/Dockerfile-arm64 +40 -0
- bplusplus/yolov5detect/utils/docker/Dockerfile-cpu +42 -0
- bplusplus/yolov5detect/utils/downloads.py +136 -0
- bplusplus/yolov5detect/utils/flask_rest_api/README.md +70 -0
- bplusplus/yolov5detect/utils/flask_rest_api/example_request.py +17 -0
- bplusplus/yolov5detect/utils/flask_rest_api/restapi.py +49 -0
- bplusplus/yolov5detect/utils/general.py +1294 -0
- bplusplus/yolov5detect/utils/google_app_engine/Dockerfile +25 -0
- bplusplus/yolov5detect/utils/google_app_engine/additional_requirements.txt +6 -0
- bplusplus/yolov5detect/utils/google_app_engine/app.yaml +16 -0
- bplusplus/yolov5detect/utils/loggers/__init__.py +476 -0
- bplusplus/yolov5detect/utils/loggers/clearml/README.md +222 -0
- bplusplus/yolov5detect/utils/loggers/clearml/__init__.py +0 -0
- bplusplus/yolov5detect/utils/loggers/clearml/clearml_utils.py +230 -0
- bplusplus/yolov5detect/utils/loggers/clearml/hpo.py +90 -0
- bplusplus/yolov5detect/utils/loggers/comet/README.md +250 -0
- bplusplus/yolov5detect/utils/loggers/comet/__init__.py +551 -0
- bplusplus/yolov5detect/utils/loggers/comet/comet_utils.py +151 -0
- bplusplus/yolov5detect/utils/loggers/comet/hpo.py +126 -0
- bplusplus/yolov5detect/utils/loggers/comet/optimizer_config.json +135 -0
- bplusplus/yolov5detect/utils/loggers/wandb/__init__.py +0 -0
- bplusplus/yolov5detect/utils/loggers/wandb/wandb_utils.py +210 -0
- bplusplus/yolov5detect/utils/loss.py +259 -0
- bplusplus/yolov5detect/utils/metrics.py +381 -0
- bplusplus/yolov5detect/utils/plots.py +517 -0
- bplusplus/yolov5detect/utils/segment/__init__.py +0 -0
- bplusplus/yolov5detect/utils/segment/augmentations.py +100 -0
- bplusplus/yolov5detect/utils/segment/dataloaders.py +366 -0
- bplusplus/yolov5detect/utils/segment/general.py +160 -0
- bplusplus/yolov5detect/utils/segment/loss.py +198 -0
- bplusplus/yolov5detect/utils/segment/metrics.py +225 -0
- bplusplus/yolov5detect/utils/segment/plots.py +152 -0
- bplusplus/yolov5detect/utils/torch_utils.py +482 -0
- bplusplus/yolov5detect/utils/triton.py +90 -0
- bplusplus-1.1.0.dist-info/METADATA +179 -0
- bplusplus-1.1.0.dist-info/RECORD +92 -0
- bplusplus/build_model.py +0 -38
- bplusplus-0.1.1.dist-info/METADATA +0 -97
- bplusplus-0.1.1.dist-info/RECORD +0 -8
- {bplusplus-0.1.1.dist-info → bplusplus-1.1.0.dist-info}/LICENSE +0 -0
- {bplusplus-0.1.1.dist-info → bplusplus-1.1.0.dist-info}/WHEEL +0 -0
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
|
|
2
|
+
"""Auto-batch utils."""
|
|
3
|
+
|
|
4
|
+
from copy import deepcopy
|
|
5
|
+
|
|
6
|
+
import numpy as np
|
|
7
|
+
import torch
|
|
8
|
+
|
|
9
|
+
from utils.general import LOGGER, colorstr
|
|
10
|
+
from utils.torch_utils import profile
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def check_train_batch_size(model, imgsz=640, amp=True):
|
|
14
|
+
"""Checks and computes optimal training batch size for YOLOv5 model, given image size and AMP setting."""
|
|
15
|
+
with torch.cuda.amp.autocast(amp):
|
|
16
|
+
return autobatch(deepcopy(model).train(), imgsz) # compute optimal batch size
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def autobatch(model, imgsz=640, fraction=0.8, batch_size=16):
|
|
20
|
+
"""Estimates optimal YOLOv5 batch size using `fraction` of CUDA memory."""
|
|
21
|
+
# Usage:
|
|
22
|
+
# import torch
|
|
23
|
+
# from utils.autobatch import autobatch
|
|
24
|
+
# model = torch.hub.load('ultralytics/yolov5', 'yolov5s', autoshape=False)
|
|
25
|
+
# print(autobatch(model))
|
|
26
|
+
|
|
27
|
+
# Check device
|
|
28
|
+
prefix = colorstr("AutoBatch: ")
|
|
29
|
+
LOGGER.info(f"{prefix}Computing optimal batch size for --imgsz {imgsz}")
|
|
30
|
+
device = next(model.parameters()).device # get model device
|
|
31
|
+
if device.type == "cpu":
|
|
32
|
+
LOGGER.info(f"{prefix}CUDA not detected, using default CPU batch-size {batch_size}")
|
|
33
|
+
return batch_size
|
|
34
|
+
if torch.backends.cudnn.benchmark:
|
|
35
|
+
LOGGER.info(f"{prefix} ⚠️ Requires torch.backends.cudnn.benchmark=False, using default batch-size {batch_size}")
|
|
36
|
+
return batch_size
|
|
37
|
+
|
|
38
|
+
# Inspect CUDA memory
|
|
39
|
+
gb = 1 << 30 # bytes to GiB (1024 ** 3)
|
|
40
|
+
d = str(device).upper() # 'CUDA:0'
|
|
41
|
+
properties = torch.cuda.get_device_properties(device) # device properties
|
|
42
|
+
t = properties.total_memory / gb # GiB total
|
|
43
|
+
r = torch.cuda.memory_reserved(device) / gb # GiB reserved
|
|
44
|
+
a = torch.cuda.memory_allocated(device) / gb # GiB allocated
|
|
45
|
+
f = t - (r + a) # GiB free
|
|
46
|
+
LOGGER.info(f"{prefix}{d} ({properties.name}) {t:.2f}G total, {r:.2f}G reserved, {a:.2f}G allocated, {f:.2f}G free")
|
|
47
|
+
|
|
48
|
+
# Profile batch sizes
|
|
49
|
+
batch_sizes = [1, 2, 4, 8, 16]
|
|
50
|
+
try:
|
|
51
|
+
img = [torch.empty(b, 3, imgsz, imgsz) for b in batch_sizes]
|
|
52
|
+
results = profile(img, model, n=3, device=device)
|
|
53
|
+
except Exception as e:
|
|
54
|
+
LOGGER.warning(f"{prefix}{e}")
|
|
55
|
+
|
|
56
|
+
# Fit a solution
|
|
57
|
+
y = [x[2] for x in results if x] # memory [2]
|
|
58
|
+
p = np.polyfit(batch_sizes[: len(y)], y, deg=1) # first degree polynomial fit
|
|
59
|
+
b = int((f * fraction - p[1]) / p[0]) # y intercept (optimal batch size)
|
|
60
|
+
if None in results: # some sizes failed
|
|
61
|
+
i = results.index(None) # first fail index
|
|
62
|
+
if b >= batch_sizes[i]: # y intercept above failure point
|
|
63
|
+
b = batch_sizes[max(i - 1, 0)] # select prior safe point
|
|
64
|
+
if b < 1 or b > 1024: # b outside of safe range
|
|
65
|
+
b = batch_size
|
|
66
|
+
LOGGER.warning(f"{prefix}WARNING ⚠️ CUDA anomaly detected, recommend restart environment and retry command.")
|
|
67
|
+
|
|
68
|
+
fraction = (np.polyval(p, b) + r + a) / t # actual fraction predicted
|
|
69
|
+
LOGGER.info(f"{prefix}Using batch-size {b} for {d} {t * fraction:.2f}G/{t:.2f}G ({fraction * 100:.0f}%) ✅")
|
|
70
|
+
return b
|
|
File without changes
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
--//
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
|
|
2
|
+
# Resume all interrupted trainings in yolov5/ dir including DDP trainings
|
|
3
|
+
# Usage: $ python utils/aws/resume.py
|
|
4
|
+
|
|
5
|
+
import os
|
|
6
|
+
import sys
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
|
|
9
|
+
import torch
|
|
10
|
+
import yaml
|
|
11
|
+
|
|
12
|
+
FILE = Path(__file__).resolve()
|
|
13
|
+
ROOT = FILE.parents[2] # YOLOv5 root directory
|
|
14
|
+
if str(ROOT) not in sys.path:
|
|
15
|
+
sys.path.append(str(ROOT)) # add ROOT to PATH
|
|
16
|
+
|
|
17
|
+
port = 0 # --master_port
|
|
18
|
+
path = Path("").resolve()
|
|
19
|
+
for last in path.rglob("*/**/last.pt"):
|
|
20
|
+
ckpt = torch.load(last)
|
|
21
|
+
if ckpt["optimizer"] is None:
|
|
22
|
+
continue
|
|
23
|
+
|
|
24
|
+
# Load opt.yaml
|
|
25
|
+
with open(last.parent.parent / "opt.yaml", errors="ignore") as f:
|
|
26
|
+
opt = yaml.safe_load(f)
|
|
27
|
+
|
|
28
|
+
# Get device count
|
|
29
|
+
d = opt["device"].split(",") # devices
|
|
30
|
+
nd = len(d) # number of devices
|
|
31
|
+
ddp = nd > 1 or (nd == 0 and torch.cuda.device_count() > 1) # distributed data parallel
|
|
32
|
+
|
|
33
|
+
if ddp: # multi-GPU
|
|
34
|
+
port += 1
|
|
35
|
+
cmd = f"python -m torch.distributed.run --nproc_per_node {nd} --master_port {port} train.py --resume {last}"
|
|
36
|
+
else: # single-GPU
|
|
37
|
+
cmd = f"python train.py --resume {last}"
|
|
38
|
+
|
|
39
|
+
cmd += " > /dev/null 2>&1 &" # redirect output to dev/null and run in daemon thread
|
|
40
|
+
print(cmd)
|
|
41
|
+
os.system(cmd)
|
|
@@ -0,0 +1,27 @@
|
|
|
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 yolov5 ]; then
|
|
9
|
+
echo "Running first-time script." # install dependencies, download COCO, pull Docker
|
|
10
|
+
git clone https://github.com/ultralytics/yolov5 -b master && sudo chmod -R 777 yolov5
|
|
11
|
+
cd yolov5
|
|
12
|
+
bash data/scripts/get_coco.sh && echo "COCO done." &
|
|
13
|
+
sudo docker pull ultralytics/yolov5:latest && 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
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Ultralytics YOLOv5 🚀, AGPL-3.0 license
|
|
2
|
+
"""Callback utils."""
|
|
3
|
+
|
|
4
|
+
import threading
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class Callbacks:
|
|
8
|
+
"""Handles all registered callbacks for YOLOv5 Hooks."""
|
|
9
|
+
|
|
10
|
+
def __init__(self):
|
|
11
|
+
"""Initializes a Callbacks object to manage registered YOLOv5 training event hooks."""
|
|
12
|
+
self._callbacks = {
|
|
13
|
+
"on_pretrain_routine_start": [],
|
|
14
|
+
"on_pretrain_routine_end": [],
|
|
15
|
+
"on_train_start": [],
|
|
16
|
+
"on_train_epoch_start": [],
|
|
17
|
+
"on_train_batch_start": [],
|
|
18
|
+
"optimizer_step": [],
|
|
19
|
+
"on_before_zero_grad": [],
|
|
20
|
+
"on_train_batch_end": [],
|
|
21
|
+
"on_train_epoch_end": [],
|
|
22
|
+
"on_val_start": [],
|
|
23
|
+
"on_val_batch_start": [],
|
|
24
|
+
"on_val_image_end": [],
|
|
25
|
+
"on_val_batch_end": [],
|
|
26
|
+
"on_val_end": [],
|
|
27
|
+
"on_fit_epoch_end": [], # fit = train + val
|
|
28
|
+
"on_model_save": [],
|
|
29
|
+
"on_train_end": [],
|
|
30
|
+
"on_params_update": [],
|
|
31
|
+
"teardown": [],
|
|
32
|
+
}
|
|
33
|
+
self.stop_training = False # set True to interrupt training
|
|
34
|
+
|
|
35
|
+
def register_action(self, hook, name="", callback=None):
|
|
36
|
+
"""
|
|
37
|
+
Register a new action to a callback hook.
|
|
38
|
+
|
|
39
|
+
Args:
|
|
40
|
+
hook: The callback hook name to register the action to
|
|
41
|
+
name: The name of the action for later reference
|
|
42
|
+
callback: The callback to fire
|
|
43
|
+
"""
|
|
44
|
+
assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}"
|
|
45
|
+
assert callable(callback), f"callback '{callback}' is not callable"
|
|
46
|
+
self._callbacks[hook].append({"name": name, "callback": callback})
|
|
47
|
+
|
|
48
|
+
def get_registered_actions(self, hook=None):
|
|
49
|
+
"""
|
|
50
|
+
Returns all the registered actions by callback hook.
|
|
51
|
+
|
|
52
|
+
Args:
|
|
53
|
+
hook: The name of the hook to check, defaults to all
|
|
54
|
+
"""
|
|
55
|
+
return self._callbacks[hook] if hook else self._callbacks
|
|
56
|
+
|
|
57
|
+
def run(self, hook, *args, thread=False, **kwargs):
|
|
58
|
+
"""
|
|
59
|
+
Loop through the registered actions and fire all callbacks on main thread.
|
|
60
|
+
|
|
61
|
+
Args:
|
|
62
|
+
hook: The name of the hook to check, defaults to all
|
|
63
|
+
args: Arguments to receive from YOLOv5
|
|
64
|
+
thread: (boolean) Run callbacks in daemon thread
|
|
65
|
+
kwargs: Keyword Arguments to receive from YOLOv5
|
|
66
|
+
"""
|
|
67
|
+
assert hook in self._callbacks, f"hook '{hook}' not found in callbacks {self._callbacks}"
|
|
68
|
+
for logger in self._callbacks[hook]:
|
|
69
|
+
if thread:
|
|
70
|
+
threading.Thread(target=logger["callback"], args=args, kwargs=kwargs, daemon=True).start()
|
|
71
|
+
else:
|
|
72
|
+
logger["callback"](*args, **kwargs)
|