Fix pylint: do not use bare 'except' (#5025)

* Fix E722, do not use bare 'except'

* Remove used codes

* Add FileNotFoundError in LoadImagesAndLabels

* Remove AssertionError

* Ignore LoadImagesAndLabels

* Ignore downloads.py

* Ignore torch_utils.py

* Ignore train.py

* Ignore datasets.py

* Enable utils/download.py

* Fixing exception in thop

* Remove unused code

* Fixing exception in LoadImagesAndLabels

* Fixing exception in exif_size

* Fixing exception in parse_model

* Ignore exceptions in requests

* Revert the exception as suggested

* Revert the exception as suggested
This commit is contained in:
Zhiqiang Wang 2021-10-04 08:54:40 +08:00 committed by GitHub
parent b0ade48457
commit 1922ddeac0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 7 deletions

View File

@ -268,7 +268,7 @@ def parse_model(d, ch, model, imgsz): # model_dict, input_channels(3)
for j, a in enumerate(args): for j, a in enumerate(args):
try: try:
args[j] = eval(a) if isinstance(a, str) else a # eval strings args[j] = eval(a) if isinstance(a, str) else a # eval strings
except: except NameError:
pass pass
n = max(round(n * gd), 1) if n > 1 else n # depth gain n = max(round(n * gd), 1) if n > 1 else n # depth gain

View File

@ -233,7 +233,7 @@ def parse_model(d, ch): # model_dict, input_channels(3)
for j, a in enumerate(args): for j, a in enumerate(args):
try: try:
args[j] = eval(a) if isinstance(a, str) else a # eval strings args[j] = eval(a) if isinstance(a, str) else a # eval strings
except: except NameError:
pass pass
n = n_ = max(round(n * gd), 1) if n > 1 else n # depth gain n = n_ = max(round(n * gd), 1) if n > 1 else n # depth gain

View File

@ -499,7 +499,6 @@ def main(opt, callbacks=Callbacks()):
# DDP mode # DDP mode
device = select_device(opt.device, batch_size=opt.batch_size) device = select_device(opt.device, batch_size=opt.batch_size)
if LOCAL_RANK != -1: if LOCAL_RANK != -1:
from datetime import timedelta
assert torch.cuda.device_count() > LOCAL_RANK, 'insufficient CUDA devices for DDP command' 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 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' assert not opt.image_weights, '--image-weights argument is not compatible with DDP training'

View File

@ -152,7 +152,7 @@ def is_colab():
try: try:
import google.colab import google.colab
return True return True
except Exception as e: except ImportError:
return False return False
@ -160,6 +160,7 @@ def is_pip():
# Is file in a pip package? # Is file in a pip package?
return 'site-packages' in Path(__file__).resolve().parts return 'site-packages' in Path(__file__).resolve().parts
def is_ascii(s=''): def is_ascii(s=''):
# Is string composed of all ASCII (no UTF) characters? (note str().isascii() introduced in python 3.7) # 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 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 = pd.read_csv(evolve_csv)
data = data.rename(columns=lambda x: x.strip()) # strip keys data = data.rename(columns=lambda x: x.strip()) # strip keys
i = np.argmax(fitness(data.values[:, :7])) # 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'# Best generation: {i}\n' +
f'# Last generation: {len(data)}\n' + f'# Last generation: {len(data)}\n' +
f'# ' + ', '.join(f'{x.strip():>20s}' for x in keys[:7]) + '\n' + '# ' + ', '.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:>20.5g}' for x in data.values[i, :7]) + '\n\n')
yaml.safe_dump(hyp, f, sort_keys=False) yaml.safe_dump(hyp, f, sort_keys=False)
if bucket: if bucket: