image_dimensions = 3 ########################## # DATA LOADING ########################## print("Loading paths...") # download & untar or get local path base_path = caltech101.download(dataset='img-gen-resized') # path to image folder base_path = os.path.join(base_path, caltech101.config.tar_inner_dirname) # X_test contain only paths to images (X_test, y_test) = util.load_paths_from_files(base_path, 'X_test.txt', 'y_test.txt') for cv_fold in [ 0 ]: # on which cross val folds to run; cant loop over several folds due to some bug print("fold {}".format(cv_fold)) experiment_name = '_bn_triangular_cv{}_e{}'.format(cv_fold, nb_epoch) # load cross val split (X_train, y_train), (X_val, y_val) = util.load_cv_split_paths(base_path, cv_fold) # compute class weights, since classes are highly imbalanced class_weight = compute_class_weight('auto', range(nb_classes), y_train)
def load_train_test_split_paths(base_path): return load_paths_from_files(base_path, 'X_train.txt', 'y_train.txt'), \ load_paths_from_files(base_path, 'X_test.txt', 'y_test.txt')
image_dimensions = 3 ########################## # DATA LOADING ########################## print("Loading paths...") # download & untar or get local path base_path = caltech101.download(dataset='img-gen-resized') # path to image folder base_path = os.path.join(base_path, caltech101.config.tar_inner_dirname) # X_test contain only paths to images (X_test, y_test) = util.load_paths_from_files(base_path, 'X_test.txt', 'y_test.txt') for cv_fold in [0]: # on which cross val folds to run; cant loop over several folds due to some bug print("fold {}".format(cv_fold)) experiment_name = '_bn_triangular_cv{}_e{}'.format(cv_fold, nb_epoch) # load cross val split (X_train, y_train), (X_val, y_val) = util.load_cv_split_paths(base_path, cv_fold) # compute class weights, since classes are highly imbalanced class_weight = compute_class_weight('auto', range(nb_classes), y_train) if normalize_data: print("Load mean and std...") X_mean, X_std = util.load_cv_stats(base_path, cv_fold)
import os from ini_caltech101 import util path = os.path.abspath(os.path.join('datasets', 'img-gen-resized', '101_ObjectCategories')) stratify = True seed = 42 # X_train contain only paths to images (X_train, y_train) = util.load_paths_from_files(path, 'X_train.txt', 'y_train.txt', full_path=False) (X_train, y_train) = util.shuffle_data(X_train, y_train, seed=seed) nb_folds = 10 for cv_fold, ((X_cv_train, y_cv_train), (X_cv_test, y_cv_test)) in \ enumerate(util.make_cv_split(X_train, y_train, nb_folds=nb_folds, stratify=stratify, seed=seed)): split_config = {'fold': cv_fold, 'nb_folds': nb_folds, 'stratify': stratify, 'seed': seed, 'train_samples': len(X_cv_train), 'test_samples': len(X_cv_test)} print("Save split for fold {}".format(cv_fold)) util.save_cv_split_paths(path, X_cv_train, y_cv_train, X_cv_test, y_cv_test, cv_fold, split_config) print("Calculating mean and std...") X_mean, X_std = util.calc_stats(X_cv_train, base_path=path) print("Save stats")