diff --git a/models/tf.py b/models/tf.py index bc6134291aca..5c81147f689a 100644 --- a/models/tf.py +++ b/models/tf.py @@ -268,7 +268,7 @@ def parse_model(d, ch, model, imgsz): # model_dict, input_channels(3) for j, a in enumerate(args): try: args[j] = eval(a) if isinstance(a, str) else a # eval strings - except: + except NameError: pass n = max(round(n * gd), 1) if n > 1 else n # depth gain diff --git a/models/yolo.py b/models/yolo.py index 5d19aad5369f..e6f3afb76722 100644 --- a/models/yolo.py +++ b/models/yolo.py @@ -233,7 +233,7 @@ def parse_model(d, ch): # model_dict, input_channels(3) for j, a in enumerate(args): try: args[j] = eval(a) if isinstance(a, str) else a # eval strings - except: + except NameError: pass n = n_ = max(round(n * gd), 1) if n > 1 else n # depth gain diff --git a/train.py b/train.py index 460c6cd77a0d..aca89e35b4f6 100644 --- a/train.py +++ b/train.py @@ -499,7 +499,6 @@ def main(opt, callbacks=Callbacks()): # DDP mode device = select_device(opt.device, batch_size=opt.batch_size) if LOCAL_RANK != -1: - from datetime import timedelta assert torch.cuda.device_count() > LOCAL_RANK, 'insufficient CUDA devices for DDP command' assert opt.batch_size % WORLD_SIZE == 0, '--batch-size must be multiple of CUDA device count' assert not opt.image_weights, '--image-weights argument is not compatible with DDP training' diff --git a/utils/general.py b/utils/general.py index f2afb480cc63..c2fcf5e9c7f9 100755 --- a/utils/general.py +++ b/utils/general.py @@ -152,7 +152,7 @@ def is_colab(): try: import google.colab return True - except Exception as e: + except ImportError: return False @@ -160,6 +160,7 @@ def is_pip(): # Is file in a pip package? return 'site-packages' in Path(__file__).resolve().parts + def is_ascii(s=''): # Is string composed of all ASCII (no UTF) characters? (note str().isascii() introduced in python 3.7) s = str(s) # convert list, tuple, None, etc. to str @@ -741,11 +742,11 @@ def print_mutation(results, hyp, save_dir, bucket): data = pd.read_csv(evolve_csv) data = data.rename(columns=lambda x: x.strip()) # strip keys i = np.argmax(fitness(data.values[:, :7])) # - f.write(f'# YOLOv5 Hyperparameter Evolution Results\n' + + f.write('# YOLOv5 Hyperparameter Evolution Results\n' + f'# Best generation: {i}\n' + f'# Last generation: {len(data)}\n' + - f'# ' + ', '.join(f'{x.strip():>20s}' for x in keys[:7]) + '\n' + - f'# ' + ', '.join(f'{x:>20.5g}' for x in data.values[i, :7]) + '\n\n') + '# ' + ', '.join(f'{x.strip():>20s}' for x in keys[:7]) + '\n' + + '# ' + ', '.join(f'{x:>20.5g}' for x in data.values[i, :7]) + '\n\n') yaml.safe_dump(hyp, f, sort_keys=False) if bucket: