def init(repo_dir, validate_mode, training): np.random.seed(0) common_params = dict(sampling_freq=fs, clip_duration=cd, frame_duration=512) if training: media_params = AudioParams(**common_params) set_name = 'tain' if validate_mode else 'full' data_dir = repo_dir else: media_params = AudioParams(**common_params) set_name = 'eval' if validate_mode else 'test' data_dir = repo_dir if validate_mode else repo_dir.replace('train', 'test') + '_new' data_dir += '/' return media_params, set_name, data_dir
from neon.initializers import Gaussian, GlorotUniform from neon.layers import Conv, Pooling, GeneralizedCost, Affine, DeepBiRNN, RecurrentMean from neon.optimizers import Adagrad from neon.transforms import Rectlin, Softmax, CrossEntropyMulti, Misclassification from neon.models import Model from neon.data import DataLoader, AudioParams from neon.callbacks.callbacks import Callbacks from util import create_index_files, display parser = NeonArgparser(__doc__) args = parser.parse_args() train_idx, valid_idx = create_index_files(args.data_dir) common_params = dict(sampling_freq=22050, clip_duration=16000, frame_duration=16) train_params = AudioParams(**common_params) valid_params = AudioParams(**common_params) common = dict(target_size=1, nclasses=10, repo_dir=args.data_dir) train = DataLoader(set_name='music-train', media_params=train_params, index_file=train_idx, shuffle=True, **common) valid = DataLoader(set_name='music-valid', media_params=valid_params, index_file=valid_idx, shuffle=False, **common) init = Gaussian(scale=0.01) layers = [Conv((2, 2, 4), init=init, activation=Rectlin(), strides=dict(str_h=2, str_w=4)), Pooling(2, strides=2), Conv((3, 3, 4), init=init, batch_norm=True, activation=Rectlin(), strides=dict(str_h=1, str_w=2)), DeepBiRNN(128, init=GlorotUniform(), batch_norm=True, activation=Rectlin(), reset_cells=True, depth=3), RecurrentMean(),
data_dir = args.data_dir out_dir = args.out_dir if not os.path.exists(out_dir): os.makedirs(out_dir) if data_dir[-1] != '/': data_dir += '/' subj = int(data_dir[-2]) assert subj in [1, 2, 3] indexer = Indexer() tain_idx, test_idx = indexer.run(data_dir, pattern, testing=args.test_mode) fs = 400 cd = 240000 * 1000 / fs common_params = dict(sampling_freq=fs, clip_duration=cd, frame_duration=512) tain_params = AudioParams(random_scale_percent=5.0, **common_params) test_params = AudioParams(**common_params) common = dict(target_size=1, nclasses=2) tain_set = 'full' if args.test_mode else 'tain' test_set = 'test' if args.test_mode else 'eval' test_dir = data_dir.replace('train', 'test') if args.test_mode else data_dir tain = DataLoader(set_name=tain_set, media_params=tain_params, index_file=tain_idx, repo_dir=data_dir, **common) test = DataLoader(set_name=test_set, media_params=test_params, index_file=test_idx, repo_dir=test_dir, **common) gauss = Gaussian(scale=0.01) glorot = GlorotUniform() tiny = dict(str_h=1, str_w=1) small = dict(str_h=1, str_w=2) big = dict(str_h=1, str_w=4)
parser = NeonArgparser(__doc__) args = parser.parse_args() args.data_dir = '/home/auto-114/PycharmProjects/neon_study_05/data' train_idx, val_idx, all_idx, test_idx, noise_idx = create_index_files( args.data_dir) args.epochs = 20 train_dir = os.path.join(args.data_dir, 'train') common_params = dict(sampling_freq=2000, clip_duration=1700, frame_duration=64, overlap_percent=50) train_params = AudioParams(noise_index_file=noise_idx, noise_dir=train_dir, **common_params) test_params = AudioParams(**common_params) common = dict(target_size=1, nclasses=2) # Validate... train = DataLoader(set_name='train', repo_dir=train_dir, media_params=train_params, index_file=train_idx, **common) test = DataLoader(set_name='val', repo_dir=train_dir, media_params=test_params, index_file=val_idx, **common)
for idx, filename in enumerate(files): fd = train_fd if idx < train_count else val_fd rel_path = os.path.join(os.path.basename(subdir), os.path.basename(filename)) fd.write(rel_path + ',' + str(label) + '\n') return train_idx, val_idx parser = NeonArgparser(__doc__) args = parser.parse_args() train_idx, val_idx = create_index_files(args.data_dir) common_params = dict(sampling_freq=22050, clip_duration=31000, frame_duration=16) train_params = AudioParams(random_scale_percent=5, **common_params) val_params = AudioParams(**common_params) common = dict(target_size=1, nclasses=10, repo_dir=args.data_dir) train = DataLoader(set_name='genres-train', media_params=train_params, index_file=train_idx, shuffle=True, **common) val = DataLoader(set_name='genres-val', media_params=val_params, index_file=val_idx, shuffle=False, **common) init = Gaussian(scale=0.01) layers = [ Conv((7, 7, 32),