def trans_mode(mode='normal'): global criterion global train_set global test_set if mode == 'one-hot': label_file = basic_dir + 'one-hot-label.csv' train_set = MusicDataThree(data_file, label_file, start=train_start, total=train_end) test_set = MusicDataThree(data_file, label_file, start=test_start, total=test_end) criterion = nn.CrossEntropyLoss()
set_record_file('record-modeltest.txt') print('Test of deep convolutional network') data_dir = basic_dir + 'raw-data-v5/' data_file = basic_dir + 'music-data-v5.csv' label_file = basic_dir + 'labels-v5.csv' # net_name = 'shallownet' net_name = '0-justreducelr' # net_name = 'simplecnn-freq' model_name = net_name + '.pt' net = Justreducelr_0() # deep convolutional network net.load_state_dict(torch.load(model_name)) net.eval() # test_set = MusicDataThree(data_file=data_file, label_file=label_file, start=2560, total=3219) test_set = MusicDataThree(data_file=data_file, label_file=label_file, start=2560, total=3219) test(net, net_name=net_name, dataset=test_set) print('Test of shallow convolutional network') data_file = basic_dir + 'music-data-v5.csv' label_file = basic_dir + 'labels-v5.csv' net = ShallowNet() net_name = 'shallownet' model_name = net_name + '.pt' net.load_state_dict(torch.load(model_name)) net.eval() test_set = MusicDataThree(data_file=data_file, label_file=label_file, start=2560, total=3219)
from train_test import train, test from train_test import Ininorm_5_6 as Net from MusicDataset import MusicDataThree, IniNorm # time.sleep(3600*4) print('start') model_path = '6-5+ininorm.pt' print('start') model_path = '6-5+ininorm.pt' tsfm = IniNorm() train_set = MusicDataThree(transform=tsfm) test_set = MusicDataThree(transform=tsfm) net = Net() net = train(net, model_path=model_path, dataset=train_set) test(net, dataset=test_set)
from train_test import train, test, set_record_file from train_test import Coon_0_2 as Net from MusicDataset import MusicDataThree, ExpNorm # time.sleep(3600*4) print('start') set_record_file('record-expoon.txt') net_name = '2-0+expcoon' model_path = net_name + '.pt' tsfm = ExpNorm() train_set = MusicDataThree(transform=tsfm, start=0, total=1) test_set = MusicDataThree(transform=tsfm, start=0, total=1) net = Net() net = train(net, model_path=model_path, dataset=train_set) test(net, net_name, dataset=test_set)
return self.classifier(x).view(-1, 18) def weights_init(m): if isinstance(m, nn.Conv2d): nn.init.normal_(m.weight.data, mean=0, std=10) nn.init.normal_(m.bias.data, mean=0, std=10) net = Justreducelr_0() net.apply(weights_init) # criterion = nn.CrossEntropyLoss() # criterion = nn.BCELoss() # ##################################################### here train_set = MusicDataThree(data_file, label_file, start=train_start, total=train_end) test_set = MusicDataThree(data_file, label_file, start=test_start, total=test_end) criterion = nn.BCEWithLogitsLoss() def set_record_file(file_name): global record_file record_file = file_name def trans_mode(mode='normal'): global criterion
second = F.relu(self.pool(self.conv3(second))) second = F.relu(self.pool(self.conv4(second))) # for i in range(3): # second = F.relu(self.conv5(second)) # second = self.conv6(second) second = second.view(batch_size, -1) y = self.sigmoid(first + second) return y net = Coon_0_2() # criterion = nn.BCELoss() # ##################################################### here train_set = MusicDataThree(data_file, label_file, start=train_start, total=train_end, mode='one-hot') test_set = MusicDataThree(data_file, label_file, start=test_start, total=test_end, mode='one-hot') # criterion = nn.MSELoss() criterion = nn.CrossEntropyLoss() def train(net=net, criterion=criterion, model_path='tmp.pt', dataset=train_set,