Hi i try to test my model and this error pop up i use the similar method when i train the data and there is no error can anyone check what went wrong?
this is when i train
def train(dataloader,net):
net = load_net(net, 'gpu')
net = net.cuda()
epoch = 2
criterion = nn.CrossEntropyLoss()
optimizer = optim.SGD(net.parameters(), lr=0.001, momentum=0.9)
train_loss = list()
#set_trace()
for i, data in enumerate(dataloader):
inps, labs = data
inps, labs = inps.cuda(args['device']), labs.cuda(args['device'])
inps = Variable(inps).cuda(args['device'])
labs = Variable(labs).cuda(args['device'])
optimizer.zero_grad()
outs = net(inps.permute(0, 3, 1, 2).float())
soft_outs = F.softmax(outs, dim=1)
prds = soft_outs.data.max(1)[1]
loss = criterion(outs, labs)
loss.backward()
optimizer.step()
prds = prds.cpu().numpy()
inps_np = inps.detach().cpu().numpy()
labs_np = labs.detach().cpu().numpy()
train_loss.append(loss.data.item
())
print('[epoch %d], [iter %d / %d], [train loss %.5f]' % (epoch, i + 1, len(dataloader), np.asarray(train_loss).mean()))
x=train(dataloadertrain,net='mobiface')
This is for test
def test(test_loader, net):
correct = 0
total = 0
since_test = time.time()
# Iterating over batches.
for i, data in enumerate(test_loader):
# Obtaining images, labels and paths for batch.
inps, labs = data
inps, labs = inps.cuda(args['device']), labs.cuda(args['device'])
#inps.squeeze_(0) # create a mini-batch as expected by the model
#labs.squeeze_(0)
inps = Variable(inps).cuda(args['device'])
labs = Variable(labs).cuda(args['device'])
# # Forwarding.
outs = net(inps.permute(0, 3, 1, 2).float())
for j in range(len(outs['out'])):
diff = outs['out'][j].argmax(0) - labs[j]
diff = diff.int().cpu().numpy()
unique, counts = np.unique(diff,return_counts=True)
print(unique, counts)
total += np.sum(counts)
correct += np.sum(counts[unique == 0])
print(total,correct)
time_elapsed = time.time() - since_test ##Edit
print('Training complete in {:.0f}m {:.0f}s'.format(time_elapsed // 60, time_elapsed % 60)) # Edit
print(f"accuracy is {(correct/total)*100}%")
test(dataloadertest, x)
I found this method online and it look fine to another person but when i try to impliment it this error pop up
<ipython-input-142-ce0ef120179a> in <module>()
----> 1 test(dataloadertest, x)
<ipython-input-141-4000f8300d82> in test(test_loader, net)
16 labs = Variable(labs).cuda(args['device'])
17 # # Forwarding.
---> 18 outs = net(inps.permute(0, 3, 1, 2).float())
19
20 for j in range(len(outs['out'])):
TypeError: 'NoneType' object is not callable