updates
This commit is contained in:
parent
42221c6822
commit
ad0860dbe2
26
test.py
26
test.py
|
@ -5,18 +5,18 @@ from utils.datasets import *
|
||||||
from utils.utils import *
|
from utils.utils import *
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('--epochs', type=int, default=200, help='number of epochs')
|
parser.add_argument('-epochs', type=int, default=200, help='number of epochs')
|
||||||
parser.add_argument('--batch_size', type=int, default=32, help='size of each image batch')
|
parser.add_argument('-batch_size', type=int, default=32, help='size of each image batch')
|
||||||
parser.add_argument('--model_config_path', type=str, default='cfg/yolov3.cfg', help='path to model config file')
|
parser.add_argument('-cfg', type=str, default='cfg/yolov3.cfg', help='path to model config file')
|
||||||
parser.add_argument('--data_config_path', type=str, default='cfg/coco.data', help='path to data config file')
|
parser.add_argument('-data_config_path', type=str, default='cfg/coco.data', help='path to data config file')
|
||||||
parser.add_argument('--weights_path', type=str, default='checkpoints/yolov3.weights', help='path to weights file')
|
parser.add_argument('-weights_path', type=str, default='checkpoints/yolov3.weights', help='path to weights file')
|
||||||
parser.add_argument('--class_path', type=str, default='data/coco.names', help='path to class label file')
|
parser.add_argument('-class_path', type=str, default='data/coco.names', help='path to class label file')
|
||||||
parser.add_argument('--iou_thres', type=float, default=0.5, help='iou threshold required to qualify as detected')
|
parser.add_argument('-iou_thres', type=float, default=0.5, help='iou threshold required to qualify as detected')
|
||||||
parser.add_argument('--conf_thres', type=float, default=0.5, help='object confidence threshold')
|
parser.add_argument('-conf_thres', type=float, default=0.5, help='object confidence threshold')
|
||||||
parser.add_argument('--nms_thres', type=float, default=0.45, help='iou threshold for non-maximum suppression')
|
parser.add_argument('-nms_thres', type=float, default=0.45, help='iou threshold for non-maximum suppression')
|
||||||
parser.add_argument('--n_cpu', type=int, default=0, help='number of cpu threads to use during batch generation')
|
parser.add_argument('-n_cpu', type=int, default=0, help='number of cpu threads to use during batch generation')
|
||||||
parser.add_argument('--img_size', type=int, default=416, help='size of each image dimension')
|
parser.add_argument('-img_size', type=int, default=416, help='size of each image dimension')
|
||||||
parser.add_argument('--use_cuda', type=bool, default=True, help='whether to use cuda if available')
|
parser.add_argument('-use_cuda', type=bool, default=True, help='whether to use cuda if available')
|
||||||
opt = parser.parse_args()
|
opt = parser.parse_args()
|
||||||
print(opt)
|
print(opt)
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ test_path = data_config['valid']
|
||||||
num_classes = int(data_config['classes'])
|
num_classes = int(data_config['classes'])
|
||||||
|
|
||||||
# Initiate model
|
# Initiate model
|
||||||
model = Darknet(opt.model_config_path, opt.img_size)
|
model = Darknet(opt.cfg, opt.img_size)
|
||||||
|
|
||||||
# Load weights
|
# Load weights
|
||||||
weights_path = 'checkpoints/yolov3.pt'
|
weights_path = 'checkpoints/yolov3.pt'
|
||||||
|
|
4
train.py
4
train.py
|
@ -1,6 +1,5 @@
|
||||||
import argparse
|
import argparse
|
||||||
import time
|
import time
|
||||||
from sys import platform
|
|
||||||
|
|
||||||
from models import *
|
from models import *
|
||||||
from utils.datasets import *
|
from utils.datasets import *
|
||||||
|
@ -27,6 +26,7 @@ if cuda:
|
||||||
torch.cuda.manual_seed_all(0)
|
torch.cuda.manual_seed_all(0)
|
||||||
torch.backends.cudnn.benchmark = True
|
torch.backends.cudnn.benchmark = True
|
||||||
|
|
||||||
|
|
||||||
def main(opt):
|
def main(opt):
|
||||||
os.makedirs('checkpoints', exist_ok=True)
|
os.makedirs('checkpoints', exist_ok=True)
|
||||||
|
|
||||||
|
@ -93,7 +93,7 @@ def main(opt):
|
||||||
for epoch in range(opt.epochs):
|
for epoch in range(opt.epochs):
|
||||||
epoch += start_epoch
|
epoch += start_epoch
|
||||||
|
|
||||||
# img_size = random.choice([19, 20, 21, 22, 23, 24, 25]) * 32
|
# img_size = random.choice(range(10, 20)) * 32
|
||||||
# dataloader = ListDataset(train_path, batch_size=opt.batch_size, img_size=img_size, targets_path=targets_path)
|
# dataloader = ListDataset(train_path, batch_size=opt.batch_size, img_size=img_size, targets_path=targets_path)
|
||||||
# print('Running image size %g' % img_size)
|
# print('Running image size %g' % img_size)
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ class ListDataset(): # for training
|
||||||
if img is None:
|
if img is None:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
augment_hsv = False
|
augment_hsv = True
|
||||||
if augment_hsv:
|
if augment_hsv:
|
||||||
# SV augmentation by 50%
|
# SV augmentation by 50%
|
||||||
fraction = 0.50
|
fraction = 0.50
|
||||||
|
@ -150,13 +150,15 @@ class ListDataset(): # for training
|
||||||
labels = np.array([])
|
labels = np.array([])
|
||||||
|
|
||||||
# Augment image and labels
|
# Augment image and labels
|
||||||
# img, labels, M = random_affine(img, targets=labels, degrees=(-10, 10), translate=(0.2, 0.2), scale=(0.8, 1.2)) # RGB
|
img, labels, M = random_affine(img, targets=labels, degrees=(-5, 5), translate=(0.2, 0.2), scale=(0.8, 1.2)) # RGB
|
||||||
|
|
||||||
plotFlag = False
|
plotFlag = False
|
||||||
if plotFlag:
|
if plotFlag:
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
|
plt.figure(figsize=(10, 10)) if index == 0 else None
|
||||||
plt.subplot(4, 4, index + 1).imshow(img[:, :, ::-1])
|
plt.subplot(4, 4, index + 1).imshow(img[:, :, ::-1])
|
||||||
plt.plot(labels[:, [1, 3, 3, 1, 1]].T, labels[:, [2, 2, 4, 4, 2]].T, '.-')
|
plt.plot(labels[:, [1, 3, 3, 1, 1]].T, labels[:, [2, 2, 4, 4, 2]].T, '.-')
|
||||||
|
plt.axis('off')
|
||||||
|
|
||||||
nL = len(labels)
|
nL = len(labels)
|
||||||
if nL > 0:
|
if nL > 0:
|
||||||
|
@ -164,7 +166,7 @@ class ListDataset(): # for training
|
||||||
labels[:, 1:5] = xyxy2xywh(labels[:, 1:5].copy()) / height
|
labels[:, 1:5] = xyxy2xywh(labels[:, 1:5].copy()) / height
|
||||||
|
|
||||||
# random left-right flip
|
# random left-right flip
|
||||||
lr_flip = False
|
lr_flip = True
|
||||||
if lr_flip & (random.random() > 0.5):
|
if lr_flip & (random.random() > 0.5):
|
||||||
img = np.fliplr(img)
|
img = np.fliplr(img)
|
||||||
if nL > 0:
|
if nL > 0:
|
||||||
|
@ -206,7 +208,7 @@ def resize_square(img, height=416, color=(0, 0, 0)): # resize a rectangular ima
|
||||||
|
|
||||||
|
|
||||||
def random_affine(img, targets=None, degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-3, 3),
|
def random_affine(img, targets=None, degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-3, 3),
|
||||||
borderValue=(0, 0, 0)):
|
borderValue=(127.5, 127.5, 127.5)):
|
||||||
# torchvision.transforms.RandomAffine(degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-10, 10))
|
# torchvision.transforms.RandomAffine(degrees=(-10, 10), translate=(.1, .1), scale=(.9, 1.1), shear=(-10, 10))
|
||||||
# https://medium.com/uruvideo/dataset-augmentation-with-random-homographies-a8f4b44830d4
|
# https://medium.com/uruvideo/dataset-augmentation-with-random-homographies-a8f4b44830d4
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue