-
Notifications
You must be signed in to change notification settings - Fork 9
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 huyhoang17/DB_text_minimal #26
base: master
Are you sure you want to change the base?
Conversation
augment_seq = iaa.Sequential([ | ||
iaa.Fliplr(0.5), | ||
iaa.Affine(rotate=(-10, 10)), | ||
iaa.Resize((0.5, 3.0)) | ||
]) | ||
return augment_seq | ||
return iaa.Sequential( | ||
[iaa.Fliplr(0.5), iaa.Affine(rotate=(-10, 10)), iaa.Resize((0.5, 3.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 BaseDatasetIter._get_default_augment
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
gt_fn = "gt_img{}.txt".format(img_id) | ||
gt_fn = f"gt_img{img_id}.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 TotalTextDatasetIter.load_metadata
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
@@ -195,7 +192,6 @@ def load_all_anns(self, gt_paths): | |||
lines = [] | |||
reader = open(gt, 'r').readlines() | |||
for line in reader: | |||
item = {} |
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 TotalTextDatasetIter.load_all_anns
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
) - Move assignment closer to its usage within a block (
move-assign-in-block
)
gt_fn = "{}.txt".format(img_id) | ||
gt_fn = f"{img_id}.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 CTW1500DatasetIter.load_metadata
refactored with the following changes:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
@@ -237,7 +232,6 @@ def load_all_anns(self, gt_fps): | |||
lines = [] | |||
with open(gt_fp, 'r') as f: | |||
for line in f: | |||
item = {} |
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 CTW1500DatasetIter.load_all_anns
refactored with the following changes:
- Merge dictionary assignment with declaration (
merge-dict-assign
) - Move assignment closer to its usage within a block (
move-assign-in-block
)
methodMetrics = { | ||
return { | ||
'precision': methodPrecision, | ||
'recall': methodRecall, | ||
'hmean': methodHmean | ||
'hmean': methodHmean, | ||
} | ||
|
||
return methodMetrics |
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 DetectionDetEvalEvaluator.combine_results
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
args = parser.parse_args() | ||
return args | ||
return parser.parse_args() |
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 load_args
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
results = [] | ||
for gt, pred in zip(gts, preds): | ||
results.append(evaluator.evaluate_image(gt, pred)) | ||
results = [evaluator.evaluate_image(gt, pred) for gt, pred in zip(gts, preds)] |
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 426-428
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
iou = get_intersection(pD, pG) / get_union(pD, pG) | ||
return iou | ||
return get_intersection(pD, pG) / get_union(pD, pG) |
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 DetectionIoUEvaluator.evaluate_image.get_intersection_over_union
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
|
||
def get_intersection(pD, pG): | ||
pD = Polygon(pD).buffer(0) | ||
pG = Polygon(pG).buffer(0) | ||
return pD.intersection(pG).area | ||
|
||
def compute_ap(confList, matchList, numGtCare): | ||
correct = 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 DetectionIoUEvaluator.evaluate_image.compute_ap
refactored with the following changes:
- Move assignments closer to their usage (
move-assign
)
methodMetrics = { | ||
return { | ||
'precision': methodPrecision, | ||
'recall': methodRecall, | ||
'hmean': methodHmean | ||
'hmean': methodHmean, | ||
} | ||
|
||
return methodMetrics |
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 DetectionIoUEvaluator.combine_results
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
args = parser.parse_args() | ||
return args | ||
return parser.parse_args() |
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 load_args
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
results = [] | ||
# for each images | ||
for gt, pred in zip(gts, preds): | ||
results.append(evaluator.evaluate_image(gt, pred)) | ||
results = [evaluator.evaluate_image(gt, pred) for gt, pred in zip(gts, preds)] |
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 281-284
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
)
This removes the following comments ( why? ):
# for each images
balance_loss = (positive_loss.sum() + negative_loss.sum()) / ( | ||
no_positive + no_negative + self.eps) | ||
return balance_loss | ||
return (positive_loss.sum() + negative_loss.sum()) / ( | ||
no_positive + no_negative + self.eps | ||
) |
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 OHEMBalanceCrossEntropyLoss.forward
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
loss = (torch.abs(pred - gt) * mask).sum() / \ | ||
(mask.sum() + self.eps) | ||
else: | ||
l1_loss_fn = torch.nn.L1Loss(reduction=self.reduction) | ||
loss = l1_loss_fn(pred, gt) | ||
return loss | ||
return (torch.abs(pred - gt) * mask).sum() / (mask.sum() + self.eps) | ||
|
||
l1_loss_fn = torch.nn.L1Loss(reduction=self.reduction) | ||
return l1_loss_fn(pred, gt) |
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 L1Loss.forward
refactored with the following changes:
- Lift return into if (
lift-return-into-if
) - Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
print(">>> Devide: {}".format(opt.device)) | ||
print(f">>> Devide: {opt.device}") |
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:
- Replace call to format with f-string. (
use-fstring-for-formatting
) - Move assignments closer to their usage (
move-assign
)
opt = parser.parse_args() | ||
return opt | ||
return parser.parse_args() |
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 load_args
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
args = parser.parse_args() | ||
return args | ||
return parser.parse_args() |
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 load_args
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
result = {"pred": pred, "score": float(confidence_score)} | ||
return result | ||
return {"pred": pred, "score": float(confidence_score)} |
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 predict
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
print(">>> Detect: {}'s".format(end)) | ||
print(f">>> Detect: {end}'s") |
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:
- Replace call to format with f-string. (
use-fstring-for-formatting
) - Remove unnecessary calls to
enumerate
when the index is not used (remove-unused-enumerate
)
This removes the following comments ( why? ):
# noqa
hist = np.bincount(n_class * label_true[mask].astype(int) + | ||
label_pred[mask], | ||
minlength=n_class**2).reshape(n_class, n_class) | ||
|
||
return hist | ||
return np.bincount( | ||
n_class * label_true[mask].astype(int) + label_pred[mask], | ||
minlength=n_class**2, | ||
).reshape(n_class, n_class) |
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 RunningScore._fast_hist
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
@@ -29,7 +28,6 @@ def update(self, label_trues, label_preds): | |||
lt.flatten(), lp.flatten(), self.n_classes) | |||
except Exception as e: | |||
print(e) | |||
pass |
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 RunningScore.update
refactored with the following changes:
- Remove redundant pass statement (
remove-redundant-pass
)
@@ -116,7 +114,6 @@ def measure(self, batch, output, is_output_polygon=False, box_thresh=0.6): | |||
filename: the original filenames of images. | |||
output: (polygons, ...) | |||
''' | |||
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 QuadMetric.measure
refactored with the following changes:
- Merge append into list declaration (
merge-list-append
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Move assignment closer to its usage within a block (
move-assign-in-block
) - Convert for loop into list comprehension (
list-comprehension
)
This removes the following comments ( why? ):
# for 1 image
args = parser.parse_args() | ||
return args | ||
return parser.parse_args() |
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 load_args
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
url = "http://{}:{}/{}/{}".format(args.host, args.port, args.mode, | ||
args.model_name) | ||
url = f"http://{args.host}:{args.port}/{args.mode}/{args.model_name}" | ||
image_path = args.image_path | ||
with open(image_path, "rb") as f: | ||
data = f.read() | ||
|
||
start = time.time() | ||
resp = requests.post(url, data=data).text | ||
print("REST took: {}'s".format(time.time() - start)) | ||
print(f"REST took: {time.time() - start}'s") |
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:
- Replace call to format with f-string. (
use-fstring-for-formatting
)
layers = [] | ||
layers.append(block(self.inplanes, planes, stride, downsample, | ||
dcn=dcn)) | ||
layers = [block(self.inplanes, planes, stride, downsample, dcn=dcn)] | ||
self.inplanes = planes * block.expansion | ||
for i in range(1, blocks): | ||
layers.append(block(self.inplanes, planes, dcn=dcn)) | ||
|
||
layers.extend(block(self.inplanes, planes, dcn=dcn) for _ in range(1, blocks)) |
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 ResNet._make_layer
refactored with the following changes:
- Replace a for append loop with list extend (
for-append-to-extend
) - Merge append into list declaration (
merge-list-append
) - Replace unused for index with underscore (
for-index-underscore
)
for i in range(fpem_repeat): | ||
for _ in range(fpem_repeat): |
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 FPEM_FFM.__init__
refactored with the following changes:
- Replace unused for index with underscore (
for-index-underscore
)
Fy = torch.cat([c2_ffm, c3, c4, c5], dim=1) | ||
return Fy | ||
return torch.cat([c2_ffm, c3, c4, c5], dim=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 FPEM_FFM.forward
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
)
y = torch.cat((shrink_maps, threshold_maps, binary_maps), dim=1) | ||
return torch.cat((shrink_maps, threshold_maps, binary_maps), dim=1) | ||
else: | ||
y = torch.cat((shrink_maps, threshold_maps), dim=1) | ||
return y | ||
return torch.cat((shrink_maps, threshold_maps), dim=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 DBHead.forward
refactored with the following changes:
- Lift return into if (
lift-return-into-if
)
if smooth: | ||
inter_out_channels = out_channels | ||
if out_channels == 1: | ||
inter_out_channels = in_channels | ||
module_list = [ | ||
nn.Upsample(scale_factor=2, mode='nearest'), | ||
nn.Conv2d(in_channels, inter_out_channels, 3, 1, 1, bias=bias) | ||
] | ||
if out_channels == 1: | ||
module_list.append( | ||
nn.Conv2d(in_channels, | ||
out_channels, | ||
kernel_size=1, | ||
stride=1, | ||
padding=1, | ||
bias=True)) | ||
return nn.Sequential(module_list) | ||
else: | ||
if not smooth: | ||
return nn.ConvTranspose2d(in_channels, out_channels, 2, 2) | ||
inter_out_channels = out_channels | ||
if out_channels == 1: | ||
inter_out_channels = in_channels | ||
module_list = [ | ||
nn.Upsample(scale_factor=2, mode='nearest'), | ||
nn.Conv2d(in_channels, inter_out_channels, 3, 1, 1, bias=bias) | ||
] | ||
if out_channels == 1: | ||
module_list.append( | ||
nn.Conv2d(in_channels, | ||
out_channels, | ||
kernel_size=1, | ||
stride=1, | ||
padding=1, | ||
bias=True)) | ||
return nn.Sequential(module_list) |
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 DBHead._init_upsample
refactored with the following changes:
- Swap if/else branches (
swap-if-else-branches
) - Remove unnecessary else after guard condition (
remove-unnecessary-else
)
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: