Use contextlib's suppress method to silence an error (#8668)

pull/8674/head
Glenn Jocher 2022-07-21 23:12:49 +02:00 committed by GitHub
parent 602d7ffb0e
commit 4c1784bd15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 3 deletions

View File

@ -7,6 +7,7 @@ Usage:
"""
import argparse
import contextlib
import os
import platform
import sys
@ -259,10 +260,8 @@ def parse_model(d, ch): # model_dict, input_channels(3)
for i, (f, n, m, args) in enumerate(d['backbone'] + d['head']): # from, number, module, args
m = eval(m) if isinstance(m, str) else m # eval strings
for j, a in enumerate(args):
try:
with contextlib.suppress(NameError):
args[j] = eval(a) if isinstance(a, str) else a # eval strings
except NameError:
pass
n = n_ = max(round(n * gd), 1) if n > 1 else n # depth gain
if m in (Conv, GhostConv, Bottleneck, GhostBottleneck, SPP, SPPF, DWConv, MixConv2d, Focus, CrossConv,