updates
This commit is contained in:
parent
6893f1daf8
commit
96e25462e8
11
detect.py
11
detect.py
|
@ -7,20 +7,19 @@ from utils.datasets import *
|
|||
from utils.utils import *
|
||||
|
||||
|
||||
def detect(
|
||||
cfg,
|
||||
def detect(cfg,
|
||||
data_cfg,
|
||||
weights,
|
||||
images='data/samples', # input folder
|
||||
output='output', # output folder
|
||||
fourcc='mp4v',
|
||||
fourcc='mp4v', # video codec
|
||||
img_size=416,
|
||||
conf_thres=0.5,
|
||||
nms_thres=0.5,
|
||||
save_txt=False,
|
||||
save_images=True,
|
||||
webcam=False
|
||||
):
|
||||
webcam=False):
|
||||
# Initialize
|
||||
device = torch_utils.select_device()
|
||||
torch.backends.cudnn.benchmark = False # set False for reproducible results
|
||||
if os.path.exists(output):
|
||||
|
@ -74,7 +73,7 @@ def detect(
|
|||
|
||||
if det is not None and len(det) > 0:
|
||||
# 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('%gx%g ' % img.shape[2:], end='') # print image size
|
||||
|
|
13
test.py
13
test.py
|
@ -8,8 +8,7 @@ from utils.datasets import *
|
|||
from utils.utils import *
|
||||
|
||||
|
||||
def test(
|
||||
cfg,
|
||||
def test(cfg,
|
||||
data_cfg,
|
||||
weights=None,
|
||||
batch_size=16,
|
||||
|
@ -18,8 +17,8 @@ def test(
|
|||
conf_thres=0.001,
|
||||
nms_thres=0.5,
|
||||
save_json=False,
|
||||
model=None
|
||||
):
|
||||
model=None):
|
||||
# Initialize/load model and set device
|
||||
if model is None:
|
||||
device = torch_utils.select_device()
|
||||
|
||||
|
@ -104,12 +103,10 @@ def test(
|
|||
box = xyxy2xywh(box) # xywh
|
||||
box[:, :2] -= box[:, 2:] / 2 # xy center to top-left corner
|
||||
for di, d in enumerate(pred):
|
||||
jdict.append({
|
||||
'image_id': image_id,
|
||||
jdict.append({'image_id': image_id,
|
||||
'category_id': coco91class[int(d[6])],
|
||||
'bbox': [float3(x) for x in box[di]],
|
||||
'score': float(d[4])
|
||||
})
|
||||
'score': float(d[4])})
|
||||
|
||||
# Assign all predictions as incorrect
|
||||
correct = [0] * len(pred)
|
||||
|
|
11
train.py
11
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.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
|
||||
'xy': 4.062, # xy 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
|
||||
|
||||
|
||||
def train(
|
||||
cfg,
|
||||
def train(cfg,
|
||||
data_cfg,
|
||||
img_size=416,
|
||||
epochs=100, # 500200 batches at bs 16, 117263 images = 273 epochs
|
||||
batch_size=16,
|
||||
accumulate=4, # effective bs = batch_size * accumulate = 8 * 8 = 64
|
||||
freeze_backbone=False,
|
||||
):
|
||||
accumulate=4): # effective bs = batch_size * accumulate = 8 * 8 = 64
|
||||
# Initialize
|
||||
init_seeds()
|
||||
weights = 'weights' + os.sep
|
||||
latest = weights + 'latest.pt'
|
||||
|
@ -178,6 +178,7 @@ def train(
|
|||
scheduler.step()
|
||||
|
||||
# Freeze backbone at epoch 0, unfreeze at epoch 1 (optional)
|
||||
freeze_backbone = False
|
||||
if freeze_backbone and epoch < 2:
|
||||
for name, p in model.named_parameters():
|
||||
if int(name.split('.')[1]) < cutoff: # if layer < 75
|
||||
|
|
Loading…
Reference in New Issue