-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 | |||
""" | |||
|
There was a problem hiding this comment.
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:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
imported = torch.jit.load(buffer) | ||
return imported | ||
return torch.jit.load(buffer) |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
in_channels = [int(gw * width_multiple) for gw in grow_widths] | ||
return in_channels | ||
return [int(gw * width_multiple) for gw in grow_widths] |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
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] |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Replace if statement with if expression (
assign-if-exp
)
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 | ||
) |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Replace if statement with if expression (
assign-if-exp
)
image = read_image(str(img_path)) / 255 | ||
|
||
return image | ||
return read_image(str(img_path)) / 255 |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
images = list(image.to(device) for image in images) | ||
images = [image.to(device) for image in images] |
There was a problem hiding this comment.
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:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
)
ret = run_clang_format_diff(args, file) | ||
return ret | ||
return run_clang_format_diff(args, file) |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
version_invocation = [args.clang_format_executable, str("--version")] | ||
version_invocation = [args.clang_format_executable, "--version"] |
There was a problem hiding this comment.
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:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
)
table = tabulate( | ||
return tabulate( |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
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" |
There was a problem hiding this comment.
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:
- Move assignments closer to their usage (
move-assign
)
loader = torch.utils.data.DataLoader( | ||
return torch.utils.data.DataLoader( |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
num_keypoints = keypoints.shape[0] | ||
if num_keypoints: | ||
if num_keypoints := keypoints.shape[0]: |
There was a problem hiding this comment.
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:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Merge dictionary assignment with declaration [×2] (
merge-dict-assign
)
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) |
There was a problem hiding this comment.
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:
- Lift return into if (
lift-return-into-if
)
if isinstance(coco_gt, str) or isinstance(coco_gt, PosixPath): | ||
if isinstance(coco_gt, (str, PosixPath)): |
There was a problem hiding this comment.
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:
- Merge isinstance calls (
merge-isinstance
) - Simplify conditional into switch-like form [×2] (
switch
)
pred_boxes = torch.cat((pred_xy, pred_wh), 1) | ||
|
||
return pred_boxes | ||
return torch.cat((pred_xy, pred_wh), 1) |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
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] |
There was a problem hiding this comment.
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:
- Replace list(), dict() or set() with comprehension (
collection-builtin-to-comprehension
) - Replace unneeded comprehension with generator (
comprehension-to-generator
)
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'." | ||
|
There was a problem hiding this comment.
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:
- Use set when checking membership of a collection of literals (
collection-into-set
)
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 |
There was a problem hiding this comment.
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:
- Convert for loop into call to sum() (
sum-comprehension
) - Replace unused for index with underscore (
for-index-underscore
) - Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace manual loop counter with call to enumerate (
convert-to-enumerate
)
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", | ||
) | ||
|
There was a problem hiding this comment.
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:
- Use set when checking membership of a collection of literals (
collection-into-set
) - Merge consecutive list appends into a single extend [×2] (
merge-list-appends-into-extend
) - Extract guard clause from elif block (
guard
)
This removes the following comments ( why? ):
# nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
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) |
There was a problem hiding this comment.
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:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
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), | ||
) | ||
) | ||
|
There was a problem hiding this comment.
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:
- Merge consecutive list appends into a single extend (
merge-list-appends-into-extend
) - Extract guard clause from elif block (
guard
)
This removes the following comments ( why? ):
# nn.init.kaiming_normal_(m.weight, mode='fan_out', nonlinearity='relu')
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) |
There was a problem hiding this comment.
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:
- Remove unnecessary else after guard condition (
remove-unnecessary-else
)
elif version in ["r3.1", "r4.0"]: | ||
elif version in {"r3.1", "r4.0"}: |
There was a problem hiding this comment.
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:
- Use set when checking membership of a collection of literals (
collection-into-set
)
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 |
There was a problem hiding this comment.
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:
- Move assignments closer to their usage (
move-assign
) - Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace manual loop counter with call to enumerate (
convert-to-enumerate
)
out = self.post_process(x) | ||
return out | ||
return self.post_process(x) |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
out = torch.concat([i, boxes_keep, classes_keep, scores_keep], 1) | ||
return out | ||
return torch.concat([i, boxes_keep, classes_keep, scores_keep], 1) |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
return any([is_relevant_type(tt) for tt in t.elements()]) | ||
return any(is_relevant_type(tt) for tt in t.elements()) |
There was a problem hiding this comment.
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:
- Replace unneeded comprehension with generator (
comprehension-to-generator
)
if "masks" in out_dict.keys(): | ||
if "masks" in out_dict: |
There was a problem hiding this comment.
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:
- Remove unnecessary call to keys() (
remove-dict-keys
)
# Compute the detections | ||
outputs = self.model(inputs) | ||
|
||
return outputs | ||
return self.model(inputs) |
There was a problem hiding this comment.
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:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
This removes the following comments ( why? ):
# Compute the detections
Sourcery Code Quality Report❌ Merging this PR will decrease code quality in the affected files by 0.09%.
Here are some functions in these files that still need a tune-up:
Legend and ExplanationThe emojis denote the absolute quality of the code:
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! |
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:Help us improve this pull request!