def main(): device = torch.device('cpu') model = EfficientNet(1.0, 1.0) weights = torch.load('efficientnet_torch.pth', map_location=torch.device('cpu')) model.load_state_dict(weights) model.eval() config = CONFIG() optimizer = optim.SGD(model.parameters(), lr=LEARNING_RATE, momentum=config.momentum, weight_decay=config.weight_decay) frame_rate_calc = 1 freq = getTickFrequency() image_path = [] writing = 0 phoneWithHand = 0 others = 0 sleep = 0 image_path.append("./others/") image_path.append("./phoneWithHand/") image_path.append("./sleep/") image_path.append("./writing/") for j in range(0, 4): sumsum = 0 others = 0 phoneWithHand = 0 sleep = 0 writing = 0 for i in range(0, 100): image = Image.open(image_path[j] + str(i) + '.jpg') trans = torchvision.transforms.ToTensor() image = trans(image) data = image.unsqueeze(0) t1 = getTickCount() scores = model(data) t2 = getTickCount() time1 = (t2 - t1) / freq frame_rate_calc = 1 / time1 sumsum += frame_rate_calc pred = scores.data.max(1)[1] sumsum /= 100 print('others: ', end='') print(others) print('phoneWithHand: ', end='') print(phoneWithHand) print('writing: ', end='') print(writing) print('sleep: ', end='') print(sleep) print('Average FPS: ', end='') print(sumsum)
pred = scores.data.max(1)[1] test_correct += pred.eq(target.data).cpu().sum() print("Predicted {} out of {} correctly".format(test_correct, total_examples)) return 100.0 * test_correct / (float(total_examples)) if __name__ == '__main__': torch.cuda.device(0) model = EfficientNet(1.0, 1.0) config = CONFIG() model = model.cuda() avg_loss = list() best_accuracy = 0.0 optimizer = optim.SGD(model.parameters(), lr=LEARNING_RATE, momentum=config.momentum, weight_decay=config.weight_decay) train_acc, val_acc = list(), list() for i in range(1, EPOCHS + 1): train_acc.append(train(i)) val_acc.append(val()) save_model(model, i) print(train_acc) print(val_acc)