Skip to content
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 JJBT/RevO #1

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

Conversation

sourcery-ai-bot
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/RevO master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Copy link
Author

@sourcery-ai-bot sourcery-ai-bot 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.

backbone = object_from_dict(cfg)
return backbone
return object_from_dict(cfg)
Copy link
Author

Choose a reason for hiding this comment

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

Function create_backbone refactored with the following changes:

Comment on lines -36 to +35
train_dataloaders = dict()
train_dataloaders = {}
Copy link
Author

Choose a reason for hiding this comment

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

Function create_train_dataloader refactored with the following changes:

Comment on lines -45 to +44
val_dataloaders = dict()
val_dataloaders = {}
Copy link
Author

Choose a reason for hiding this comment

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

Function create_val_dataloader refactored with the following changes:

Comment on lines -54 to +69
params = dict()
params['type'] = cfg.type
params['q_root'] = cfg.query.root
params['s_root'] = cfg.support.root
params['q_ann_filename'] = cfg.query.annotations
params['s_ann_filename'] = cfg.support.annotations
params['k_shot'] = cfg.k_shot
params['q_img_size'] = cfg.input_size
params['backbone_stride'] = cfg.backbone_stride
params = {
'type': cfg.type,
'q_root': cfg.query.root,
's_root': cfg.support.root,
'q_ann_filename': cfg.query.annotations,
's_ann_filename': cfg.support.annotations,
'k_shot': cfg.k_shot,
'q_img_size': cfg.input_size,
'backbone_stride': cfg.backbone_stride,
}

q_transform = create_augmentations(cfg.transforms)
s_transform = create_augmentations(cfg.transforms)
params['q_transform'] = q_transform
params['s_transform'] = s_transform

dataset = object_from_dict(params)
return dataset
return object_from_dict(params)
Copy link
Author

Choose a reason for hiding this comment

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

Function create_dataset refactored with the following changes:

Comment on lines -74 to +76
dataset_length = cfg.len
shuffle = cfg.shuffle

if dataset_length:
if dataset_length := cfg.len:
Copy link
Author

Choose a reason for hiding this comment

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

Function create_dataloader refactored with the following changes:

Comment on lines -196 to +187
if denominator == 0:
result = 0.
else:
result = numerator / denominator

return result
return 0. if denominator == 0 else numerator / denominator
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.compute refactored with the following changes:

Comment on lines -228 to +221
if self._total == 0:
result = dict.fromkeys(self._loss_sum_dict.keys(), 0)
else:
result = dict()
for loss_name, loss_value in self._loss_sum_dict.items():
result[loss_name] = loss_value / self._total

return result
return (
dict.fromkeys(self._loss_sum_dict.keys(), 0)
if self._total == 0
else {
loss_name: loss_value / self._total
for loss_name, loss_value in self._loss_sum_dict.items()
}
)
Copy link
Author

Choose a reason for hiding this comment

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

Function TorchLoss.compute refactored with the following changes:

output_img = draw(pr_input['q_img'][0], outputs[0])
return output_img
return draw(pr_input['q_img'][0], outputs[0])
Copy link
Author

Choose a reason for hiding this comment

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

Function fn refactored with the following changes:

Comment on lines -47 to -52
if self.last_epoch == 0:
if self.last_epoch == 0 or self.last_epoch > self.W_steps:
return self.base_lrs
elif self.last_epoch <= self.W_steps:
return [base_lr * (self.last_epoch / self.W_steps) for base_lr in self.base_lrs]
else:
return self.base_lrs
Copy link
Author

Choose a reason for hiding this comment

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

Function WarmUp.get_lr refactored with the following changes:

self.validation_metrics = dict()
self.validation_metrics = {}
Copy link
Author

Choose a reason for hiding this comment

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

Function State.__init__ refactored with the following changes:

msg = f'Validation '
msg = 'Validation '
Copy link
Author

Choose a reason for hiding this comment

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

Function State.log_validation refactored with the following changes:

Comment on lines -86 to +89
self.accelerator = Accelerator(cpu=bool(cfg.device == 'cpu'), fp16=cfg.amp)
self.accelerator = Accelerator(cpu=cfg.device == 'cpu', fp16=cfg.amp)
self.model, self.optimizer = self.accelerator.prepare(self.model, self.optimizer)
self.train_dataloader_dict, self.val_dataloader_dict = \
self.prepare_dataloader_dict(self.train_dataloader_dict, self.val_dataloader_dict)
self.prepare_dataloader_dict(self.train_dataloader_dict, self.val_dataloader_dict)
Copy link
Author

Choose a reason for hiding this comment

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

Function Trainer.__init__ refactored with the following changes:

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

Choose a reason for hiding this comment

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

Function Trainer.prepare_dataloader_dict refactored with the following changes:

if attributes is None:
self._attributes = dict()
else:
self._attributes = attributes

self._attributes = {} if attributes is None else attributes
Copy link
Author

Choose a reason for hiding this comment

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

Function Callback.__init__ refactored with the following changes:

if filename is not None:
self.filename = filename
else:
self.filename = self._search_checkpoint()

self.filename = filename if filename is not None else self._search_checkpoint()
Copy link
Author

Choose a reason for hiding this comment

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

Function LoadCheckpointCallback.__init__ refactored with the following changes:

Comment on lines -234 to +230
filename = phase + f'{i:05d}.png'
filename = f'{phase}{i:05d}.png'
Copy link
Author

Choose a reason for hiding this comment

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

Function transform_to_coco_format refactored with the following changes:

Comment on lines -283 to +274

Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function main:

Comment on lines -27 to +29
elif isinstance(h_resize_limit, tuple) or isinstance(h_resize_limit, list):
elif isinstance(h_resize_limit, (tuple, list)):
assert all(list(map(lambda x: isinstance(x, float), h_resize_limit)))
assert all(list(map(lambda x: 0. <= x, h_resize_limit)))
assert all(list(map(lambda x: x >= 0., h_resize_limit)))
Copy link
Author

Choose a reason for hiding this comment

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

Function RandomResize.__init__ refactored with the following changes:

if y < 0 or y + h > self.dataset.H:
return False
return True
return y >= 0 and y + h <= self.dataset.H
Copy link
Author

Choose a reason for hiding this comment

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

Function MegapixelMNIST.Sample._locate_pathces refactored with the following changes:

Comment on lines -156 to +154
colour * np.stack((patch,) * self.n_channels, axis=2)
colour * np.stack((patch,) * self.n_channels, axis=2)
Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function MegapixelMNIST.Sample.get_sample:

Comment on lines -197 to +195
sample = self.Sample(self, idxs).get_sample()

return sample
return self.Sample(self, idxs).get_sample()
Copy link
Author

Choose a reason for hiding this comment

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

Function MegapixelMNIST._get_sample refactored with the following changes:

Comment on lines -236 to +232
filename = phase + f'{i:05d}.png'
filename = f'{phase}{i:05d}.png'
Copy link
Author

Choose a reason for hiding this comment

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

Function transform_to_coco_format refactored with the following changes:

Comment on lines -285 to +276

Copy link
Author

Choose a reason for hiding this comment

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

Found the following improvement in Function main:

if x < 0 or x + 28 > self._W:
return False
if y < 0 or y + 28 > self._H:
return False
return True
return False if x < 0 or x + 28 > self._W else y >= 0 and y + 28 <= self._H
Copy link
Author

Choose a reason for hiding this comment

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

Function MegapixelMNISTGrided._get_positions refactored with the following changes:

Comment on lines -179 to +175
filename = phase + f'{i:05d}.png'
filename = f'{phase}{i:05d}.png'
Copy link
Author

Choose a reason for hiding this comment

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

Function transform_to_coco_format refactored with the following changes:

Comment on lines -26 to -31
filtered_coco = {
return {
'images': imgs_to_keep,
'annotations': anns_to_keep,
'categories': cats_to_keep
'categories': cats_to_keep,
}
return filtered_coco
Copy link
Author

Choose a reason for hiding this comment

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

Function filter_coco_by_cats refactored with the following changes:

Comment on lines -83 to +97
support_image_meta = {}
support_image_meta['file_name'] = str(i).rjust(5, '0') + '.jpg'
support_image_meta = {'file_name': str(i).rjust(5, '0') + '.jpg'}
support_image_meta['height'] = support_image.shape[0]
support_image_meta['weight'] = support_image.shape[1]
support_image_meta['id'] = i
support_images.append(support_image_meta)

support_ann = {}
support_ann['num_keypoints'] = ann['num_keypoints']
support_ann['keypoints'] = support_kps
support_ann['image_id'] = support_image_meta['id']
support_ann['bbox'] = support_bbox
support_ann['category_id'] = ann['category_id']
support_ann['id'] = i
support_ann = {
'num_keypoints': ann['num_keypoints'],
'keypoints': support_kps,
'image_id': support_image_meta['id'],
'bbox': support_bbox,
'category_id': ann['category_id'],
'id': i,
}

Copy link
Author

Choose a reason for hiding this comment

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

Function gen_support_pool refactored with the following changes:

res = urllib.request.urlopen(req, timeout=10)
return res
return urllib.request.urlopen(req, timeout=10)
Copy link
Author

Choose a reason for hiding this comment

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

Function url_request refactored with the following changes:

context = {
'image_mode': 'RGB',
'shape': self.shape,
'name': self.name
}
return context
return {'image_mode': 'RGB', 'shape': self.shape, 'name': self.name}
Copy link
Author

Choose a reason for hiding this comment

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

Function ImageInput.get_context refactored with the following changes:

return "data:image/png;base64," + base64_str
return f"data:image/png;base64,{base64_str}"
Copy link
Author

Choose a reason for hiding this comment

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

Function array_to_base64 refactored with the following changes:

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

Successfully merging this pull request may close these issues.

2 participants