-
Notifications
You must be signed in to change notification settings - Fork 1
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 Starbot ⭐ refactored buts101/Detectron #1
base: master
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.
binary = os.path.join(binary_dir, 'test_net' + binary_ext) | ||
assert os.path.exists(binary), 'Binary \'{}\' not found'.format(binary) | ||
binary = os.path.join(binary_dir, f'test_net{binary_ext}') | ||
assert os.path.exists(binary), f"Binary '{binary}' not found" |
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 multi_gpu_generate_rpn_on_dataset
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace call to format with f-string. (
use-fstring-for-formatting
)
logger.info('Wrote RPN proposals to {}'.format(os.path.abspath(rpn_file))) | ||
logger.info(f'Wrote RPN proposals to {os.path.abspath(rpn_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 generate_rpn_on_range
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
core.ScopedName('rpn_rois_fpn' + str(l)) | ||
core.ScopedName(f'rpn_rois_fpn{str(l)}') | ||
for l in range(k_min, k_max + 1) | ||
] | ||
|
||
score_names = [ | ||
core.ScopedName('rpn_roi_probs_fpn' + str(l)) | ||
core.ScopedName(f'rpn_roi_probs_fpn{str(l)}') | ||
for l in range(k_min, k_max + 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 im_proposals
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
im_size_min = np.min(im_shape[0:2]) | ||
im_size_max = np.max(im_shape[0:2]) | ||
|
||
processed_ims = [] | ||
im_size_min = np.min(im_shape[:2]) | ||
im_size_max = np.max(im_shape[:2]) |
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_image_blob
refactored with the following changes:
- Merge append into list declaration (
merge-list-append
) - Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
) - Move assignment closer to its usage within a block (
move-assign-in-block
)
if not cfg.MODEL.FASTER_RCNN: | ||
box_proposals_hf = box_utils.flip_boxes(box_proposals, im_width) | ||
else: | ||
box_proposals_hf = None | ||
box_proposals_hf = ( | ||
None | ||
if cfg.MODEL.FASTER_RCNN | ||
else box_utils.flip_boxes(box_proposals, im_width) | ||
) |
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 im_detect_bbox_hflip
refactored with the following changes:
- Swap if/else branches of if expression to remove negation (
swap-if-expression
) - Replace if statement with if expression (
assign-if-exp
)
ds.classes = {i: name for i, name in enumerate(classes)} | ||
ds.classes = dict(enumerate(classes)) |
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_coco_dataset
refactored with the following changes:
- Replace identity comprehension with call to collection constructor (
identity-comprehension
)
assert name in DATASETS.keys(), \ | ||
'Unknown dataset name: {}'.format(name) | ||
assert os.path.exists(DATASETS[name][IM_DIR]), \ | ||
'Image directory \'{}\' not found'.format(DATASETS[name][IM_DIR]) | ||
assert os.path.exists(DATASETS[name][ANN_FN]), \ | ||
'Annotation file \'{}\' not found'.format(DATASETS[name][ANN_FN]) | ||
logger.debug('Creating: {}'.format(name)) | ||
assert name in DATASETS.keys(), f'Unknown dataset name: {name}' | ||
assert os.path.exists( | ||
DATASETS[name][IM_DIR] | ||
), f"Image directory '{DATASETS[name][IM_DIR]}' not found" | ||
|
||
assert os.path.exists( | ||
DATASETS[name][ANN_FN] | ||
), f"Annotation file '{DATASETS[name][ANN_FN]}' not found" | ||
|
||
logger.debug(f'Creating: {name}') |
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 JsonDataset.__init__
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
logger.info('Loading proposals from: {}'.format(proposal_file)) | ||
logger.info(f'Loading proposals from: {proposal_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 JsonDataset._add_proposals_from_file
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
x = kp[0::3] # 0-indexed x coordinates | ||
x = kp[::3] |
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 JsonDataset._get_gt_keypoints
refactored with the following changes:
- Replace a[0:x] with a[:x] and a[x:len(a)] with a[x:] (
remove-redundant-slice-index
)
This removes the following comments ( why? ):
# 0-indexed x coordinates
output_dir, 'segmentations_' + json_dataset.name + '_results' | ||
output_dir, f'segmentations_{json_dataset.name}_results' | ||
) | ||
|
||
if use_salt: | ||
res_file += '_{}'.format(str(uuid.uuid4())) | ||
res_file += f'_{str(uuid.uuid4())}' |
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_masks
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace call to format with f-string. (
use-fstring-for-formatting
)
'Writing segmentation results json to: {}'.format( | ||
os.path.abspath(res_file))) | ||
f'Writing segmentation results json to: {os.path.abspath(res_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 _write_coco_segms_results_file
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
logger.info('Wrote json eval results to: {}'.format(eval_file)) | ||
logger.info(f'Wrote json eval results to: {eval_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 _do_segmentation_eval
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
res_file = os.path.join( | ||
output_dir, 'bbox_' + json_dataset.name + '_results' | ||
) | ||
res_file = os.path.join(output_dir, f'bbox_{json_dataset.name}_results') | ||
if use_salt: | ||
res_file += '_{}'.format(str(uuid.uuid4())) | ||
res_file += f'_{str(uuid.uuid4())}' |
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_boxes
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace call to format with f-string. (
use-fstring-for-formatting
)
logger.info( | ||
'Writing bbox results json to: {}'.format(os.path.abspath(res_file))) | ||
logger.info(f'Writing bbox results json to: {os.path.abspath(res_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 _write_coco_bbox_results_file
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
logger.info('Wrote json eval results to: {}'.format(eval_file)) | ||
logger.info(f'Wrote json eval results to: {eval_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 _do_detection_eval
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
assert dataset in results, 'Dataset {} not in results'.format(dataset) | ||
assert task in results[dataset], 'Task {} not in results'.format(task) | ||
assert metric in results[dataset][task], \ | ||
'Metric {} not in results'.format(metric) | ||
assert dataset in results, f'Dataset {dataset} not in results' | ||
assert task in results[dataset], f'Task {task} not in results' | ||
assert metric in results[dataset][task], f'Metric {metric} not in results' |
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_expected_results
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
salt = '_{}'.format(str(uuid.uuid4())) if use_salt else '' | ||
salt = f'_{str(uuid.uuid4())}' if use_salt else '' |
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_boxes
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
assert os.path.exists(image_set_path), \ | ||
'Image set path does not exist: {}'.format(image_set_path) | ||
assert os.path.exists( | ||
image_set_path | ||
), f'Image set path does not exist: {image_set_path}' | ||
|
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 _write_voc_results_files
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
filename = 'comp4' + salt + '_det_' + image_set + '_{:s}.txt' | ||
return os.path.join(devkit_path, 'results', 'VOC' + year, 'Main', filename) | ||
filename = f'comp4{salt}_det_{image_set}' + '_{:s}.txt' | ||
return os.path.join(devkit_path, 'results', f'VOC{year}', 'Main', filename) |
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_voc_results_file_template
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
use_07_metric = True if int(year) < 2010 else False | ||
use_07_metric = int(year) < 2010 | ||
logger.info('VOC07 metric? ' + ('Yes' if use_07_metric else 'No')) | ||
if not os.path.isdir(output_dir): | ||
os.mkdir(output_dir) | ||
for _, cls in enumerate(json_dataset.classes): | ||
for cls in json_dataset.classes: |
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 _do_python_eval
refactored with the following changes:
- Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
) - Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary calls to
enumerate
when the index is not used (remove-unused-enumerate
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
cmd = 'cd {} && '.format(path) | ||
cmd += '{:s} -nodisplay -nodesktop '.format(cfg.MATLAB) | ||
cmd = f'cd {path} && ' + '{:s} -nodisplay -nodesktop '.format(cfg.MATLAB) | ||
cmd += '-r "dbstop if error; ' | ||
cmd += 'voc_eval(\'{:s}\',\'{:s}\',\'{:s}\',\'{:s}\'); quit;"' \ | ||
.format(info['devkit_path'], 'comp4' + salt, info['image_set'], | ||
output_dir) | ||
cmd += 'voc_eval(\'{:s}\',\'{:s}\',\'{:s}\',\'{:s}\'); quit;"'.format( | ||
info['devkit_path'], f'comp4{salt}', info['image_set'], output_dir | ||
) | ||
|
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 _do_matlab_eval
refactored with the following changes:
- Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign
) - Replace call to format with f-string. (
use-fstring-for-formatting
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
assert os.path.exists(devkit_path), \ | ||
'Devkit directory {} not found'.format(devkit_path) | ||
anno_path = os.path.join( | ||
devkit_path, 'VOC' + year, 'Annotations', '{:s}.xml') | ||
assert os.path.exists(devkit_path), f'Devkit directory {devkit_path} not found' | ||
anno_path = os.path.join(devkit_path, f'VOC{year}', 'Annotations', '{:s}.xml') | ||
image_set_path = os.path.join( | ||
devkit_path, 'VOC' + year, 'ImageSets', 'Main', image_set + '.txt') | ||
devkit_path, f'VOC{year}', 'ImageSets', 'Main', f'{image_set}.txt' | ||
) | ||
|
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 voc_info
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
) - Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
obj_struct = {} | ||
obj_struct['name'] = obj.find('name').text | ||
obj_struct = {'name': obj.find('name').text} |
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 parse_rec
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
)
if np.sum(rec >= t) == 0: | ||
p = 0 | ||
else: | ||
p = np.max(prec[rec >= t]) | ||
p = 0 if np.sum(rec >= t) == 0 else np.max(prec[rec >= t]) |
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 voc_ap
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
)
cachefile = os.path.join(cachedir, imageset + '_annots.pkl') | ||
cachefile = os.path.join(cachedir, f'{imageset}_annots.pkl') |
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 voc_eval
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Merge duplicate blocks in conditional (
merge-duplicate-blocks
) - Remove redundant conditional (
remove-redundant-if
)
'conv_rpn_fpn' + slvl, | ||
f'conv_rpn_fpn{slvl}', | ||
dim_in, | ||
dim_out, | ||
kernel=3, | ||
pad=1, | ||
stride=1, | ||
weight_init=gauss_fill(0.01), | ||
bias_init=const_fill(0.0) | ||
bias_init=const_fill(0.0), | ||
) | ||
|
||
model.Relu(conv_rpn_fpn, conv_rpn_fpn) | ||
# Proposal classification scores | ||
rpn_cls_logits_fpn = model.Conv( | ||
conv_rpn_fpn, | ||
'rpn_cls_logits_fpn' + slvl, | ||
f'rpn_cls_logits_fpn{slvl}', | ||
dim_in, | ||
num_anchors, | ||
kernel=1, | ||
pad=0, | ||
stride=1, | ||
weight_init=gauss_fill(0.01), | ||
bias_init=const_fill(0.0) | ||
bias_init=const_fill(0.0), | ||
) | ||
|
||
# Proposal bbox regression deltas | ||
rpn_bbox_pred_fpn = model.Conv( | ||
conv_rpn_fpn, | ||
'rpn_bbox_pred_fpn' + slvl, | ||
f'rpn_bbox_pred_fpn{slvl}', | ||
dim_in, | ||
4 * num_anchors, | ||
kernel=1, | ||
pad=0, | ||
stride=1, | ||
weight_init=gauss_fill(0.01), | ||
bias_init=const_fill(0.0) | ||
bias_init=const_fill(0.0), | ||
) | ||
|
||
else: | ||
# Share weights and biases | ||
sk_min = str(k_min) | ||
# RPN hidden representation | ||
conv_rpn_fpn = model.ConvShared( | ||
bl_in, | ||
'conv_rpn_fpn' + slvl, | ||
f'conv_rpn_fpn{slvl}', | ||
dim_in, | ||
dim_out, | ||
kernel=3, | ||
pad=1, | ||
stride=1, | ||
weight='conv_rpn_fpn' + sk_min + '_w', | ||
bias='conv_rpn_fpn' + sk_min + '_b' | ||
weight=f'conv_rpn_fpn{sk_min}_w', | ||
bias=f'conv_rpn_fpn{sk_min}_b', | ||
) | ||
|
||
model.Relu(conv_rpn_fpn, conv_rpn_fpn) | ||
# Proposal classification scores | ||
rpn_cls_logits_fpn = model.ConvShared( | ||
conv_rpn_fpn, | ||
'rpn_cls_logits_fpn' + slvl, | ||
f'rpn_cls_logits_fpn{slvl}', | ||
dim_in, | ||
num_anchors, | ||
kernel=1, | ||
pad=0, | ||
stride=1, | ||
weight='rpn_cls_logits_fpn' + sk_min + '_w', | ||
bias='rpn_cls_logits_fpn' + sk_min + '_b' | ||
weight=f'rpn_cls_logits_fpn{sk_min}_w', | ||
bias=f'rpn_cls_logits_fpn{sk_min}_b', | ||
) | ||
|
||
# Proposal bbox regression deltas | ||
rpn_bbox_pred_fpn = model.ConvShared( | ||
conv_rpn_fpn, | ||
'rpn_bbox_pred_fpn' + slvl, | ||
f'rpn_bbox_pred_fpn{slvl}', | ||
dim_in, | ||
4 * num_anchors, | ||
kernel=1, | ||
pad=0, | ||
stride=1, | ||
weight='rpn_bbox_pred_fpn' + sk_min + '_w', | ||
bias='rpn_bbox_pred_fpn' + sk_min + '_b' | ||
weight=f'rpn_bbox_pred_fpn{sk_min}_w', | ||
bias=f'rpn_bbox_pred_fpn{sk_min}_b', | ||
) | ||
|
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 add_fpn_rpn_outputs
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
blobs[blob_prefix + '_fpn' + str(lvl)] = rois[idx_lvl, :] | ||
blobs[f'{blob_prefix}_fpn{str(lvl)}'] = rois[idx_lvl, :] | ||
rois_idx_order = np.concatenate((rois_idx_order, idx_lvl)) | ||
rois_stacked = np.vstack( | ||
[rois_stacked, blobs[blob_prefix + '_fpn' + str(lvl)]] | ||
) | ||
rois_stacked = np.vstack([rois_stacked, blobs[f'{blob_prefix}_fpn{str(lvl)}']]) | ||
rois_idx_restore = np.argsort(rois_idx_order).astype(np.int32, copy=False) | ||
blobs[blob_prefix + '_idx_restore_int32'] = rois_idx_restore | ||
blobs[f'{blob_prefix}_idx_restore_int32'] = rois_idx_restore |
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 add_multilevel_roi_blobs
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
'{}_{}'.format(prefix, i), | ||
f'{prefix}_{i}', | ||
blob_in, | ||
dim_in, | ||
dim_out, | ||
dim_inner, | ||
dilation, | ||
stride_init, | ||
# Not using inplace for the last block; | ||
# it may be fetched externally or used by FPN | ||
inplace_sum=i < n - 1 | ||
inplace_sum=i < n - 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 add_stage
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
This removes the following comments ( why? ):
# Not using inplace for the last block;
# it may be fetched externally or used by FPN
s = model.net.Sum([tr, sc], prefix + '_sum') | ||
s = model.net.Sum([tr, sc], f'{prefix}_sum') |
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 add_residual_block
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
prefix + '_branch1', | ||
f'{prefix}_branch1', | ||
dim_in, | ||
dim_out, | ||
kernel=1, | ||
stride=stride, | ||
no_bias=1 | ||
no_bias=1, | ||
) | ||
return model.AffineChannel(c, prefix + '_branch1_bn', dim=dim_out) | ||
|
||
return model.AffineChannel(c, f'{prefix}_branch1_bn', dim=dim_out) |
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 add_shortcut
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
)
Thanks for starring sourcery-ai/sourcery ✨ 🌟 ✨
Here's your pull request refactoring your most popular Python repo.
If you want Sourcery to refactor all your Python repos and incoming pull requests install our bot.
Review changes via command line
To manually merge these changes, make sure you're on the
master
branch, then run: