remove unused functions

This commit is contained in:
Jeremy Howard
2018-04-24 06:41:49 -07:00
parent b2274ab380
commit 2cb5a5ff87
3 changed files with 1160 additions and 1201 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -73,47 +73,6 @@ def read_dirs(path, folder):
labels.append(label)
return filenames, labels, all_labels
def create_sample(path, r):
""" Takes a path to a dataset and creates a sample of specified size at <path>_sample
Parameters:
-----------
path: dataset path
r (float): proportion of examples to use as sample, in the range from 0 to 1
"""
sample_path = path + '_sample'
shutil.rmtree(sample_path, ignore_errors=True)
subdirs = [os.path.split(p)[1] for p in glob(os.path.join(path, '*'))]
copy_or_move_with_subdirs(subdirs, path, sample_path, r, move=False)
def create_val(path, r):
""" Takes a path to a dataset and creates a validation set of specified size
Note - this changes the dataset at <path> by moving files to the val set
Parameters:
-----------
path: dataset path
r (float): proportion of examples to use for validation, in the range from 0 to 1
"""
val_path = os.path.join(os.path.split(path)[0], 'valid')
subdirs = [os.path.split(p)[1] for p in glob(os.path.join(path, '*'))]
copy_or_move_with_subdirs(subdirs, path, val_path, r, move=True)
def copy_or_move_with_subdirs(subdir_lst, src, dst, r, move=False):
'''
Copy or move subdirectory of folders from source to destination.
r: no fucking clue
'''
do = shutil.move if move else shutil.copy
for subdir in subdir_lst:
os.makedirs(os.path.join(dst, subdir))
files = glob(os.path.join(src, subdir, '*'))
np.random.shuffle(files)
for f in files[:int(len(files) * r)]:
do(f, os.path.join(dst, subdir, os.path.split(f)[1]))
def n_hot(ids, c):
'''
one hot encoding by index. Returns array of length c, where all entries are 0, except for the indecies in ids