Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored main branch #1

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Jul 1, 2022

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from xinetzone July 1, 2022 03:19
Copy link
Author

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to GitHub API limits, only the first 60 comments can be shown.

@@ -7,6 +7,7 @@
Adapted from TorchVision, see:
https://github.com/pytorch/vision/blob/master/setup.py
"""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 30-30 refactored with the following changes:

imported = torch.jit.load(buffer)
return imported
return torch.jit.load(buffer)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _check_jit_scriptable.assert_export_import_module.get_export_import_copy refactored with the following changes:

Comment on lines -101 to +100
in_channels = [int(gw * width_multiple) for gw in grow_widths]
return in_channels
return [int(gw * width_multiple) for gw in grow_widths]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestModel._get_in_channels refactored with the following changes:

Comment on lines -106 to +104
if use_p6:
strides = [8, 16, 32, 64]
else:
strides = [8, 16, 32]
return strides
return [8, 16, 32, 64] if use_p6 else [8, 16, 32]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestModel._get_strides refactored with the following changes:

Comment on lines -114 to +121
if use_p6:
anchor_grids = [
return (
[
[19, 27, 44, 40, 38, 94],
[96, 68, 86, 152, 180, 137],
[140, 301, 303, 264, 238, 542],
[436, 615, 739, 380, 925, 792],
]
else:
anchor_grids = [
if use_p6
else [
[10, 13, 16, 30, 33, 23],
[30, 61, 62, 45, 59, 119],
[116, 90, 156, 198, 373, 326],
]
return anchor_grids
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestModel._get_anchor_grids refactored with the following changes:

image = read_image(str(img_path)) / 255

return image
return read_image(str(img_path)) / 255
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function TestONNXExporter.get_image refactored with the following changes:

images = list(image.to(device) for image in images)
images = [image.to(device) for image in images]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function evaluate refactored with the following changes:

ret = run_clang_format_diff(args, file)
return ret
return run_clang_format_diff(args, file)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function run_clang_format_diff_wrapper refactored with the following changes:

Comment on lines -296 to +295
version_invocation = [args.clang_format_executable, str("--version")]
version_invocation = [args.clang_format_executable, "--version"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function main refactored with the following changes:

table = tabulate(
return tabulate(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function create_small_table refactored with the following changes:

coco128_url = "https://github.com/zhiqwang/yolov5-rt-stack/releases/download/v0.3.0/coco128.zip"
if not zip_path.is_file():
coco128_url = "https://github.com/zhiqwang/yolov5-rt-stack/releases/download/v0.3.0/coco128.zip"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function prepare_coco128 refactored with the following changes:

Comment on lines -109 to +108
loader = torch.utils.data.DataLoader(
return torch.utils.data.DataLoader(
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_dataloader refactored with the following changes:

num_keypoints = keypoints.shape[0]
if num_keypoints:
if num_keypoints := keypoints.shape[0]:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ConvertCocoPolysToMask.__call__ refactored with the following changes:

Comment on lines -112 to +111
masks = torch.stack(masks, dim=0)
return torch.stack(masks, dim=0)
else:
masks = torch.zeros((0, height, width), dtype=torch.uint8)
return masks
return torch.zeros((0, height, width), dtype=torch.uint8)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function convert_coco_poly_to_mask refactored with the following changes:

if isinstance(coco_gt, str) or isinstance(coco_gt, PosixPath):
if isinstance(coco_gt, (str, PosixPath)):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function COCOEvaluator.__init__ refactored with the following changes:

pred_boxes = torch.cat((pred_xy, pred_wh), 1)

return pred_boxes
return torch.cat((pred_xy, pred_wh), 1)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function encode_single refactored with the following changes:

grid_sizes = list([feature_map.shape[-2:] for feature_map in feature_maps])
grid_sizes = [feature_map.shape[-2:] for feature_map in feature_maps]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function AnchorGenerator.forward refactored with the following changes:

Comment on lines -95 to +100
assert version in [
assert version in {
"r3.1",
"r4.0",
"r6.0",
], "Currently only supports version 'r3.1', 'r4.0' and 'r6.0'."
}, "Currently only supports version 'r3.1', 'r4.0' and 'r6.0'."

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function darknet_pan_backbone refactored with the following changes:

Comment on lines -55 to -65
num_blocks = 0
for m in self.head:
num_blocks += 1
num_blocks = sum(1 for _ in self.head)
if idx < 0:
idx += num_blocks
i = 0
out = features
for module in self.head:
for i, module in enumerate(self.head):
if i == idx:
out = module(features)
i += 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function YOLOHead.get_result_from_head refactored with the following changes:

Comment on lines -65 to 68
assert version in ["r3.1", "r4.0"], (
assert version in {"r3.1", "r4.0"}, (
"Currently the module version used in DarkNetV4 is r3.1 or r4.0",
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DarkNetV4.__init__ refactored with the following changes:

This removes the following comments ( why? ):

# nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')

Comment on lines -149 to +160
else:
state_dict = load_state_dict_from_url(model_url, progress=progress)
model.load_state_dict(state_dict)
state_dict = load_state_dict_from_url(model_url, progress=progress)
model.load_state_dict(state_dict)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _darknet_v4_conf refactored with the following changes:

Comment on lines -88 to +94
layers.append(Conv(input_channel, out_channel, k=3, s=2, version=version))
layers.append(block(out_channel, out_channel, n=depth_gain))
layers.extend(
(
Conv(input_channel, out_channel, k=3, s=2, version=version),
block(out_channel, out_channel, n=depth_gain),
)
)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DarkNetV6.__init__ refactored with the following changes:

This removes the following comments ( why? ):

# nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')

Comment on lines -140 to +146
else:
state_dict = load_state_dict_from_url(model_url, progress=progress)
model.load_state_dict(state_dict)
state_dict = load_state_dict_from_url(model_url, progress=progress)
model.load_state_dict(state_dict)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function _darknet_v6_conf refactored with the following changes:

elif version in ["r3.1", "r4.0"]:
elif version in {"r3.1", "r4.0"}:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PathAggregationNetwork.__init__ refactored with the following changes:

Comment on lines -172 to -180
num_blocks = len(self.inner_blocks)
if idx < 0:
num_blocks = len(self.inner_blocks)
idx += num_blocks
i = 0
out = x
for module in self.inner_blocks:
for i, module in enumerate(self.inner_blocks):
if i == idx:
out = module(x)
i += 1
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PathAggregationNetwork.get_result_from_inner_blocks refactored with the following changes:

out = self.post_process(x)
return out
return self.post_process(x)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FakeYOLO.forward refactored with the following changes:

Comment on lines -86 to +85
out = torch.concat([i, boxes_keep, classes_keep, scores_keep], 1)
return out
return torch.concat([i, boxes_keep, classes_keep, scores_keep], 1)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function FakePostProcess.forward refactored with the following changes:

return any([is_relevant_type(tt) for tt in t.elements()])
return any(is_relevant_type(tt) for tt in t.elements())
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function is_relevant_type refactored with the following changes:

if "masks" in out_dict.keys():
if "masks" in out_dict:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function dict_to_tuple refactored with the following changes:

# Compute the detections
outputs = self.model(inputs)

return outputs
return self.model(inputs)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function YOLOTRTInference.forward refactored with the following changes:

This removes the following comments ( why? ):

# Compute the detections

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Jul 1, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.09%.

Quality metrics Before After Change
Complexity 7.24 ⭐ 7.16 ⭐ -0.08 👍
Method Length 74.62 🙂 74.16 🙂 -0.46 👍
Working memory 11.45 😞 11.51 😞 0.06 👎
Quality 59.92% 🙂 59.83% 🙂 -0.09% 👎
Other metrics Before After Change
Lines 10766 10671 -95
Changed files Quality Before Quality After Quality Change
setup.py 77.92% ⭐ 77.88% ⭐ -0.04% 👎
test/test_models.py 70.93% 🙂 70.02% 🙂 -0.91% 👎
test/test_models_anchor_utils.py 76.07% ⭐ 75.25% ⭐ -0.82% 👎
test/test_runtime_ort.py 72.48% 🙂 72.52% 🙂 0.04% 👍
tools/eval_metric.py 65.13% 🙂 65.32% 🙂 0.19% 👍
tools/run_clang_format.py 52.73% 🙂 52.55% 🙂 -0.18% 👎
yolort/data/_helper.py 75.84% ⭐ 75.98% ⭐ 0.14% 👍
yolort/data/coco.py 50.91% 🙂 51.62% 🙂 0.71% 👍
yolort/data/coco_eval.py 61.63% 🙂 61.76% 🙂 0.13% 👍
yolort/data/data_module.py 72.00% 🙂 71.83% 🙂 -0.17% 👎
yolort/data/distributed.py 65.79% 🙂 65.33% 🙂 -0.46% 👎
yolort/data/transforms.py 53.12% 🙂 53.48% 🙂 0.36% 👍
yolort/models/_checkpoint.py 59.79% 🙂 60.69% 🙂 0.90% 👍
yolort/models/_utils.py 67.08% 🙂 66.81% 🙂 -0.27% 👎
yolort/models/anchor_utils.py 72.60% 🙂 72.66% 🙂 0.06% 👍
yolort/models/backbone_utils.py 74.64% 🙂 74.64% 🙂 0.00%
yolort/models/box_head.py 50.09% 🙂 49.49% 😞 -0.60% 👎
yolort/models/darknetv4.py 63.36% 🙂 63.59% 🙂 0.23% 👍
yolort/models/darknetv6.py 60.89% 🙂 60.61% 🙂 -0.28% 👎
yolort/models/path_aggregation_network.py 58.12% 🙂 57.20% 🙂 -0.92% 👎
yolort/models/transform.py 61.01% 🙂 61.88% 🙂 0.87% 👍
yolort/models/yolo.py 69.19% 🙂 69.24% 🙂 0.05% 👍
yolort/models/yolov5.py 59.45% 🙂 60.66% 🙂 1.21% 👍
yolort/relay/head_helper.py 71.50% 🙂 71.63% 🙂 0.13% 👍
yolort/relay/ir_visualizer.py 36.79% 😞 36.79% 😞 0.00%
yolort/relay/trace_wrapper.py 92.31% ⭐ 93.01% ⭐ 0.70% 👍
yolort/relay/trt_inference.py 73.03% 🙂 72.15% 🙂 -0.88% 👎
yolort/runtime/ort_helper.py 75.56% ⭐ 75.05% ⭐ -0.51% 👎
yolort/runtime/y_onnxruntime.py 80.99% ⭐ 82.47% ⭐ 1.48% 👍
yolort/runtime/y_tensorrt.py 69.22% 🙂 69.24% 🙂 0.02% 👍
yolort/trainer/lightning_task.py 84.11% ⭐ 84.15% ⭐ 0.04% 👍
yolort/utils/annotations_converter.py 69.21% 🙂 69.05% 🙂 -0.16% 👎
yolort/utils/image_utils.py 62.57% 🙂 62.66% 🙂 0.09% 👍
yolort/utils/logger.py 74.24% 🙂 74.18% 🙂 -0.06% 👎
yolort/utils/visualizer.py 68.25% 🙂 67.36% 🙂 -0.89% 👎
yolort/v5/helper.py 72.56% 🙂 73.66% 🙂 1.10% 👍
yolort/v5/models/common.py 64.60% 🙂 64.25% 🙂 -0.35% 👎
yolort/v5/models/experimental.py 71.30% 🙂 70.70% 🙂 -0.60% 👎
yolort/v5/models/yolo.py 50.33% 🙂 50.42% 🙂 0.09% 👍
yolort/v5/utils/augmentations.py 43.73% 😞 43.88% 😞 0.15% 👍
yolort/v5/utils/autoanchor.py 40.22% 😞 40.27% 😞 0.05% 👍
yolort/v5/utils/callbacks.py 88.43% ⭐ 86.98% ⭐ -1.45% 👎
yolort/v5/utils/datasets.py 58.38% 🙂 58.73% 🙂 0.35% 👍
yolort/v5/utils/general.py 63.63% 🙂 63.54% 🙂 -0.09% 👎
yolort/v5/utils/loss.py 50.57% 🙂 50.65% 🙂 0.08% 👍
yolort/v5/utils/metrics.py 46.49% 😞 47.83% 😞 1.34% 👍
yolort/v5/utils/plots.py 47.32% 😞 47.18% 😞 -0.14% 👎
yolort/v5/utils/torch_utils.py 55.78% 🙂 55.99% 🙂 0.21% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
yolort/relay/ir_visualizer.py TorchScriptVisualizer.make_graph 56 ⛔ 606 ⛔ 28 ⛔ 3.61% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
yolort/v5/models/common.py Detections.display 43 ⛔ 315 ⛔ 24 ⛔ 9.95% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
yolort/v5/models/yolo.py parse_model 37 ⛔ 468 ⛔ 20 ⛔ 11.33% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
yolort/v5/utils/plots.py plot_images 40 ⛔ 478 ⛔ 18 ⛔ 11.70% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
yolort/v5/utils/torch_utils.py profile 45 ⛔ 379 ⛔ 16 ⛔ 13.23% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants