kf = KFold(n_splits=n_folds) trainval_id_type_list = np.array(trainval_id_type_list) for train_index, test_index in kf.split(trainval_id_type_list): train_id_type_list, val_id_type_list = trainval_id_type_list[ train_index], trainval_id_type_list[test_index] if len(val_fold_indices) > 0: if val_fold_index not in val_fold_indices: val_fold_index += 1 continue val_fold_index += 1 print("\n\n ---- Validation fold index: ", val_fold_index, "/", n_folds) print(datetime.now(), len(train_id_type_list), len(val_id_type_list)) assert len(to_set(train_id_type_list) & to_set(val_id_type_list)) == 0, "WTF" cnn = params['network'](lr=params['lr_kwargs']['lr'], **params, **params['network_kwargs']) params['save_prefix'] = params['save_prefix_template'].format( cnn_name=cnn.name, fold_index=val_fold_index - 1) print("\n {} - Loaded {} model ...".format(datetime.now(), cnn.name)) if 'pretrained_model' in params: load_pretrained_model(cnn, **params) print("\n {} - Start training ...".format(datetime.now())) h = train(cnn, train_id_type_list, val_id_type_list, **params) if h is None:
np.random.seed(seed) cache = DataCache(0) # !!! CHECK BEFORE LOAD TO FLOYD class_index = 0 trainval_id_type_list = get_id_type_list_for_class(class_index) n_other_samples = len(trainval_id_type_list) class_indices = list(equalized_data_classes.keys()) class_indices.remove(class_index) for index in class_indices: id_type_list = np.array(get_id_type_list_for_class(index)) id_type_list = list(to_set(id_type_list) - to_set(trainval_id_type_list)) np.random.shuffle(id_type_list) trainval_id_type_list.extend(id_type_list[:n_other_samples]) print(len(trainval_id_type_list), len(to_set(trainval_id_type_list))) params = { 'seed': seed, 'xy_provider': image_class_labels_provider, 'network': get_densenet, 'network_kwargs': { 'depth': 121, 'input_shape': (256, 256, 3),