Commit
•
0892c44
1
Parent(s):
a925f28
Fix Logging (#719)
Browse files* Add logging setup
* Fix fusing layers message
* Fix logging does not have end
* Add logging
* Change logging to use logger
* Update yolo.py
I tried this in a cloned branch, and everything seems to work fine
* Update yolo.py
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
- detect.py +3 -1
- models/export.py +2 -0
- models/yolo.py +3 -2
- test.py +3 -2
- train.py +2 -2
detect.py
CHANGED
@@ -13,7 +13,8 @@ from numpy import random
|
|
13 |
from models.experimental import attempt_load
|
14 |
from utils.datasets import LoadStreams, LoadImages
|
15 |
from utils.general import (
|
16 |
-
check_img_size, non_max_suppression, apply_classifier, scale_coords,
|
|
|
17 |
from utils.torch_utils import select_device, load_classifier, time_synchronized
|
18 |
|
19 |
|
@@ -23,6 +24,7 @@ def detect(save_img=False):
|
|
23 |
webcam = source == '0' or source.startswith('rtsp') or source.startswith('http') or source.endswith('.txt')
|
24 |
|
25 |
# Initialize
|
|
|
26 |
device = select_device(opt.device)
|
27 |
if os.path.exists(out):
|
28 |
shutil.rmtree(out) # delete output folder
|
|
|
13 |
from models.experimental import attempt_load
|
14 |
from utils.datasets import LoadStreams, LoadImages
|
15 |
from utils.general import (
|
16 |
+
check_img_size, non_max_suppression, apply_classifier, scale_coords,
|
17 |
+
xyxy2xywh, plot_one_box, strip_optimizer, set_logging)
|
18 |
from utils.torch_utils import select_device, load_classifier, time_synchronized
|
19 |
|
20 |
|
|
|
24 |
webcam = source == '0' or source.startswith('rtsp') or source.startswith('http') or source.endswith('.txt')
|
25 |
|
26 |
# Initialize
|
27 |
+
set_logging()
|
28 |
device = select_device(opt.device)
|
29 |
if os.path.exists(out):
|
30 |
shutil.rmtree(out) # delete output folder
|
models/export.py
CHANGED
@@ -9,6 +9,7 @@ import argparse
|
|
9 |
import torch
|
10 |
|
11 |
from utils.google_utils import attempt_download
|
|
|
12 |
|
13 |
if __name__ == '__main__':
|
14 |
parser = argparse.ArgumentParser()
|
@@ -18,6 +19,7 @@ if __name__ == '__main__':
|
|
18 |
opt = parser.parse_args()
|
19 |
opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand
|
20 |
print(opt)
|
|
|
21 |
|
22 |
# Input
|
23 |
img = torch.zeros((opt.batch_size, 3, *opt.img_size)) # image size(1,3,320,192) iDetection
|
|
|
9 |
import torch
|
10 |
|
11 |
from utils.google_utils import attempt_download
|
12 |
+
from utils.general import set_logging
|
13 |
|
14 |
if __name__ == '__main__':
|
15 |
parser = argparse.ArgumentParser()
|
|
|
19 |
opt = parser.parse_args()
|
20 |
opt.img_size *= 2 if len(opt.img_size) == 1 else 1 # expand
|
21 |
print(opt)
|
22 |
+
set_logging()
|
23 |
|
24 |
# Input
|
25 |
img = torch.zeros((opt.batch_size, 3, *opt.img_size)) # image size(1,3,320,192) iDetection
|
models/yolo.py
CHANGED
@@ -9,7 +9,7 @@ import torch.nn as nn
|
|
9 |
|
10 |
from models.common import Conv, Bottleneck, SPP, DWConv, Focus, BottleneckCSP, Concat
|
11 |
from models.experimental import MixConv2d, CrossConv, C3
|
12 |
-
from utils.general import check_anchor_order, make_divisible, check_file
|
13 |
from utils.torch_utils import (
|
14 |
time_synchronized, fuse_conv_and_bn, model_info, scale_img, initialize_weights, select_device)
|
15 |
|
@@ -156,7 +156,7 @@ class Model(nn.Module):
|
|
156 |
# print('%10.3g' % (m.w.detach().sigmoid() * 2)) # shortcut weights
|
157 |
|
158 |
def fuse(self): # fuse model Conv2d() + BatchNorm2d() layers
|
159 |
-
print('Fusing layers... '
|
160 |
for m in self.model.modules():
|
161 |
if type(m) is Conv:
|
162 |
m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatability
|
@@ -239,6 +239,7 @@ if __name__ == '__main__':
|
|
239 |
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
|
240 |
opt = parser.parse_args()
|
241 |
opt.cfg = check_file(opt.cfg) # check file
|
|
|
242 |
device = select_device(opt.device)
|
243 |
|
244 |
# Create model
|
|
|
9 |
|
10 |
from models.common import Conv, Bottleneck, SPP, DWConv, Focus, BottleneckCSP, Concat
|
11 |
from models.experimental import MixConv2d, CrossConv, C3
|
12 |
+
from utils.general import check_anchor_order, make_divisible, check_file, set_logging
|
13 |
from utils.torch_utils import (
|
14 |
time_synchronized, fuse_conv_and_bn, model_info, scale_img, initialize_weights, select_device)
|
15 |
|
|
|
156 |
# print('%10.3g' % (m.w.detach().sigmoid() * 2)) # shortcut weights
|
157 |
|
158 |
def fuse(self): # fuse model Conv2d() + BatchNorm2d() layers
|
159 |
+
print('Fusing layers... ')
|
160 |
for m in self.model.modules():
|
161 |
if type(m) is Conv:
|
162 |
m._non_persistent_buffers_set = set() # pytorch 1.6.0 compatability
|
|
|
239 |
parser.add_argument('--device', default='', help='cuda device, i.e. 0 or 0,1,2,3 or cpu')
|
240 |
opt = parser.parse_args()
|
241 |
opt.cfg = check_file(opt.cfg) # check file
|
242 |
+
set_logging()
|
243 |
device = select_device(opt.device)
|
244 |
|
245 |
# Create model
|
test.py
CHANGED
@@ -13,8 +13,8 @@ from tqdm import tqdm
|
|
13 |
from models.experimental import attempt_load
|
14 |
from utils.datasets import create_dataloader
|
15 |
from utils.general import (
|
16 |
-
coco80_to_coco91_class, check_dataset, check_file, check_img_size, compute_loss, non_max_suppression,
|
17 |
-
|
18 |
from utils.torch_utils import select_device, time_synchronized
|
19 |
|
20 |
|
@@ -39,6 +39,7 @@ def test(data,
|
|
39 |
device = next(model.parameters()).device # get model device
|
40 |
|
41 |
else: # called directly
|
|
|
42 |
device = select_device(opt.device, batch_size=batch_size)
|
43 |
merge, save_txt = opt.merge, opt.save_txt # use Merge NMS, save *.txt labels
|
44 |
if save_txt:
|
|
|
13 |
from models.experimental import attempt_load
|
14 |
from utils.datasets import create_dataloader
|
15 |
from utils.general import (
|
16 |
+
coco80_to_coco91_class, check_dataset, check_file, check_img_size, compute_loss, non_max_suppression, scale_coords,
|
17 |
+
xyxy2xywh, clip_coords, plot_images, xywh2xyxy, box_iou, output_to_target, ap_per_class, set_logging)
|
18 |
from utils.torch_utils import select_device, time_synchronized
|
19 |
|
20 |
|
|
|
39 |
device = next(model.parameters()).device # get model device
|
40 |
|
41 |
else: # called directly
|
42 |
+
set_logging()
|
43 |
device = select_device(opt.device, batch_size=batch_size)
|
44 |
merge, save_txt = opt.merge, opt.save_txt # use Merge NMS, save *.txt labels
|
45 |
if save_txt:
|
train.py
CHANGED
@@ -71,7 +71,7 @@ def train(hyp, opt, device, tb_writer=None):
|
|
71 |
state_dict = ckpt['model'].float().state_dict() # to FP32
|
72 |
state_dict = intersect_dicts(state_dict, model.state_dict(), exclude=exclude) # intersect
|
73 |
model.load_state_dict(state_dict, strict=False) # load
|
74 |
-
|
75 |
else:
|
76 |
model = Model(opt.cfg, ch=3, nc=nc).to(device) # create
|
77 |
|
@@ -234,7 +234,7 @@ def train(hyp, opt, device, tb_writer=None):
|
|
234 |
if rank != -1:
|
235 |
dataloader.sampler.set_epoch(epoch)
|
236 |
pbar = enumerate(dataloader)
|
237 |
-
|
238 |
if rank in [-1, 0]:
|
239 |
pbar = tqdm(pbar, total=nb) # progress bar
|
240 |
optimizer.zero_grad()
|
|
|
71 |
state_dict = ckpt['model'].float().state_dict() # to FP32
|
72 |
state_dict = intersect_dicts(state_dict, model.state_dict(), exclude=exclude) # intersect
|
73 |
model.load_state_dict(state_dict, strict=False) # load
|
74 |
+
logger.info('Transferred %g/%g items from %s' % (len(state_dict), len(model.state_dict()), weights)) # report
|
75 |
else:
|
76 |
model = Model(opt.cfg, ch=3, nc=nc).to(device) # create
|
77 |
|
|
|
234 |
if rank != -1:
|
235 |
dataloader.sampler.set_epoch(epoch)
|
236 |
pbar = enumerate(dataloader)
|
237 |
+
logger.info(('\n' + '%10s' * 8) % ('Epoch', 'gpu_mem', 'GIoU', 'obj', 'cls', 'total', 'targets', 'img_size'))
|
238 |
if rank in [-1, 0]:
|
239 |
pbar = tqdm(pbar, total=nb) # progress bar
|
240 |
optimizer.zero_grad()
|