Sourcery Starbot ⭐ refactored YuhaoCheng/PyAnomaly#13
Sourcery Starbot ⭐ refactored YuhaoCheng/PyAnomaly#13SourceryAI wants to merge 1 commit intoYuhaoCheng:masterfrom
Conversation
SourceryAI
left a comment
There was a problem hiding this comment.
Due to GitHub API limits, only the first 60 comments can be shown.
| result_image = None | ||
|
|
||
| return result_image | ||
| return None |
There was a problem hiding this comment.
Function make_result refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| dy = list() | ||
| dy = [] | ||
| for i in range(video_length): | ||
| temp_dx, temp_dy = image_gradient(x[:,i,:,:,:]) | ||
| # dx.append(temp_dx.unsqueeze_(1)) | ||
| dx.append(temp_dx) | ||
| dy.append(temp_dy) | ||
|
|
There was a problem hiding this comment.
Function frame_gradient refactored with the following changes:
- Replace list() with [] (
list-literal)
| def vis_optical_flow(batch_optical, output_format, output_size, normalize): | ||
| temp = batch_optical.detach().cpu().permute(0,2,3,1).numpy() | ||
| temp_list = list() | ||
| temp_list = [] |
There was a problem hiding this comment.
Function vis_optical_flow refactored with the following changes:
- Replace list() with [] (
list-literal)
| """ | ||
| """ | ||
| Use the detecron2 | ||
| """ | ||
| image_list = list() | ||
| batch_size = batch_image.size(0) | ||
| images = torch.chunk(batch_image, batch_size, dim=0) | ||
| for image in images: | ||
| image_list.append({"image":image.squeeze_(0).mul(255).byte()[[2,0,1],:,:]}) | ||
| outputs = det_model(image_list) | ||
|
|
||
| bboxs = [] | ||
| frame_objects = OrderedDict() | ||
| max_objects = 0 | ||
| min_objects = 1000 | ||
| for frame_id, out in enumerate(outputs): | ||
| temp = out['instances'].pred_boxes.tensor.detach() | ||
| temp.requires_grad = False | ||
| frame_objects[frame_id] = temp.size(0) | ||
| if frame_objects[frame_id] > max_objects: | ||
| max_objects = frame_objects[frame_id] | ||
| if frame_objects[frame_id] < min_objects: | ||
| min_objects = frame_objects[frame_id] | ||
| bboxs.append(temp) | ||
|
|
||
| return bboxs | ||
| batch_size = batch_image.size(0) | ||
| images = torch.chunk(batch_image, batch_size, dim=0) | ||
| image_list = [ | ||
| {"image": image.squeeze_(0).mul(255).byte()[[2, 0, 1], :, :]} | ||
| for image in images | ||
| ] | ||
|
|
||
| outputs = det_model(image_list) | ||
|
|
||
| bboxs = [] | ||
| frame_objects = OrderedDict() | ||
| max_objects = 0 | ||
| min_objects = 1000 | ||
| for frame_id, out in enumerate(outputs): | ||
| temp = out['instances'].pred_boxes.tensor.detach() | ||
| temp.requires_grad = False | ||
| frame_objects[frame_id] = temp.size(0) | ||
| if frame_objects[frame_id] > max_objects: | ||
| max_objects = frame_objects[frame_id] | ||
| if frame_objects[frame_id] < min_objects: | ||
| min_objects = frame_objects[frame_id] | ||
| bboxs.append(temp) | ||
|
|
||
| return bboxs |
There was a problem hiding this comment.
Function get_batch_dets refactored with the following changes:
- Replace list() with [] (
list-literal) - Convert for loop into list comprehension (
list-comprehension)
| msg = f'Step: [{current_step}/{max_step}]\t' \ | ||
|
|
||
| return f'Step: [{current_step}/{max_step}]\t' \ | ||
| f'Type: {model_type}\t' \ | ||
| f'Time: {batch_time.val:.2f}s ({batch_time.avg:.2f}s)\t' \ | ||
| f'Speed: {speed:.1f} samples/s\t' \ | ||
| f'Data: {data_time.val:.2f}s ({data_time.avg:.2f}s)\t' + loss_string | ||
|
|
||
| return msg |
There was a problem hiding this comment.
Function make_info_message refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
|
|
||
| def _build_multi_optimizers(self, model_list): | ||
| param_groups = list() | ||
| param_groups = [] |
There was a problem hiding this comment.
Function OptimizerAPI._build_multi_optimizers refactored with the following changes:
- Replace list() with [] (
list-literal)
| model_combination = [] | ||
| for temp in include_parts: | ||
| model_combination.append(model[temp]) | ||
| model_combination = [model[temp] for temp in include_parts] |
There was a problem hiding this comment.
Function OptimizerAPI.__call__ refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension)
| indices = np.random.choice(num_samples, num_clusters, replace=False) | ||
| initial_state = X[indices] | ||
| return initial_state | ||
| return X[indices] |
There was a problem hiding this comment.
Function initialize refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
|
|
||
| if distance == 'euclidean': | ||
| pairwise_distance_function = pairwise_distance | ||
| elif distance == 'cosine': | ||
| if distance == 'cosine': | ||
| pairwise_distance_function = pairwise_cosine |
There was a problem hiding this comment.
Function kmeans refactored with the following changes:
- Simplify conditional into switch-like form (
switch) - Replace assignment with augmented assignment (
aug-assign)
| last_epoch: int = -1, | ||
| ): | ||
| if not list(milestones) == sorted(milestones): | ||
| if list(milestones) != sorted(milestones): |
There was a problem hiding this comment.
Function WarmupMultiStepLR.__init__ refactored with the following changes:
- Simplify logical expression using De Morgan identities (
de-morgan)
| """ | ||
| dataset = self.factory() | ||
| return dataset | ||
| return self.factory() |
There was a problem hiding this comment.
Function DataAPI._build_dataset refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| sampler = DistTrainSampler(_data_len) | ||
| return DistTrainSampler(_data_len) | ||
| else: | ||
| sampler = TrainSampler(_data_len, self.seed) | ||
| return sampler | ||
| return TrainSampler(_data_len, self.seed) |
There was a problem hiding this comment.
Function DataAPI._build_sampler refactored with the following changes:
- Lift return into if (
lift-return-into-if)
| dataloader_dict = self.build() | ||
| return dataloader_dict | ||
| return self.build() |
There was a problem hiding this comment.
Function DataAPI.__call__ refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| self.phase = 'train' | ||
| else: | ||
| self.phase = 'val' | ||
| self.phase = 'train' if self.is_training else 'val' |
There was a problem hiding this comment.
Function AbstractDatasetFactory.__init__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| clip_list = list() | ||
| clip_list_original = list() | ||
| clip_list = [] | ||
| clip_list_original = [] |
There was a problem hiding this comment.
Function VideoLoader.read refactored with the following changes:
- Replace list() with [] (
list-literal)
| if optimal_results < results: | ||
| optimal_results = results | ||
| optimal_results = max(optimal_results, results) |
There was a problem hiding this comment.
Function precision_recall_auc refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
| if optimal_results > results: | ||
| optimal_results = results | ||
| optimal_results = min(optimal_results, results) |
There was a problem hiding this comment.
Function compute_eer refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
|
|
There was a problem hiding this comment.
Function compute_auc_psnr refactored with the following changes:
- Replace comparison with min/max call (
min-max-identity)
|
|
||
| fpr, tpr, thresholds = metrics.roc_curve(labels, scores, pos_label=pos_label) | ||
| auc = metrics.auc(fpr, tpr) | ||
| results = RecordResult(fpr, tpr, thresholds, auc, dataset, sub_loss_file, sigma) | ||
|
|
||
| return results | ||
| return RecordResult(fpr, tpr, thresholds, auc, dataset, sub_loss_file, sigma) |
There was a problem hiding this comment.
Function compute_auc_score.get_results refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| args_name = list() | ||
| args_value = list() | ||
| args_name = [] | ||
| args_value = [] | ||
| for config in loss_cfg: | ||
| args_name.append(config[0]) | ||
| args_value.append(config[1]) | ||
| loss_args_template = namedtuple('LossArgs', args_name) | ||
| loss_args = loss_args_template._make(args_value) | ||
| return loss_args | ||
| return loss_args_template._make(args_value) |
There was a problem hiding this comment.
Function get_loss_args refactored with the following changes:
- Replace list() with [] (
list-literal) - Inline variable that is immediately returned (
inline-immediately-returned-variable)
| x = torch.mean(torch.pow(torch.abs(gen_frames - gt_frames), self.l_num)) | ||
| # x = torch.mean(torch.abs(gen_frames - gt_frames)**self.l_num) | ||
| return x | ||
| return torch.mean(torch.pow(torch.abs(gen_frames - gt_frames), self.l_num)) |
There was a problem hiding this comment.
Function IntensityLoss.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| loss = self.t1(outputs, labels) | ||
| return loss | ||
| return self.t1(outputs, labels) |
There was a problem hiding this comment.
Function AMCDiscriminateLoss.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| loss = self.t1(fake_outputs, fake) | ||
| return loss | ||
| return self.t1(fake_outputs, fake) |
There was a problem hiding this comment.
Function AMCGenerateLoss.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
| if target_is_real: | ||
| target_tensor = self.real_label | ||
| else: | ||
| target_tensor = self.fake_label | ||
| target_tensor = self.real_label if target_is_real else self.fake_label |
There was a problem hiding this comment.
Function GANLoss.get_target_tensor refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| if target_is_real: | ||
| loss = -prediction.mean() | ||
| else: | ||
| loss = prediction.mean() | ||
| loss = -prediction.mean() if target_is_real else prediction.mean() |
There was a problem hiding this comment.
Function GANLoss.__call__ refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp)
| self.netFeat = torch.nn.Sequential() | ||
|
|
||
| elif intLevel == 2: | ||
| else: |
There was a problem hiding this comment.
Function LiteFlowNet.__init__.Subpixel.__init__ refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
| self.netFeat = torch.nn.Sequential() | ||
|
|
||
| elif intLevel < 5: | ||
| else: |
There was a problem hiding this comment.
Function LiteFlowNet.__init__.Regularization.__init__ refactored with the following changes:
- Remove redundant conditional (
remove-redundant-if)
| layers = [] | ||
| layers.append(block(self.inplanes, planes, stride, downsample)) | ||
| layers = [block(self.inplanes, planes, stride, downsample)] | ||
| self.inplanes = planes * block.expansion | ||
| for i in range(1, blocks): | ||
| for _ in range(1, blocks): |
There was a problem hiding this comment.
Function PoseResNet._make_layer refactored with the following changes:
- Merge append into list declaration (
merge-list-append) - Replace unused for index with underscore (
for-index-underscore)
| x_sigmod = F.sigmoid(x) | ||
|
|
||
| return x_sigmod | ||
| return F.sigmoid(x) |
There was a problem hiding this comment.
Function AMCDiscriminiator.forward refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable)
|
|
||
| # for each sequence, we need to clear the internal_state | ||
| self.internal_state = list() | ||
| self.internal_state = [] |
There was a problem hiding this comment.
Function SingleStampConvLSTM.__init__ refactored with the following changes:
- Replace list() with [] (
list-literal)
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
masterbranch, then run: