updates
This commit is contained in:
parent
6893f1daf8
commit
96e25462e8
29
detect.py
29
detect.py
|
@ -7,20 +7,19 @@ from utils.datasets import *
|
||||||
from utils.utils import *
|
from utils.utils import *
|
||||||
|
|
||||||
|
|
||||||
def detect(
|
def detect(cfg,
|
||||||
cfg,
|
data_cfg,
|
||||||
data_cfg,
|
weights,
|
||||||
weights,
|
images='data/samples', # input folder
|
||||||
images='data/samples', # input folder
|
output='output', # output folder
|
||||||
output='output', # output folder
|
fourcc='mp4v', # video codec
|
||||||
fourcc='mp4v',
|
img_size=416,
|
||||||
img_size=416,
|
conf_thres=0.5,
|
||||||
conf_thres=0.5,
|
nms_thres=0.5,
|
||||||
nms_thres=0.5,
|
save_txt=False,
|
||||||
save_txt=False,
|
save_images=True,
|
||||||
save_images=True,
|
webcam=False):
|
||||||
webcam=False
|
# Initialize
|
||||||
):
|
|
||||||
device = torch_utils.select_device()
|
device = torch_utils.select_device()
|
||||||
torch.backends.cudnn.benchmark = False # set False for reproducible results
|
torch.backends.cudnn.benchmark = False # set False for reproducible results
|
||||||
if os.path.exists(output):
|
if os.path.exists(output):
|
||||||
|
@ -74,7 +73,7 @@ def detect(
|
||||||
|
|
||||||
if det is not None and len(det) > 0:
|
if det is not None and len(det) > 0:
|
||||||
# Rescale boxes from 416 to true image size
|
# Rescale boxes from 416 to true image size
|
||||||
det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round() # TODO: clamp to image border https://github.com/ultralytics/yolov3/issues/368
|
det[:, :4] = scale_coords(img.shape[2:], det[:, :4], im0.shape).round()
|
||||||
|
|
||||||
# Print results to screen
|
# Print results to screen
|
||||||
print('%gx%g ' % img.shape[2:], end='') # print image size
|
print('%gx%g ' % img.shape[2:], end='') # print image size
|
||||||
|
|
33
test.py
33
test.py
|
@ -8,18 +8,17 @@ from utils.datasets import *
|
||||||
from utils.utils import *
|
from utils.utils import *
|
||||||
|
|
||||||
|
|
||||||
def test(
|
def test(cfg,
|
||||||
cfg,
|
data_cfg,
|
||||||
data_cfg,
|
weights=None,
|
||||||
weights=None,
|
batch_size=16,
|
||||||
batch_size=16,
|
img_size=416,
|
||||||
img_size=416,
|
iou_thres=0.5,
|
||||||
iou_thres=0.5,
|
conf_thres=0.001,
|
||||||
conf_thres=0.001,
|
nms_thres=0.5,
|
||||||
nms_thres=0.5,
|
save_json=False,
|
||||||
save_json=False,
|
model=None):
|
||||||
model=None
|
# Initialize/load model and set device
|
||||||
):
|
|
||||||
if model is None:
|
if model is None:
|
||||||
device = torch_utils.select_device()
|
device = torch_utils.select_device()
|
||||||
|
|
||||||
|
@ -104,12 +103,10 @@ def test(
|
||||||
box = xyxy2xywh(box) # xywh
|
box = xyxy2xywh(box) # xywh
|
||||||
box[:, :2] -= box[:, 2:] / 2 # xy center to top-left corner
|
box[:, :2] -= box[:, 2:] / 2 # xy center to top-left corner
|
||||||
for di, d in enumerate(pred):
|
for di, d in enumerate(pred):
|
||||||
jdict.append({
|
jdict.append({'image_id': image_id,
|
||||||
'image_id': image_id,
|
'category_id': coco91class[int(d[6])],
|
||||||
'category_id': coco91class[int(d[6])],
|
'bbox': [float3(x) for x in box[di]],
|
||||||
'bbox': [float3(x) for x in box[di]],
|
'score': float(d[4])})
|
||||||
'score': float(d[4])
|
|
||||||
})
|
|
||||||
|
|
||||||
# Assign all predictions as incorrect
|
# Assign all predictions as incorrect
|
||||||
correct = [0] * len(pred)
|
correct = [0] * len(pred)
|
||||||
|
|
19
train.py
19
train.py
|
@ -20,6 +20,8 @@ from utils.utils import *
|
||||||
# 0.268 0.268 0.178 0.240 4.36 1.104 5.596 0.2087 14.47 2.599 16.27 2.406 0.4114 0.001585 -4 0.950 0.000524
|
# 0.268 0.268 0.178 0.240 4.36 1.104 5.596 0.2087 14.47 2.599 16.27 2.406 0.4114 0.001585 -4 0.950 0.000524
|
||||||
# 0.161 0.327 0.190 0.193 7.82 1.153 4.062 0.1845 24.28 3.05 20.93 2.842 0.2759 0.001357 -4 0.916 0.000572 # 320 --epochs 2
|
# 0.161 0.327 0.190 0.193 7.82 1.153 4.062 0.1845 24.28 3.05 20.93 2.842 0.2759 0.001357 -4 0.916 0.000572 # 320 --epochs 2
|
||||||
|
|
||||||
|
|
||||||
|
# Training hyperparameters
|
||||||
hyp = {'giou': 0.8541, # giou loss gain
|
hyp = {'giou': 0.8541, # giou loss gain
|
||||||
'xy': 4.062, # xy loss gain
|
'xy': 4.062, # xy loss gain
|
||||||
'wh': 0.1845, # wh loss gain
|
'wh': 0.1845, # wh loss gain
|
||||||
|
@ -34,15 +36,13 @@ hyp = {'giou': 0.8541, # giou loss gain
|
||||||
'weight_decay': 0.000467} # optimizer weight decay
|
'weight_decay': 0.000467} # optimizer weight decay
|
||||||
|
|
||||||
|
|
||||||
def train(
|
def train(cfg,
|
||||||
cfg,
|
data_cfg,
|
||||||
data_cfg,
|
img_size=416,
|
||||||
img_size=416,
|
epochs=100, # 500200 batches at bs 16, 117263 images = 273 epochs
|
||||||
epochs=100, # 500200 batches at bs 16, 117263 images = 273 epochs
|
batch_size=16,
|
||||||
batch_size=16,
|
accumulate=4): # effective bs = batch_size * accumulate = 8 * 8 = 64
|
||||||
accumulate=4, # effective bs = batch_size * accumulate = 8 * 8 = 64
|
# Initialize
|
||||||
freeze_backbone=False,
|
|
||||||
):
|
|
||||||
init_seeds()
|
init_seeds()
|
||||||
weights = 'weights' + os.sep
|
weights = 'weights' + os.sep
|
||||||
latest = weights + 'latest.pt'
|
latest = weights + 'latest.pt'
|
||||||
|
@ -178,6 +178,7 @@ def train(
|
||||||
scheduler.step()
|
scheduler.step()
|
||||||
|
|
||||||
# Freeze backbone at epoch 0, unfreeze at epoch 1 (optional)
|
# Freeze backbone at epoch 0, unfreeze at epoch 1 (optional)
|
||||||
|
freeze_backbone = False
|
||||||
if freeze_backbone and epoch < 2:
|
if freeze_backbone and epoch < 2:
|
||||||
for name, p in model.named_parameters():
|
for name, p in model.named_parameters():
|
||||||
if int(name.split('.')[1]) < cutoff: # if layer < 75
|
if int(name.split('.')[1]) < cutoff: # if layer < 75
|
||||||
|
|
Loading…
Reference in New Issue