예제 #1
0
    new_scores = scores.get_scores(net, refrigerator_test_set, 1,
                                   params.REFRIGERATOR_WINDOW_SIZE, std, mean)
    if scores.compare_scores(best_scores, new_scores) > 0:
        best_model.load_state_dict(net.state_dict())
        best_scores = new_scores
        torch.save(best_model, 'models/refrigerator_trained_model.pt')
        print('Best trained model')
    print('-------------------------------------------\n\n')
print('Finished Training')
torch.save(best_model, 'models/refrigerator_trained_model.pt')
net.eval()
last_scores = scores.get_scores(net, refrigerator_test_set, 1,
                                params.REFRIGERATOR_WINDOW_SIZE, std, mean)
dataiter = iter(refrigerator_testloader)
for i in range(len(refrigerator_testloader)):
    aggregate, labels = dataiter.next()
    label = labels.mean(dim=1).float()
    inputs = aggregate
    inputs = inputs.view(-1, 1, params.REFRIGERATOR_WINDOW_SIZE)
    if torch.cuda.is_available():
        inputs, labels = inputs.cuda(), labels.cuda()
    inputs = Variable(inputs.float())
    outputs = net(inputs)
    #print('Outputs:', outputs)
    for i in range(len(inputs)):
        data.show_output(aggregate=aggregate[i],
                         individual=labels[i],
                         output=outputs.data[i][0],
                         label=label[i],
                         window_size=params.REFRIGERATOR_WINDOW_SIZE)
예제 #2
0
    torchvision.transforms.Compose([Normalize(mean=mean, sd=std)]))
print('Size of test set: ', len(test_set))
# del training_set
net = ConvDishNILM()
try:
    net = torch.load('models/dishwasher_lucky_shot_house1.pt')
except FileNotFoundError:
    print('There is no pretrained model')

if torch.cuda.is_available():
    net = net.cuda()
print('Testing.')
print("Trained network's results: ")
net_scores = train.test_network(net, test_set, params.DISHWASHER_WINDOW_SIZE,
                                std, mean)
for i in range(len(test_set)):
    aggregate, labels = test_set[i]
    label = labels.mean()
    inputs = aggregate
    inputs = inputs.view(-1, 1, params.DISHWASHER_WINDOW_SIZE)
    if torch.cuda.is_available():
        inputs, labels = inputs.cuda(), labels.cuda()
    inputs = Variable(inputs.float())
    outputs = net(inputs)
    #print('Outputs:', outputs)
    data.show_output(aggregate=aggregate,
                     individual=labels,
                     output=outputs.data[0][0],
                     label=label,
                     window_size=params.DISHWASHER_WINDOW_SIZE)