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 numpy as np | |
class inputGen: | |
def __init__(self, batch_size, X, y, shuffle=True): | |
self.batch_size = batch_size | |
self.X = X | |
self.y = y | |
self.cursor = 0 | |
self.n_samples = X.shape[0] | |
self.ids_sequence = np.arange(X.shape[0]) |
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
from glob import iglob | |
def return_impaths(dpath): | |
impaths = [list(iglob('{}/*.{}'.format(dpath, e))) for e in ['png', 'jpg', 'jpeg']] | |
impaths = sum(impaths, []) | |
return impaths |
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
# https://arxiv.org/pdf/1602.07360.pdf | |
# | |
from keras import backend as K | |
from keras.layers import Input, Convolution2D, MaxPooling2D, Activation, concatenate | |
from keras.layers import GlobalAveragePooling2D | |
from keras.models import Model | |
class SqueezeNet: | |
def __init__(self, input_shape, n_classes): |
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
from line_profiler import LineProfiler | |
def do_profile(follow=[]): | |
def inner(func): | |
def profiled_func(*args, **kwargs): | |
try: | |
profiler = LineProfiler() | |
profiler.add_function(func) | |
for f in follow: | |
profiler.add_function(f) | |
profiler.enable_by_count() |
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
# Install cuda-10.0 because the newest one (for now the version 10.2) mismatchs the tensorflow 1.14.0 requirements | |
wget https://developer.nvidia.com/compute/cuda/10.0/Prod/local_installers/cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd6 | |
dpkg -i cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd6 | |
apt-key add /var/cuda-repo-10-0-local-10.0.130-410.48/7fa2af80.pub | |
apt-get install cuda | |
# This cuda version install nvidia v410 drivers. Remove it. |
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 logging | |
from logging.handlers import RotatingFileHandler | |
import traceback | |
logger = logging.getLogger() | |
logger.setLevel(logging.DEBUG) | |
handler = RotatingFileHandler('app.log', mode='a', maxBytes=50e6, backupCount=2) | |
formatter = logging.Formatter('%(asctime)s,%(message)s', datefmt='%Y-%m-%d %H:%M:%S') | |
handler.setFormatter(formatter) |
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 traceback | |
import sys | |
try: | |
pass | |
except Exception as e: | |
traceback_info = ''.join(traceback.format_exception(*sys.exc_info())) | |
logger.info(traceback_info) |
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
xgb_params = {'objective': 'multi:softmax', | |
'num_class': 19, | |
'tree_method': 'exact', | |
# 'max_bin': 64, | |
'colsample_bytree': 0.75, | |
'subsample': 0.75, | |
# 'lambda': 2, | |
# 'alpha': 2, | |
# 'min_child_weight': 10, | |
# 'max_delta_step': 10, |
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
# Code adapted from skimage | |
# https://github.com/riaanvddool/scikits-image/blob/master/skimage/color/delta_e.py#L123 | |
import numpy as np | |
import tensorflow as tf | |
def tf_deg2rad(deg): | |
return (deg / 180) * np.pi | |
def tf_rad2deg(rad): |
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 parse_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-d', type=str, help='directory path', dest='dpath') | |
parser.add_argument('-f', type=str, help='filepath', dest='fpath') | |
return parser.parse_args() | |
if __name__ == '__main__': | |
args = parse_args() | |
if not any([args.dpath, args.fpath]): |