Exemplo n.º 1
0
#Model loading
output_channels = 32 #mapas características de salida de la capa 1 de la CNN
model = CNN_Fusion(output_channels, output_channels)
#model.load_state_dict(torch.load("E:\\INVESTIGACIÓN\\Proyectos\\Boundaries Detection\\Trained_models_MLS_SSLM\\Trained_models_Gauss0,1_lr0,001_4cnn_drop\\saved_model_" + epochs + "epochs.bin"))
model.load_state_dict(torch.load("E:\\INVESTIGACIÓN\\Proyectos\\Boundaries Detection\\Trained models\\MLS_SSLM_MFCCs_cos_Chromas_cos_2pool3\\saved_model_" + epochs + "epochs.bin"))
model.eval()

batch_size = 1
transform = transforms.Compose([transforms.ToPILImage(), transforms.ToTensor()])

im_path_mel = "E:\\INVESTIGACIÓN\\Proyectos\\Boundaries Detection\\Inputs\\TEST\\np MLS\\"
im_path_L_MFCCs = "E:\\INVESTIGACIÓN\\Proyectos\\Boundaries Detection\\Inputs\\TEST\\" + matrix + "\\"
im_path_L_MFCCs2 = "E:\\INVESTIGACIÓN\\Proyectos\\Boundaries Detection\\Inputs\\TEST\\" + matrix2 + "\\"
labels_path = "E:\\UNIVERSIDAD\\MÁSTER INGENIERÍA INDUSTRIAL\\TFM\\Database\\salami-data-public\\annotations\\"

mels_dataset = SSMDataset(im_path_mel, labels_path, transforms=[padding_MLS, normalize_image, borders])
mels_trainloader = DataLoader(mels_dataset, batch_size = batch_size, num_workers=0)

sslms_dataset = SSMDataset(im_path_L_MFCCs, labels_path, transforms=[padding_SSLM, normalize_image, borders])
sslms_trainloader = DataLoader(sslms_dataset, batch_size = batch_size, num_workers=0)

sslms_dataset2 = SSMDataset(im_path_L_MFCCs2, labels_path, transforms=[padding_SSLM, normalize_image, borders])
sslms_trainloader2 = DataLoader(sslms_dataset2, batch_size = batch_size, num_workers=0)
"""
for k in range(len(sslm_trainloader)):
    if sslms_dataset[k][0] == 6762:
        break
"""
hop_length = 1024
sr = 44100
window_size = 2024
model.load_state_dict(
    torch.load(
        "E:\\INVESTIGACIÓN\\Proyectos\\Boundaries Detection\\Trained models\\SSLM_MFCCs_euclidean_2pool3\\saved_model_"
        + epochs + "epochs.bin"))
model.eval()

batch_size = 1

transform = transforms.Compose(
    [transforms.ToPILImage(), transforms.ToTensor()])

im_path_sslm = "E:\\INVESTIGACIÓN\\Proyectos\\Boundaries Detection\\Inputs\\TEST\\" + matrix + "\\"
labels_path = "E:\\UNIVERSIDAD\\MÁSTER INGENIERÍA INDUSTRIAL\\TFM\\Database\\salami-data-public\\annotations\\"

sslm_dataset = SSMDataset(im_path_sslm,
                          labels_path,
                          transforms=[padding_SSLM, normalize_image, borders])
sslm_trainloader = DataLoader(sslm_dataset,
                              batch_size=batch_size,
                              num_workers=0)

hop_length = 1024
sr = 44100
window_size = 2024
pooling_factor = 6
lamda = 6 / pooling_factor
padding_factor = 50
lamda = round(lamda * sr / hop_length)
n_songs = len(sslm_trainloader)
delta = 0.205
beta = 1
        "/media/carlos/FILES/INVESTIGACION/Proyectos/Boundaries Detection/Trained models/MLS/saved_model_"
        + epochs + "epochs.bin",
        map_location=torch.device('cpu')))
model.eval()

batch_size = 1

transform = transforms.Compose(
    [transforms.ToPILImage(), transforms.ToTensor()])

im_path_mel = "/media/carlos/FILES/INVESTIGACION/Proyectos/Boundaries Detection/Inputs/TEST/np MLS/"
#im_path_L_MFCCs = "/media/carlos/FILES/INVESTIGACION/Proyectos/Boundaries Detection/Inputs/TEST/np SSLM from Chromas cosine 2pool3/"
labels_path = "/media/carlos/FILES/INVESTIGACION/Datasets/MusicStructure/SALAMI/annotations/"

mels_dataset = SSMDataset(im_path_mel,
                          labels_path,
                          transforms=[padding_MLS, normalize_image, borders])
mels_trainloader = DataLoader(mels_dataset,
                              batch_size=batch_size,
                              num_workers=0)

#sslms_dataset = SSMDataset(im_path_L_MFCCs, labels_path, transforms=[padding_SSLM, normalize_image, borders])
#sslms_trainloader = DataLoader(sslms_dataset, batch_size = batch_size, num_workers=0)

hop_length = 1024
sr = 44100
window_size = 2024
pooling_factor = 6
padding_factor = 50  #samples
lamda = 6 / pooling_factor
lamda = round(lamda * sr / hop_length)
Exemplo n.º 4
0
from model_CNN_MLS import CNN_Fusion
import numpy as np
from scipy import signal
import mir_eval

device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
start_time = time.time()

batch_size = 1
labels_path = "/media/carlos/FILES/SALAMI/annotations/"
im_path_mls_train = "/media/carlos/FILES/INVESTIGACIÓN/Proyectos/Boundaries Detection/Inputs/TRAIN/np MLS/"
im_path_mls_val = "media/carlos/FILES/INVESTIGACIÓN/Proyectos/Boundaries Detection/Inputs/VALIDATION/np MLS/"

#Datasets initialization
dataset_mls_train = SSMDataset(
    im_path_mls_train,
    labels_path,
    transforms=[padding_MLS, normalize_image, borders])
dataset_mls_val = SSMDataset(
    im_path_mls_val,
    labels_path,
    transforms=[padding_MLS, normalize_image, borders])

#creating train and test
#1006 songs as dataset, so 65% for training (first 650 songs),
#15% for validation (next 150 songs) and
#20% for test (last 206 songs)

trainloader_mls = DataLoader(dataset_mls_train,
                             batch_size=batch_size,
                             num_workers=0,
                             shuffle=False)
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
start_time = time.time()

batch_size = 1
labels_path = "H:\\INVESTIGACION\\Datasets\\MusicStructure\\SALAMI\\annotations\\"
im_path_mel_near_train = "H:\\INVESTIGACION\\Proyectos\\Boundaries Detection\\Inputs\\TRAIN\\np MLS\\"
im_path_L_MFCCs_near_train = "H:\\INVESTIGACION\\Proyectos\\Boundaries Detection\\Inputs\\TRAIN\\np SSLM from MFCCs euclidean 2pool3\\"
im_path_L_MFCCs_near_train2 = "H:\\INVESTIGACION\\Proyectos\\Boundaries Detection\\Inputs\\TRAIN\\np SSLM from MFCCs cosine 2pool3\\"

im_path_mel_near_val = "H:\\INVESTIGACION\\Proyectos\\Boundaries Detection\\Inputs\\VALIDATION\\np MLS\\"
im_path_L_MFCCs_near_val = "H:\\INVESTIGACION\\Proyectos\\Boundaries Detection\\Inputs\\VALIDATION\\np SSLM from MFCCs euclidean 2pool3\\"
im_path_L_MFCCs_near_val2 = "H:\\INVESTIGACION\\Proyectos\\Boundaries Detection\\Inputs\\VALIDATION\\np SSLM from MFCCs cosine 2pool3\\"

#Datasets initialization
dataset_mels_train = SSMDataset(
    im_path_mel_near_train,
    labels_path,
    transforms=[padding_MLS, normalize_image, borders])
dataset_sslms_train = SSMDataset(
    im_path_L_MFCCs_near_train,
    labels_path,
    transforms=[padding_SSLM, normalize_image, borders])
dataset_sslms_train2 = SSMDataset(
    im_path_L_MFCCs_near_train2,
    labels_path,
    transforms=[padding_SSLM, normalize_image, borders])

dataset_mels_val = SSMDataset(
    im_path_mel_near_val,
    labels_path,
    transforms=[padding_MLS, normalize_image, borders])
dataset_sslms_val = SSMDataset(
from model_CNN_SSLM import CNN_Fusion
import numpy as np
from scipy import signal
import mir_eval

device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
start_time = time.time()

batch_size = 1
labels_path = "/media/carlos/FILES/SALAMI/annotations/"
im_path_L_MFCCs_near_train = "/media/carlos/FILES/INVESTIGACIÓN/Proyectos/Boundaries Detection/Inputs/TRAIN/np SSLM from MFCCs euclidean 2pool3/"
im_path_L_MFCCs_near_val = "/media/carlos/FILES/INVESTIGACIÓN/Proyectos/Boundaries Detection/Inputs/VALIDATION/np SSLM from MFCCs euclidean 2pool3/"

#Datasets initialization
dataset_sslms_train = SSMDataset(
    im_path_L_MFCCs_near_train,
    labels_path,
    transforms=[normalize_image, padding_SSLM, borders])
dataset_sslms_val = SSMDataset(
    im_path_L_MFCCs_near_val,
    labels_path,
    transforms=[normalize_image, padding_SSLM, borders])

#creating train and test
#1006 songs as dataset, so 65% for training (first 650 songs),
#15% for validation (next 150 songs) and
#20% for test (last 206 songs)

trainloader_sslms = DataLoader(dataset_sslms_train,
                               batch_size=batch_size,
                               num_workers=0,
                               shuffle=False)