Skip to content
This repository has been archived by the owner on Feb 17, 2022. It is now read-only.

Sourcery Starbot ⭐ refactored YuhaoCheng/PyAnomaly #13

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

Conversation

SourceryAI
Copy link

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:

git fetch https://github.com/sourcery-ai-bot/PyAnomaly master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Author

@SourceryAI SourceryAI 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.

result_image = None

return result_image
return None
Copy link
Author

Choose a reason for hiding this comment

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

Function make_result refactored with the following changes:

Comment on lines -219 to +225
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)

Copy link
Author

Choose a reason for hiding this comment

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

Function frame_gradient refactored with the following changes:

temp_list = list()
temp_list = []
Copy link
Author

Choose a reason for hiding this comment

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

Function vis_optical_flow refactored with the following changes:

Comment on lines -353 to +379
"""
"""
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
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_batch_dets refactored with the following changes:

Comment on lines -451 to -458
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
Copy link
Author

Choose a reason for hiding this comment

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

Function make_info_message refactored with the following changes:

param_groups = list()
param_groups = []
Copy link
Author

Choose a reason for hiding this comment

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

Function OptimizerAPI._build_multi_optimizers refactored with the following changes:

model_combination = []
for temp in include_parts:
model_combination.append(model[temp])
model_combination = [model[temp] for temp in include_parts]
Copy link
Author

Choose a reason for hiding this comment

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

Function OptimizerAPI.__call__ refactored with the following changes:

initial_state = X[indices]
return initial_state
return X[indices]
Copy link
Author

Choose a reason for hiding this comment

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

Function initialize refactored with the following changes:

Comment on lines -44 to 47
if distance == 'euclidean':
pairwise_distance_function = pairwise_distance
elif distance == 'cosine':
if distance == 'cosine':
pairwise_distance_function = pairwise_cosine
Copy link
Author

Choose a reason for hiding this comment

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

Function kmeans refactored with the following changes:

  • Simplify conditional into switch-like form (switch)
  • Replace assignment with augmented assignment (aug-assign)

if not list(milestones) == sorted(milestones):
if list(milestones) != sorted(milestones):
Copy link
Author

Choose a reason for hiding this comment

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

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()
Copy link
Author

Choose a reason for hiding this comment

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

Function DataAPI._build_dataset refactored with the following changes:

Comment on lines -131 to +132
sampler = DistTrainSampler(_data_len)
return DistTrainSampler(_data_len)
else:
sampler = TrainSampler(_data_len, self.seed)
return sampler
return TrainSampler(_data_len, self.seed)
Copy link
Author

Choose a reason for hiding this comment

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

Function DataAPI._build_sampler refactored with the following changes:

Comment on lines -144 to +142
dataloader_dict = self.build()
return dataloader_dict
return self.build()
Copy link
Author

Choose a reason for hiding this comment

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

Function DataAPI.__call__ refactored with the following changes:

if self.is_training:
self.phase = 'train'
else:
self.phase = 'val'
self.phase = 'train' if self.is_training else 'val'
Copy link
Author

Choose a reason for hiding this comment

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

Function AbstractDatasetFactory.__init__ refactored with the following changes:

Comment on lines -148 to +149
clip_list = list()
clip_list_original = list()
clip_list = []
clip_list_original = []
Copy link
Author

Choose a reason for hiding this comment

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

Function VideoLoader.read refactored with the following changes:

Comment on lines -309 to +303
if optimal_results < results:
optimal_results = results
optimal_results = max(optimal_results, results)
Copy link
Author

Choose a reason for hiding this comment

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

Function precision_recall_auc refactored with the following changes:

Comment on lines -339 to +332
if optimal_results > results:
optimal_results = results
optimal_results = min(optimal_results, results)
Copy link
Author

Choose a reason for hiding this comment

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

Function compute_eer refactored with the following changes:

Comment on lines -414 to +406

Copy link
Author

Choose a reason for hiding this comment

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

Function compute_auc_psnr refactored with the following changes:

Comment on lines -460 to +454

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)
Copy link
Author

Choose a reason for hiding this comment

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

Function compute_auc_score.get_results refactored with the following changes:

Comment on lines -31 to +37
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)
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_loss_args refactored with the following changes:

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))
Copy link
Author

Choose a reason for hiding this comment

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

Function IntensityLoss.forward refactored with the following changes:

Comment on lines -140 to +138
loss = self.t1(outputs, labels)
return loss
return self.t1(outputs, labels)
Copy link
Author

Choose a reason for hiding this comment

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

Function AMCDiscriminateLoss.forward refactored with the following changes:

Comment on lines -149 to +146
loss = self.t1(fake_outputs, fake)
return loss
return self.t1(fake_outputs, fake)
Copy link
Author

Choose a reason for hiding this comment

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

Function AMCGenerateLoss.forward refactored with the following changes:

Comment on lines -197 to +193
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
Copy link
Author

Choose a reason for hiding this comment

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

Function GANLoss.get_target_tensor refactored with the following changes:

Comment on lines -217 to +210
if target_is_real:
loss = -prediction.mean()
else:
loss = prediction.mean()
loss = -prediction.mean() if target_is_real else prediction.mean()
Copy link
Author

Choose a reason for hiding this comment

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

Function GANLoss.__call__ refactored with the following changes:

elif intLevel == 2:
else:
Copy link
Author

Choose a reason for hiding this comment

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

Function LiteFlowNet.__init__.Subpixel.__init__ refactored with the following changes:

elif intLevel < 5:
else:
Copy link
Author

Choose a reason for hiding this comment

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

Function LiteFlowNet.__init__.Regularization.__init__ refactored with the following changes:

Comment on lines -240 to +242
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):
Copy link
Author

Choose a reason for hiding this comment

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

Function PoseResNet._make_layer refactored with the following changes:

x_sigmod = F.sigmoid(x)

return x_sigmod
return F.sigmoid(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 AMCDiscriminiator.forward refactored with the following changes:

self.internal_state = list()
self.internal_state = []
Copy link
Author

Choose a reason for hiding this comment

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

Function SingleStampConvLSTM.__init__ refactored with the following changes:

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

Successfully merging this pull request may close these issues.

1 participant