This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def divide_chunks(a_list, chunk_size): | |
"""Divide a list in chunks from given size | |
""" | |
for i in range(0, len(a_list), chunk_size): | |
yield a_list[i:i + chunk_size] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
def concat_images(im1, im2): | |
""" Concat two images towards the height | |
""" | |
dst_img = Image.new('RGB', (min(im1.width, im2.width), im1.height + im2.height)) | |
dst_img.paste(im1, (0, 0)) | |
dst_img.paste(im2, (0, im1.height)) | |
return dst_img |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def merge_items(a_list): | |
"""Merge the 4 lists of items | |
and combine as values to keys | |
""" | |
#Same amount of lists of lists to receive a key | |
keys = ['key1','key2','key3','key4'] | |
items = [list(i) for i in list(zip(*a_list))] | |
result = [] | |
for i in items: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from keras import backend as K | |
def grayscale_to_rgb(images, channel_axis=-1): | |
'''Function to convert the Grayscale data | |
to RGB to match with an architecture | |
''' | |
images= K.expand_dims(images, axis=channel_axis) | |
tiling = [1] * 4 # 4 dimensions: B, H, W, C | |
tiling[channel_axis] *= 3 | |
images= K.tile(images, tiling) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def remove_none(json_file): | |
""" Remove null keys and values from | |
a nested structure of dicts, tuple and lists. | |
""" | |
if isinstance(json_file, (list, tuple, set)): | |
return type(json_file)(remove_none(x) for x in json_file if x is not None) | |
elif isinstance(json_file, dict): | |
return type(json_file)((remove_none(k), remove_none(v)) | |
for k, v in json_file.items() if k is not None and v is not None) | |
else: |
NewerOlder