Skip to content

Commit 4c04d0b

Browse files
PyUpgrade 3.8 updates (#55)
Co-authored-by: UltralyticsAssistant <web@ultralytics.com>
1 parent a39771d commit 4c04d0b

4 files changed

Lines changed: 5 additions & 11 deletions

File tree

benchmark/evaluate_famous_models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,6 @@
2323
dsize = (1, 3, 299, 299)
2424
inputs = torch.randn(dsize).to(device)
2525
total_ops, total_params = profile(model, (inputs,), verbose=False)
26-
print("%s | %.2f | %.2f" % (name, total_params / (1000**2), total_ops / (1000**3)))
26+
print(f"{name} | {total_params / (1000**2):.2f} | {total_ops / (1000**3):.2f}")
2727
except Exception as e:
2828
print(f"Warning: failed to process {e}")

benchmark/evaluate_rnn_models.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,7 @@
3434
total_ops, total_params = profile(model, (inputs[0],), verbose=False)
3535
else:
3636
total_ops, total_params = profile(model, (inputs,), verbose=False)
37-
print(
38-
"{} | {:.2f} | {:.2f}".format(
39-
name,
40-
total_params / 1e6,
41-
total_ops / 1e9,
42-
)
43-
)
37+
print(f"{name} | {total_params / 1e6:.2f} | {total_ops / 1e9:.2f}")
4438

4539
# validate batch_first support
4640
inputs = torch.randn(100, 32, input_size)

thop/profile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ def add_hooks(m):
6969

7070
if hasattr(m, "total_ops") or hasattr(m, "total_params"):
7171
logging.warning(
72-
"Either .total_ops or .total_params is already defined in %s. "
73-
"Be careful, it might change your code's behavior." % str(m)
72+
f"Either .total_ops or .total_params is already defined in {str(m)}. "
73+
"Be careful, it might change your code's behavior."
7474
)
7575

7676
m.register_buffer("total_ops", torch.zeros(1, dtype=default_dtype))

thop/vision/basic_hooks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def count_convNd_ver2(m: _ConvNd, x, y: torch.Tensor):
4444
x = x[0]
4545

4646
# N x H x W (exclude Cout)
47-
output_size = torch.zeros((y.size()[:1] + y.size()[2:])).numel()
47+
output_size = torch.zeros(y.size()[:1] + y.size()[2:]).numel()
4848
# # Cout x Cin x Kw x Kh
4949
# kernel_ops = m.weight.nelement()
5050
# if m.bias is not None:

0 commit comments

Comments
 (0)