net.to(device) print(net) softmax = nn.Softmax() criterion = nn.CrossEntropyLoss() optimizer = optim.SGD(net.parameters(), lr=LR, momentum=0.1) loss_list = [] train_acc_list = [] test_acc_list = [] pred_temp = [] true_temp = [] for epoch in range(EPOCH): net.train() running_loss = 0 total = train_size correct = 0 for step, images_labels in enumerate(train_loader): inputs, labels = images_labels inputs, labels = inputs.type( torch.FloatTensor).to(device), labels.type( torch.LongTensor).to(device) outputs = net(inputs) loss = criterion(outputs, labels) optimizer.zero_grad()
npimg = img.numpy() plt.imshow(np.transpose(npimg, (1, 2, 0))) plt.show() dataiter = iter(train_loader) images, labels = dataiter.next() imshow(torchvision.utils.make_grid(images)) print(' '.join('%5s' % classes[labels[j]] for j in range(4))) #=============Defining Training Parameters and type of Device device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu") model = Net(out_fea=len(classes)) model = model.train() model = model.to(device) criterion = nn.CrossEntropyLoss() optimizer = optim.SGD(model.parameters(), lr=0.001, momentum=0.9) step = 0 loss_train = [] loss_val = [] min_loss = 100 patience = 5 training_loss_store = [] validation_loss_store = [] writer = SummaryWriter('writer')