-
-
Notifications
You must be signed in to change notification settings - Fork 15.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
2,802 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Hyperparameters for COCO training from scratch | ||
# python train.py --batch 40 --cfg yolov5m.yaml --weights '' --data coco.yaml --img 640 --epochs 300 | ||
# See tutorials for hyperparameter evolution https://github.com/ultralytics/yolov5#tutorials | ||
|
||
|
||
lr0: 0.0001 # initial learning rate (SGD=1E-2, Adam=1E-3) | ||
lrf: 0.2 # final OneCycleLR learning rate (lr0 * lrf) | ||
momentum: 0.937 # SGD momentum/Adam beta1 | ||
weight_decay: 0.0005 # optimizer weight decay 5e-4 | ||
warmup_epochs: 0 # warmup epochs (fractions ok) | ||
warmup_momentum: 0.8 # warmup initial momentum | ||
warmup_bias_lr: 0.1 # warmup initial bias lr | ||
box: 0.05 # box loss gain | ||
cls: 0.5 # cls loss gain | ||
cls_pw: 1.0 # cls BCELoss positive_weight | ||
obj: 1.0 # obj loss gain (scale with pixels) | ||
obj_pw: 1.0 # obj BCELoss positive_weight | ||
iou_t: 0.20 # IoU training threshold | ||
anchor_t: 4.0 # anchor-multiple threshold | ||
# anchors: 3 # anchors per output layer (0 to ignore) | ||
fl_gamma: 0.0 # focal loss gamma (efficientDet default gamma=1.5) | ||
hsv_h: 0.015 # image HSV-Hue augmentation (fraction) | ||
hsv_s: 0.7 # image HSV-Saturation augmentation (fraction) | ||
hsv_v: 0.4 # image HSV-Value augmentation (fraction) | ||
degrees: 0.0 # image rotation (+/- deg) | ||
translate: 0.1 # image translation (+/- fraction) | ||
scale: 0.5 # image scale (+/- gain) | ||
shear: 0.0 # image shear (+/- deg) | ||
perspective: 0.0 # image perspective (+/- fraction), range 0-0.001 | ||
flipud: 0.0 # image flip up-down (probability) | ||
fliplr: 0.5 # image flip left-right (probability) | ||
mosaic: 1.0 # image mosaic (probability) | ||
mixup: 0.0 # image mixup (probability) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
docker build --network=host . --rm --pull --no-cache -t yolov5_quant |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/bin/bash | ||
|
||
CMD=${1:-/bin/bash} | ||
NV_VISIBLE_DEVICES=${2:-"0"} | ||
DOCKER_BRIDGE=${3:-"host"} | ||
|
||
docker run -it --rm --name yolov5_quant -p 80:8888 \ | ||
--gpus device=$NV_VISIBLE_DEVICES \ | ||
--net=$DOCKER_BRIDGE \ | ||
--shm-size=16g \ | ||
-v $(dirname $(pwd)):/root/space/projects \ | ||
yolov5_quant $CMD |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
"""Exports a YOLOv5 *.pt model to ONNX and TorchScript formats | ||
Usage: | ||
$ export PYTHONPATH="$PWD" && python models/export.py --weights ./weights/yolov5s.pt --img 640 --batch 1 | ||
""" | ||
|
||
import argparse | ||
import sys | ||
import time | ||
import warnings | ||
|
||
sys.path.append('./') # to run '$ python *.py' files in subdirectories | ||
|
||
import torch | ||
import torch.nn as nn | ||
|
||
import models | ||
from models.experimental import attempt_load | ||
from utils.activations import Hardswish, SiLU | ||
from utils.general import set_logging | ||
from utils.torch_utils import select_device | ||
|
||
# To use Pytorch's own fake quantization functions | ||
from pytorch_quantization import nn as quant_nn | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--weights', type=str, default='./yolov5s.pt', help='weights path') # from yolov5/models/ | ||
parser.add_argument('--img-size', type=int, default=640, help='image size') # height, width | ||
parser.add_argument('--batch-size', type=int, default=1, help='batch size') | ||
parser.add_argument('--dynamic', action='store_true', help='dynamic ONNX axes') | ||
parser.add_argument('--grid', action='store_true', help='export Detect() layer grid') | ||
parser.add_argument('--device', default='cpu', help='cuda device, i.e. 0 or 0,1,2,3 or cpu') | ||
opt = parser.parse_args() | ||
print(opt) | ||
set_logging() | ||
t = time.time() | ||
|
||
# Load PyTorch model | ||
device = select_device(opt.device) | ||
model = attempt_load(opt.weights, map_location=device) # load FP32 model | ||
model.eval() | ||
quant_nn.TensorQuantizer.use_fb_fake_quant = True | ||
model.model[-1].export = not opt.grid # set Detect() layer grid export | ||
|
||
|
||
dummy_input = torch.rand(opt.batch_size, 3, opt.img_size, opt.img_size, device='cuda') | ||
|
||
# ONNX export | ||
try: | ||
import onnx | ||
|
||
print('\nStarting ONNX export with onnx %s...' % onnx.__version__) | ||
f = opt.weights.replace('.pt', '.onnx') # filename | ||
torch.onnx.export(model, dummy_input, f, verbose=False, opset_version=13, input_names=['images'], | ||
output_names= ['output_0', 'output_1', 'output_2'], | ||
dynamic_axes={'images': {0: 'batch', 2: 'height', 3: 'width'}} if opt.dynamic else None) | ||
|
||
# Checks | ||
onnx_model = onnx.load(f) # load onnx model | ||
onnx.checker.check_model(onnx_model) # check onnx model | ||
# print(onnx.helper.printable_graph(onnx_model.graph)) # print a human readable model | ||
print('ONNX export success, saved as %s' % f) | ||
except Exception as e: | ||
print('ONNX export failure: %s' % e) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.