Zhiqiang Wang
commited on
Fix pylint: do not use bare 'except' (#5025)
Browse files* 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
- models/tf.py +1 -1
- models/yolo.py +1 -1
- train.py +0 -1
- utils/general.py +5 -4
models/tf.py
CHANGED
@@ -268,7 +268,7 @@ def parse_model(d, ch, model, imgsz): # model_dict, input_channels(3)
|
|
268 |
for j, a in enumerate(args):
|
269 |
try:
|
270 |
args[j] = eval(a) if isinstance(a, str) else a # eval strings
|
271 |
-
except:
|
272 |
pass
|
273 |
|
274 |
n = max(round(n * gd), 1) if n > 1 else n # depth gain
|
|
|
268 |
for j, a in enumerate(args):
|
269 |
try:
|
270 |
args[j] = eval(a) if isinstance(a, str) else a # eval strings
|
271 |
+
except NameError:
|
272 |
pass
|
273 |
|
274 |
n = max(round(n * gd), 1) if n > 1 else n # depth gain
|
models/yolo.py
CHANGED
@@ -233,7 +233,7 @@ def parse_model(d, ch): # model_dict, input_channels(3)
|
|
233 |
for j, a in enumerate(args):
|
234 |
try:
|
235 |
args[j] = eval(a) if isinstance(a, str) else a # eval strings
|
236 |
-
except:
|
237 |
pass
|
238 |
|
239 |
n = n_ = max(round(n * gd), 1) if n > 1 else n # depth gain
|
|
|
233 |
for j, a in enumerate(args):
|
234 |
try:
|
235 |
args[j] = eval(a) if isinstance(a, str) else a # eval strings
|
236 |
+
except NameError:
|
237 |
pass
|
238 |
|
239 |
n = n_ = max(round(n * gd), 1) if n > 1 else n # depth gain
|
train.py
CHANGED
@@ -499,7 +499,6 @@ def main(opt, callbacks=Callbacks()):
|
|
499 |
# DDP mode
|
500 |
device = select_device(opt.device, batch_size=opt.batch_size)
|
501 |
if LOCAL_RANK != -1:
|
502 |
-
from datetime import timedelta
|
503 |
assert torch.cuda.device_count() > LOCAL_RANK, 'insufficient CUDA devices for DDP command'
|
504 |
assert opt.batch_size % WORLD_SIZE == 0, '--batch-size must be multiple of CUDA device count'
|
505 |
assert not opt.image_weights, '--image-weights argument is not compatible with DDP training'
|
|
|
499 |
# DDP mode
|
500 |
device = select_device(opt.device, batch_size=opt.batch_size)
|
501 |
if LOCAL_RANK != -1:
|
|
|
502 |
assert torch.cuda.device_count() > LOCAL_RANK, 'insufficient CUDA devices for DDP command'
|
503 |
assert opt.batch_size % WORLD_SIZE == 0, '--batch-size must be multiple of CUDA device count'
|
504 |
assert not opt.image_weights, '--image-weights argument is not compatible with DDP training'
|
utils/general.py
CHANGED
@@ -152,7 +152,7 @@ def is_colab():
|
|
152 |
try:
|
153 |
import google.colab
|
154 |
return True
|
155 |
-
except
|
156 |
return False
|
157 |
|
158 |
|
@@ -160,6 +160,7 @@ def is_pip():
|
|
160 |
# Is file in a pip package?
|
161 |
return 'site-packages' in Path(__file__).resolve().parts
|
162 |
|
|
|
163 |
def is_ascii(s=''):
|
164 |
# Is string composed of all ASCII (no UTF) characters? (note str().isascii() introduced in python 3.7)
|
165 |
s = str(s) # convert list, tuple, None, etc. to str
|
@@ -741,11 +742,11 @@ def print_mutation(results, hyp, save_dir, bucket):
|
|
741 |
data = pd.read_csv(evolve_csv)
|
742 |
data = data.rename(columns=lambda x: x.strip()) # strip keys
|
743 |
i = np.argmax(fitness(data.values[:, :7])) #
|
744 |
-
f.write(
|
745 |
f'# Best generation: {i}\n' +
|
746 |
f'# Last generation: {len(data)}\n' +
|
747 |
-
|
748 |
-
|
749 |
yaml.safe_dump(hyp, f, sort_keys=False)
|
750 |
|
751 |
if bucket:
|
|
|
152 |
try:
|
153 |
import google.colab
|
154 |
return True
|
155 |
+
except ImportError:
|
156 |
return False
|
157 |
|
158 |
|
|
|
160 |
# Is file in a pip package?
|
161 |
return 'site-packages' in Path(__file__).resolve().parts
|
162 |
|
163 |
+
|
164 |
def is_ascii(s=''):
|
165 |
# Is string composed of all ASCII (no UTF) characters? (note str().isascii() introduced in python 3.7)
|
166 |
s = str(s) # convert list, tuple, None, etc. to str
|
|
|
742 |
data = pd.read_csv(evolve_csv)
|
743 |
data = data.rename(columns=lambda x: x.strip()) # strip keys
|
744 |
i = np.argmax(fitness(data.values[:, :7])) #
|
745 |
+
f.write('# YOLOv5 Hyperparameter Evolution Results\n' +
|
746 |
f'# Best generation: {i}\n' +
|
747 |
f'# Last generation: {len(data)}\n' +
|
748 |
+
'# ' + ', '.join(f'{x.strip():>20s}' for x in keys[:7]) + '\n' +
|
749 |
+
'# ' + ', '.join(f'{x:>20.5g}' for x in data.values[i, :7]) + '\n\n')
|
750 |
yaml.safe_dump(hyp, f, sort_keys=False)
|
751 |
|
752 |
if bucket:
|