val.py refactor (#4053)

* val.py refactor

* cleanup

* cleanup

* cleanup

* cleanup

* save after eval

* opt.imgsz bug fix

* wandb refactor

* dataloader to train_loader

* capitalize global variables

* runs/hub/exp to runs/detect/exp

* refactor wandb logging

* Refactor wandb operations (#4061)

Co-authored-by: Ayush Chaurasia <ayush.chaurarsia@gmail.com>
This commit is contained in:
Glenn JocherandAyush Chaurasia authored and GitHub committed 2021-07-19 10:43:01 +02:00
1 parent 9dd33fd20f
commit f7d8562060
8 files changed
+219 -202

No files matched your search

+7 -7
View File
@@ -22,7 +22,7 @@ try:
import thop # for FLOPs computation
except ImportError:
thop = None
logger = logging.getLogger(__name__)
LOGGER = logging.getLogger(__name__)
@contextmanager
@@ -85,11 +85,11 @@ def select_device(device='', batch_size=None):
else:
s += 'CPU\n'
logger.info(s.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else s) # emoji-safe
LOGGER.info(s.encode().decode('ascii', 'ignore') if platform.system() == 'Windows' else s) # emoji-safe
return torch.device('cuda:0' if cuda else 'cpu')
def time_synchronized():
def time_sync():
# pytorch-accurate time
if torch.cuda.is_available():
torch.cuda.synchronize()
@@ -118,12 +118,12 @@ def profile(x, ops, n=100, device=None):
flops = 0
for _ in range(n):
t[0] = time_synchronized()
t[0] = time_sync()
y = m(x)
t[1] = time_synchronized()
t[1] = time_sync()
try:
_ = y.sum().backward()
t[2] = time_synchronized()
t[2] = time_sync()
except: # no backward method
t[2] = float('nan')
dtf += (t[1] - t[0]) * 1000 / n # ms per op forward
@@ -231,7 +231,7 @@ def model_info(model, verbose=False, img_size=640):
except (ImportError, Exception):
fs = ''
logger.info(f"Model Summary: {len(list(model.modules()))} layers, {n_p} parameters, {n_g} gradients{fs}")
LOGGER.info(f"Model Summary: {len(list(model.modules()))} layers, {n_p} parameters, {n_g} gradients{fs}")
def load_classifier(name='resnet101', n=2):