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 vinothpandian/akin-generator #7

Open
wants to merge 1 commit into
base: main
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 main branch, then run:

git fetch https://github.com/sourcery-ai-bot/akin-generator main
git merge --ff-only FETCH_HEAD
git reset HEAD^

response = generate_wireframe_samples(ui_design_pattern_type, sample_num=8)

return response
return generate_wireframe_samples(ui_design_pattern_type, sample_num=8)
Copy link
Author

Choose a reason for hiding this comment

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

Function generate_wireframes refactored with the following changes:

Comment on lines -33 to +35
self.gamma = self.add_weight(self.name + '_gamma',
shape=(),
initializer=tf.initializers.Zeros)
self.gamma = self.add_weight(
f'{self.name}_gamma', shape=(), initializer=tf.initializers.Zeros
)
Copy link
Author

Choose a reason for hiding this comment

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

Function _Attention.build refactored with the following changes:

Comment on lines -45 to +58

input_shape = tf.shape(query_tensor)

if self.data_format == 'channels_first':
height_axis = 2
width_axis = 3
else:
height_axis = 1
width_axis = 2

batchsize = input_shape[0]
height = input_shape[height_axis]
width = input_shape[width_axis]

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 _Attention.call:

Comment on lines -54 to -59
i = 0
for k, v in label_color_map.items():
for i, (k, v) in enumerate(label_color_map.items()):
img[(i * side) : (i * side) + side, 0:side, :] = [v[0], v[1], v[2]]
bottomLeftCornerOfText = (int(side * 1.5), (i * side) + int(side / 2))
bottomLeftCornerOfText = int(side * 1.5), i * side + side // 2
img = cv2.putText(img, str(k), bottomLeftCornerOfText, font, fontScale, fontColor, lineType)
i += 1
Copy link
Author

Choose a reason for hiding this comment

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

Function ColorMapper.save_color_map refactored with the following changes:

Comment on lines -64 to +62
sorted_color = []
sorted_color.append(colors.pop(max_i))
sorted_color = [colors.pop(max_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 ColorMapper.get_sorted_colors refactored with the following changes:

Comment on lines -94 to +93
if data is not None and len(data) > 0:
if data is not None and data:
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_json_file refactored with the following changes:

Comment on lines -22 to +29
img_path = os.path.join(android_elements_base_path, img_name + ".jpg")
img_path = os.path.join(android_elements_base_path, f"{img_name}.jpg")
if not os.path.exists(img_path):
img_path = os.path.join(android_elements_base_path, img_name + ".png")
img_path = os.path.join(android_elements_base_path, f"{img_name}.png")
img = cv2.imread(img_path, cv2.IMREAD_COLOR)
else:
img = None
text = s[2]
if text is None or len(text) == 0:
text = None
else:
text = text.strip().split(",")
text = None if text is None or len(text) == 0 else text.strip().split(",")
Copy link
Author

Choose a reason for hiding this comment

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

Function load_all_ui_images refactored with the following changes:

Comment on lines -46 to +50
else:
shapes = data["shapes"]
flags = data["flags"]
for shape in shapes:
label = shape["label"]
points = shape["points"]
elements.append(
[label, [int(points[0][0]), int(points[0][1]), int(points[1][0]), int(points[1][1])]]
)
shapes = data["shapes"]
flags = data["flags"]
for shape in shapes:
label = shape["label"]
points = shape["points"]
elements.append(
[label, [int(points[0][0]), int(points[0][1]), int(points[1][0]), int(points[1][1])]]
)
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_elements refactored with the following changes:

Comment on lines -74 to +72
elif flag == 1 or flag == 5:
elif flag in [1, 5]:
return cv2.resize(img, (w, h)), 0
elif flag == 2 or flag == 3 or flag == 4:
elif flag in [2, 3, 4]:
Copy link
Author

Choose a reason for hiding this comment

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

Function element_resize refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator [×2] (merge-comparisons)

Comment on lines -106 to +104
elif flag == 1 or flag == 5:
elif flag in [1, 5]:
return cv2.resize(img, (w, h)), 0
elif flag == 2 or flag == 3 or flag == 4:
elif flag in [2, 3, 4]:
Copy link
Author

Choose a reason for hiding this comment

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

Function element_resize_old refactored with the following changes:

  • Replace multiple comparisons of same variable with in operator [×2] (merge-comparisons)

Comment on lines -173 to +176
x = x1
y = y1
w = x2 - x1
h = y2 - y1
if x1 >= 0 and y1 >= 0 and x2 < img_w and y2 < img_h and w > 0 and h > 0:
x = x1
y = y1
if not real and (h < 20 or w < 20):
continue
elif h <= 0 or w <= 0 or y >= img_h or x >= img_w:
elif y >= img_h or x >= img_w:
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_img refactored with the following changes:

if len(text) - 4 >= 5:
new_length = len(text) - 4
r = text[0:new_length]
return r, True
else:
if len(text) < 9:
return text, False
new_length = len(text) - 4
r = text[:new_length]
return r, True
Copy link
Author

Choose a reason for hiding this comment

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

Function reduce_text_size refactored with the following changes:

Comment on lines -272 to +267
if label_resize == 3 and fw > 0 and w > fw:
accesible_w = w - fw
else:
accesible_w = w
accesible_w = w - fw if label_resize == 3 and fw > 0 and w > fw else w
Copy link
Author

Choose a reason for hiding this comment

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

Function add_text_pil refactored with the following changes:

Comment on lines -348 to +340
dst_file_path = os.path.join(dst_folder_path, str(count) + "_" + str(real) + ".jpg")
dst_file_path = os.path.join(dst_folder_path, f"{str(count)}_{str(real)}.jpg")
Copy link
Author

Choose a reason for hiding this comment

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

Lines 348-348 refactored with the following changes:

for i in range(repeat_num - 4):
for _ in range(repeat_num - 4):
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_generator refactored with the following changes:

Comment on lines -110 to +117
if image_label in cat_count.keys() and cat_count[image_label] >= 100:
continue
else:
if image_label not in cat_count.keys():
images.append(image_path)
labels.append(image_label)
if image_label not in cat_count.keys():
cat_count[image_label] = 1
else:
cat_count[image_label] += 1
cat_count[image_label] = 1
elif cat_count[image_label] < 100:
images.append(image_path)
labels.append(image_label)
cat_count[image_label] += 1
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.get_data_generator refactored with the following changes:

Comment on lines -196 to +195
print("epoch: {}".format(self.epoch))
print(f"epoch: {self.epoch}")
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.train refactored with the following changes:

Comment on lines -41 to +62
else:
label_count = UILabelFileManager.get_label_counts(label_count_file)
hierarchy_map = UILabelFileManager.get_ui_hierarchy_map(heirarchy_file)
hierarchy_count = {}
for k, v in hierarchy_map.items():
if len(v) < level - 1:
label = v[-1]
else:
label = v[level - 1]
if k not in label_count.keys():
count = 0
print(k + " not in label count")
else:
count = label_count[k]
if label in hierarchy_count.keys():
hierarchy_count[label] += count
else:
hierarchy_count[label] = count
heirarchy_count_list = list(hierarchy_count.items())
heirarchy_count_list.sort(key=lambda x: x[1], reverse=True)
print(heirarchy_count_list)
if with_count:
return heirarchy_count_list
label_count = UILabelFileManager.get_label_counts(label_count_file)
hierarchy_map = UILabelFileManager.get_ui_hierarchy_map(heirarchy_file)
hierarchy_count = {}
for k, v in hierarchy_map.items():
label = v[-1] if len(v) < level - 1 else v[level - 1]
if k not in label_count.keys():
count = 0
print(f"{k} not in label count")
else:
count = label_count[k]
if label in hierarchy_count:
hierarchy_count[label] += count
else:
sorted_labels = [v[0] for v in heirarchy_count_list]
return sorted_labels
hierarchy_count[label] = count
heirarchy_count_list = list(hierarchy_count.items())
heirarchy_count_list.sort(key=lambda x: x[1], reverse=True)
print(heirarchy_count_list)
return (
heirarchy_count_list
if with_count
else [v[0] for v in heirarchy_count_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 UILabelFileManager.get_sorted_labels_for_hierarchy refactored with the following changes:

Comment on lines -80 to +83
if level >= 1:
hierarchy_map = UILabelFileManager.get_ui_hierarchy_map(file)
hierarchy_label_map = {}
for k, v in hierarchy_map.items():
if len(v) < level - 1:
label = v[-1]
else:
label = v[level - 1]
hierarchy_label_map[k] = label
return hierarchy_label_map
else:
if level < 1:
return {}
hierarchy_map = UILabelFileManager.get_ui_hierarchy_map(file)
hierarchy_label_map = {}
for k, v in hierarchy_map.items():
label = v[-1] if len(v) < level - 1 else v[level - 1]
hierarchy_label_map[k] = label
return hierarchy_label_map
Copy link
Author

Choose a reason for hiding this comment

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

Function UILabelFileManager.get_hierarchy_label_map refactored with the following changes:

json_name = name[:-3] + "json"
json_name = f"{name[:-3]}json"
Copy link
Author

Choose a reason for hiding this comment

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

Function Utils.copy_json_files 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.

None yet

1 participant