Giter Site home page Giter Site logo

Comments (6)

ildoonet avatar ildoonet commented on August 23, 2024 1

@NomiMalik0207 You need to debug line by line, especially I suggest you to look tensor sizes. In my experience, when the accuracy is above 1.0, it was (mostly) due to the wrong processed tensors. I always check the tensor sizes for this reason.

Also, this is not related to cutmix technically, but I will open this for now to help you. Let me know the result after you debug.

from cutmix.

ildoonet avatar ildoonet commented on August 23, 2024

you can change predicted vector to one hot [64, 7]. or you should check the prediction accuracy only on validation set which would have target size [64]. If codes are provided, it will be much easier to answer. Thanks.

from cutmix.

NomiMalik0207 avatar NomiMalik0207 commented on August 23, 2024

i solved this error by matching the size but now in while testing model, the accuracy of test set start from 1200 or above out of 100. the code for test set is

for batch_idx, (inputs, targets) in enumerate(Testloader):                                                                                                     
        bs, ncrops, c, h, w = np.shape(inputs)                                                                                                                           
        inputs = inputs.view(-1, c, h, w)                                                                                                                                
        if use_cuda:                                                                                                                                                     
            inputs, targets = inputs.cuda(), targets.cuda()                                                                                                              
        inputs, targets = Variable(inputs, volatile=True), Variable(targets)                                                                                             
        outputs = net(inputs)                                                                                                                                                                                                                                                                                                    
        outputs_avg = outputs.view(bs, ncrops, -1).mean(1)                                                                                                                                                                                                                               
        loss = criterion(outputs_avg, targets)                                                                                                                           
        Test_loss += loss.item()                                                                                                                                   
        _, predicted = torch.max(outputs_avg.data, 1)                                                                                                                    
        predicted= predicted.unsqueeze(1) // for matchin size                                                                                                                               
        total += targets.size(0)                                                                                                                                         
        correct += predicted.eq(targets.long().data).cpu().sum()// target should be long tensor                                                                                                                                                                                                                               
        utils.progress_bar(batch_idx, len(Testloader), 'Loss: %.3f | Acc: %.3f%% (%d/%d)'                                                                          
                           % (Test_loss / (batch_idx + 1), 100. * correct / total, correct, total))

from cutmix.

ildoonet avatar ildoonet commented on August 23, 2024

@NomiMalik0207 Don't use CutMix wrapper for Testloader. Seems to me, predicted= predicted.unsqueeze(1) is not the solution for you.

  1. Remove CutMix wrapper for Testloader, not Trainloader.
  2. no .unsqueeze(1). Use torch.argmax to get predicted class indices and count the number of correctness with targets.

I hope this will help you.

from cutmix.

NomiMalik0207 avatar NomiMalik0207 commented on August 23, 2024

HERE is the results of your suggested modification

  1. i already didnot use CutMix wrapper for testloader, So i removed predicted= predicted.unsqueeze(1) from testing solved the problem.
  2. when i use torch.agrmax with trainloader, the train accuracy started from more then 100%. but its going normal with unsqueeze.
    Seeing farward to your helpful suggestions .
    Thank you mate

from cutmix.

NomiMalik0207 avatar NomiMalik0207 commented on August 23, 2024

Thank you for your time and help.
Here i showed the training loop for my network. The size of tensors are given as comment at the end of line.
for batch_idx, (inputs, targets) in enumerate(trainloader):
import pdb
if use_cuda:
inputs, targets = inputs.cuda(), targets.cuda()
inputs, targets = Variable(inputs, volatile=True), Variable(targets)
optimizer.zero_grad()
outputs = net(inputs)
loss = criterion(outputs, targets)
train_loss += loss.item()
pdb.set_trace()
_, predicted = torch.max(outputs.data, 1)// predicted.size()=torch.Size([64])
total += targets.size(0)
predicted = torch.argmax(predicted)//predicted.size()=torch.Size([])
// here when i print the value of predcted, it shows predicted= tensor(38)
#predicted= predicted.unsqueeze(1)// if i use this line, this shows //predicted.size()=torch.Size([64, 1])
correct += predicted.eq(targets.long().data).cpu().sum()// targets.size()=torch.Size([64, 7])
loss.backward()
optimizer.step()

from cutmix.

Related Issues (8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.