This file contains hidden or 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 os, sys | |
curPath = os.path.abspath(os.path.dirname(__file__)) | |
rootPath = os.path.split(curPath)[0] | |
print('rootPath:{}'.format(rootPath)) | |
sys.path.append(rootPath) |
This file contains hidden or 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 interval_peek(arr): | |
''' | |
Find all no-zero continuous interval, then in every interval, set all element 0 except the peek. | |
:param arr: | |
:return: | |
''' | |
left = 0 | |
arr_len = len(arr) | |
res = arr[:] | |
while left < arr_len: |
This file contains hidden or 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 rgb2gray(img): | |
assert np.ndim(img) == 3 | |
img = color.rgb2gray(img) * 255 | |
img = np.uint8(img) | |
return img |
This file contains hidden or 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 pandas as pd | |
import numpy as np | |
def load_train_data(path='inputFiles/train.csv'): | |
x = [] | |
y = [] | |
data = pd.read_csv(path) | |
data = data.values | |
data_num = len(data) | |
for i in range(0, data_num): |
This file contains hidden or 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 re | |
def is_img_file(file_name): | |
file_name = str(file_name) | |
file_name = file_name.lower() | |
return re.search('\.bmp$', file_name) or re.search('\.png$', file_name) or \ | |
re.search('\.jpg$', file_name) or re.search('\.jpeg', file_name) or re.search('\.tiff', file_name) |
This file contains hidden or 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 cal_IoU(img, lab, nb_class): | |
for i in range(nb_class): | |
mask1 = (img == (i + 1)).astype('uint8') | |
mask2 = (lab == (i + 1)).astype('uint8') | |
mask_and = cv2.bitwise_and(mask1, mask2) | |
mask_or = cv2.bitwise_or(mask1, mask2) | |
s1 = np.sum(mask_and) | |
s2 = np.sum(mask_or) |
This file contains hidden or 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
# Usage: | |
# $python file_count.py [option] | |
# options: | |
# -r count recursively | |
# -s[dir] workdir | |
# eg. | |
# #work on curent workdir: | |
# $python file_count.py | |
# #count recursively |
This file contains hidden or 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 os | |
# GPU 00000000:88:00.0 | |
# FB Memory Usage | |
# Total : 8119 MiB | |
# Used : 2 MiB | |
# Free : 8117 MiB | |
# BAR1 Memory Usage | |
# Total : 256 MiB | |
# Used : 5 MiB | |
# Free : 251 MiB |
This file contains hidden or 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 matplotlib.pyplot as plt | |
import numpy as np | |
def show_images(images, cols = 1, titles = None): | |
"""Display a list of images in a single figure with matplotlib. | |
Parameters | |
--------- | |
images: List of np.arrays compatible with plt.imshow. | |
This file contains hidden or 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 cvt_unix_like_path(path): | |
if path is None: | |
return None | |
path = str(path) | |
unix_p_temp = path.replace('\\', '/') | |
unix_p = '' | |
pre = '' | |
for ch in unix_p_temp: | |
if not (ch == '/'): | |
unix_p = unix_p + ch |
OlderNewer