Exemplo n.º 1
0
def analyse_sound(path):
    x, sr = librosa.load(path)
    td = librosa.get_duration(x)
    print("Time duration of audio: ", td)
    x = np.reshape(x, [1, -1, 1, 1])
    print("Shape of input waveform: ", x.shape)

    # Setup visible device
    os.environ["CUDA_VISIBLE_DEVICES"] = args.cuda_device

    # Load pre-trained model
    G_name = './models/sound8.npy'
    param_G = np.load(G_name, encoding='latin1').item()

    # Init. Session
    sess_config = tf.ConfigProto()
    sess_config.allow_soft_placement = True
    sess_config.gpu_options.allow_growth = True

    with tf.Session(config=sess_config) as session:
        # Build model
        model = Model(session, config=local_config, param_G=param_G)
        init = tf.global_variables_initializer()
        session.run(init)

        model.load()

        features = ef.extract_feat(model, x, local_config)
        print("Shape of feature: ", features.shape)
Exemplo n.º 2
0
def main():

    args = parse_args()
    local_config['phase'] = args.phase

    # Setup visible device
    os.environ["CUDA_VISIBLE_DEVICES"] = args.cuda_device

    # Make path
    if not os.path.exists(args.outpath):
        os.mkdir(args.outpath)

    # Load pre-trained model
    param_G = np.load(local_config['param_g_dir'], encoding='latin1').item() \
            if args.phase in ['finetune', 'extract'] \
            else None

    # Init. Session
    sess_config = tf.ConfigProto()
    sess_config.allow_soft_placement = True
    sess_config.gpu_options.allow_growth = True

    with tf.Session(config=sess_config) as session:
        # Build model
        model = Model(session, config=local_config, param_G=param_G)

        if args.phase in ['train', 'finetune']:
            # Training phase
            model.train()
        elif args.phase == 'extract':
            # import when we need
            from extract_feat import extract_feat

            # Feature extractor
            #sound_sample = np.reshape(np.load('./data/demo.npy', encoding='latin1'), [local_config['batch_size'], -1, 1, 1])

            import librosa
            audio_path = './data/demo.mp3'
            sound_sample, _ = load_audio(audio_path)
            sound_sample = preprocess(sound_sample, config=local_config)

            output = extract_feat(model, sound_sample, args)
Exemplo n.º 3
0
def extract_feat_from_link(model, audio_path, config):
    sound_sample = load_from_link(audio_path)

    features = extract_feat(model, sound_sample)
    
    return features
Exemplo n.º 4
0
# coding: utf-8

import pandas as pd
from extract_feat import extract_feat

dataset = pd.read_csv("extract_dataset/extract_feat_dataset_15.csv")
feat = dataset[dataset.time >= "t5"][[
    "user_id", "item_id", "item_category", "label"
]]
feat = feat.drop_duplicates()
feat = extract_feat(feat, dataset, '2014-12-15 00', '2014-12-16 00',
                    '2014-12-14 00', '2014-12-12 00', '2014-12-09 00',
                    '2014-11-18 00')

feat.to_csv("feature/feature1.csv", index=False)
Exemplo n.º 5
0
# coding: utf-8

import pandas as pd
from extract_feat import extract_feat

dataset = pd.read_csv("extract_dataset/extract_feat_dataset_18.csv")
feat = dataset[dataset.time >= "t5"][["user_id", "item_id", "item_category"]]
feat = feat.drop_duplicates()
feat = extract_feat(feat, dataset, '2014-12-18 00',
                                    '2014-12-19 00',
                                    '2014-12-17 00',
                                    '2014-12-15 00',
                                    '2014-12-12 00',
                                    '2014-11-18 00')

feat.to_csv("feature/feature4.csv",index=False)





Exemplo n.º 6
0
# coding: utf-8

import pandas as pd
from extract_feat import extract_feat

dataset = pd.read_csv("extract_dataset/extract_feat_dataset_17.csv")
feat = dataset[dataset.time >= "t5"][[
    "user_id", "item_id", "item_category", "label"
]]
feat = feat.drop_duplicates()
feat = extract_feat(feat, dataset, '2014-12-17 00', '2014-12-18 00',
                    '2014-12-16 00', '2014-12-14 00', '2014-12-11 00',
                    '2014-11-18 00')

feat.to_csv("feature/feature3.csv", index=False)