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: |
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 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 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 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
def merge_list(a_list): | |
"""Merge together items from list of lists sequentially | |
""" | |
return [list(i) for i in list(zip(*a_list))] | |
""" | |
i. e. | |
[[1,2,3], [4,5,6]] | |
result: | |
[[1,4], [2,5], [3,6]] |
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 load_images_from_folder(folder): | |
images = [] | |
for filename in os.listdir(folder): | |
img = cv2.imread(os.path.join(folder,filename)) | |
if img is not None: | |
images.append(img) | |
return images |
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 clean_blocks(): | |
for block in bpy.data.meshes: | |
if block.users == 0: | |
bpy.data.meshes.remove(block) | |
for block in bpy.data.materials: | |
if block.users == 0: | |
bpy.data.materials.remove(block) | |
for block in bpy.data.textures: |
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 intersection(horizontal, vertical): | |
# https://en.wikipedia.org/wiki/Line%E2%80%93line_intersection | |
# Horizontal x y x y | |
# Vertical x y x y | |
# x1, y1, x2, y2, x3, y3, x4, y4 | |
# 0 1 2 3 0 1 2 3 | |
result = [] | |
x1, x2, x3, x4, y1, y2, y3, y4 = int(horizontal[0]), int(horizontal[2]), int(vertical[0]), int(vertical[2]), int(horizontal[1]), int(horizontal[3]), int(vertical[1]), int(vertical[3]) |
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
import websocket | |
try: | |
import thread | |
except ImportError: | |
import _thread as thread | |
import time | |
import argparse | |
import socks | |
parser = argparse.ArgumentParser() |
OlderNewer