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 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 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 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 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 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 rlcompleter | |
import pdb | |
pdb.Pdb.complete = rlcompleter.Completer(locals()).complete | |
pdb.set_trace() | |
# Oneline to insert into code | |
import rlcompleter; import pdb; pdb.Pdb.complete = rlcompleter.Completer(locals()).complete; pdb.set_trace() |
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 argparse | |
def parse_args(): | |
parser = argparse.ArgumentParser() | |
parser.add_argument('-e', type=str, help='Environment variable', required=True, dest='var1', | |
choices=['staging', 'production']) | |
parser.add_argument('--hypertuning', help='Run hypertuning process', action='store_true', dest='var2') | |
return parser.parse_args() | |
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
# Easy to go tools | |
- http://www.robots.ox.ac.uk/~vgg/software/via/via-1.0.6.html | |
- https://github.com/virajmavani/semi-auto-image-annotation-tool | |
- https://labelbox.com/ -> Free until 2500 images per year. | |
# More references | |
- https://github.com/jsbroks/awesome-dataset-tools | |
- https://www.datasetlist.com/tools/ |
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 matplotlib.pyplot as plt | |
fig, axs = plt.subplots(4, figsize=(12, 12)) | |
for i in range(4): | |
axs[i].imshow(sample_masks[:, :, i]) | |
axs[i].axis('off') |
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
# Code snippet to train lightgbm models quickly, using the number of iterations based on CV | |
import lightgbm as lgb | |
lgb_dftrain = lgb.Dataset(features_train, target_train) | |
params = {'boosting_type': 'gbdt', | |
'objective': 'binary', | |
'enable_bundle': True, | |
'max_conflict_rate': 0, | |
'max_depth': 20, |
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 cv2 | |
import numpy as np | |
from keras.applications import ResNet50 | |
from keras.applications import imagenet_utils | |
from keras.preprocessing.image import img_to_array | |
model = ResNet50(weights='imagenet') | |
camera = cv2.VideoCapture(0) | |
# If possible control the FPS to constrain the labels appearances |