Skip to content

Instantly share code, notes, and snippets.

View Jojozzc's full-sized avatar
🏍️
Racing

Jojo Jojozzc

🏍️
Racing
View GitHub Profile
@Jojozzc
Jojozzc / append_path.py
Created December 2, 2018 02:12
Append root path to system path in python
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)
@Jojozzc
Jojozzc / interval_peek.py
Created December 2, 2018 02:40
Find all no-zero continuous interval, then in every interval, set all element 0 except the peek.
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:
@Jojozzc
Jojozzc / simple_rgb2gray.py
Created December 2, 2018 07:34
Simple rgb2gray
def rgb2gray(img):
assert np.ndim(img) == 3
img = color.rgb2gray(img) * 255
img = np.uint8(img)
return img
@Jojozzc
Jojozzc / load_data_from_csv.py
Created December 2, 2018 12:45
load data from csv file use pandas
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):
@Jojozzc
Jojozzc / is_img_file.py
Created December 4, 2018 06:35
judge whether a file's name is image format
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)
@Jojozzc
Jojozzc / cal_IOU.py
Created December 15, 2018 12:34
Intersection over Union
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)
@Jojozzc
Jojozzc / file_count.py
Last active December 28, 2018 02:12
File count
# Usage:
# $python file_count.py [option]
# options:
# -r count recursively
# -s[dir] workdir
# eg.
# #work on curent workdir:
# $python file_count.py
# #count recursively
@Jojozzc
Jojozzc / gpu_monitor.py
Created December 28, 2018 11:26
get gpu memory usage rate by python
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
@Jojozzc
Jojozzc / disp_multiple_images.py
Created December 29, 2018 11:15 — forked from soply/disp_multiple_images.py
Plot multiple images with matplotlib in a single figure. Titles can be given optionally as second argument.
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.
@Jojozzc
Jojozzc / cvt_unix_like_path.py
Created January 8, 2019 09:21
convert path to unix-like path
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