コード例 #1
0
def predict_spec(model, path):
    temp_spec = os.path.join(result_dir, "temp.png")
    tools.make_spec(path, temp_spec)
    x_batch = np.ndarray((1, 3, model.insize, model.insize), dtype=np.float32)
    y_batch = np.zeros((1, ), dtype=np.int32)
    x_batch[0] = read_image(temp_spec)
    return get_result(x_batch, y_batch, model)[0]
コード例 #2
0
def predict_spec(model,path):
    temp_spec = os.path.join(result_dir,"temp.png")
    tools.make_spec(path,temp_spec)
    x_batch = np.ndarray((1,3,model.insize,model.insize), dtype=np.float32)
    y_batch = np.zeros((1,), dtype=np.int32)
    x_batch[0] = read_image(temp_spec)
    return get_result(x_batch,y_batch,model)[0]
コード例 #3
0
def make_train():
    #posi_tempo=[]
    print "start positive music feature extract"
    posi_mel=[]
    posi_chroma=[]
    posi_mfcc=[]
    hi_res=0
    #posi_tempo=[]
    #nega_tempo=[]
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        for i in tqdm(positive_sample):
            #tools.make_vec(os.path.join(posi_dir,i),0,(posi_mel,posi_mfcc,posi_chroma))
            try:
                mel,mfcc,chroma = tools.get_feature(os.path.join(posi_dir,i))
            
                mel=[(0,j) for j in mel]
                mfcc=[(0,j) for j in mfcc]
                chroma=[(0,j) for j in chroma]
            
                posi_mel+=mel
                posi_mfcc+=mfcc
                posi_chroma+=chroma
                tools.make_spec(os.path.join(posi_dir,i),os.path.join(data_dir,"posi_spectro",i[:-3]+"png"))
            except audioop.error:
                hi_res+=1
        p_dump(posi_mel,"posi_mel")
        p_dump(posi_mfcc,"posi_mfcc")
        p_dump(posi_chroma,"posi_chroma")
        
        del posi_mel
        del posi_mfcc
        del posi_chroma
        
        print "start negative music feature extract"
        nega_mel=[]
        nega_chroma=[]
        nega_mfcc=[]
    
        for i in tqdm(negative_sample):
        #tools.make_vec(os.path.join(nega_dir,i),0,(nega_mel,nega_mfcc,nega_chroma))
            try:
                mel,mfcc,chroma=tools.get_feature(os.path.join(nega_dir,i))
                mel=[(1,j) for j in mel]
                mfcc=[(1,j) for j in mfcc]
                chroma=[(1,j) for j in chroma]
                
                nega_mel+=mel
                nega_mfcc+=mfcc
                nega_chroma+=chroma
                tools.make_spec(os.path.join(nega_dir,i),os.path.join(data_dir,"nega_spectro",i[:-3]+"png"))
            except audioop.error:
                hi_res+=1

        p_dump(nega_mel,"nega_mel")
        p_dump(nega_mfcc,"nega_mfcc")
        p_dump(nega_chroma,"nega_chroma")
    if hi_res:
        print "{} files are not used.it may be 24bit.".format(hi_res)
コード例 #4
0
def make_train():
    #posi_tempo=[]
    print "start positive music feature extract"
    posi_mel = []
    posi_chroma = []
    posi_mfcc = []
    hi_res = 0
    #posi_tempo=[]
    #nega_tempo=[]
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        for i in tqdm(positive_sample):
            #tools.make_vec(os.path.join(posi_dir,i),0,(posi_mel,posi_mfcc,posi_chroma))
            try:
                mel, mfcc, chroma = tools.get_feature(os.path.join(
                    posi_dir, i))

                mel = [(0, j) for j in mel]
                mfcc = [(0, j) for j in mfcc]
                chroma = [(0, j) for j in chroma]

                posi_mel += mel
                posi_mfcc += mfcc
                posi_chroma += chroma
                tools.make_spec(
                    os.path.join(posi_dir, i),
                    os.path.join(data_dir, "posi_spectro", i[:-3] + "png"))
            except audioop.error:
                hi_res += 1
        p_dump(posi_mel, "posi_mel")
        p_dump(posi_mfcc, "posi_mfcc")
        p_dump(posi_chroma, "posi_chroma")

        del posi_mel
        del posi_mfcc
        del posi_chroma

        print "start negative music feature extract"
        nega_mel = []
        nega_chroma = []
        nega_mfcc = []

        for i in tqdm(negative_sample):
            #tools.make_vec(os.path.join(nega_dir,i),0,(nega_mel,nega_mfcc,nega_chroma))
            try:
                mel, mfcc, chroma = tools.get_feature(os.path.join(
                    nega_dir, i))
                mel = [(1, j) for j in mel]
                mfcc = [(1, j) for j in mfcc]
                chroma = [(1, j) for j in chroma]

                nega_mel += mel
                nega_mfcc += mfcc
                nega_chroma += chroma
                tools.make_spec(
                    os.path.join(nega_dir, i),
                    os.path.join(data_dir, "nega_spectro", i[:-3] + "png"))
            except audioop.error:
                hi_res += 1

        p_dump(nega_mel, "nega_mel")
        p_dump(nega_mfcc, "nega_mfcc")
        p_dump(nega_chroma, "nega_chroma")
    if hi_res:
        print "{} files are not used.it may be 24bit.".format(hi_res)