aaron-xichen / pytorch-playground

Base pretrained models and datasets in pytorch (MNIST, SVHN, CIFAR10, CIFAR100, STL10, AlexNet, VGG16, VGG19, ResNet, Inception, SqueezeNet)
MIT License
2.62k stars 612 forks source link

svhn with batch_size = 1 #13

Closed sungyoon-lee closed 4 years ago

sungyoon-lee commented 6 years ago
import torch
from torch.autograd import Variable
from utee import selector
model_raw, ds_fetcher, is_imagenet = selector.select('svhn')
ds_val = ds_fetcher(batch_size=1, train=False, val=True)
for idx, (data, target) in enumerate(ds_val):
    data =  Variable(torch.FloatTensor(data)).cuda()
    output = model_raw(data)
    print(output.data.cpu().numpy())
    print(np.argmax(output.data.cpu().numpy()))
    print(target)

@aaron-xichen I've tried this and the result was unsatisfactory ( it works fine for batch_size>1) The followings are some results.

[[ 0.9298288 0.17785856 0.9966059 -1.3422316 -0.8245616 -1.9604906 -2.7374938 -1.6454206 -1.8076795 -2.0542176 ]] 2

4 [torch.LongTensor of size 1]

[[ 2.7919588 0.49071673 -0.00736207 -2.0971794 -0.84618115 -2.2232437 -1.6899112 -0.6246177 -2.9164875 -3.1203978 ]] 0

1 [torch.LongTensor of size 1]

[[ 2.9281554 -0.13904905 -1.3504897 -1.6061695 -2.2028518 -2.205429 -2.3030198 -1.7889079 -1.5594031 0.7322607 ]] 0

0 [torch.LongTensor of size 1]

[[ 1.6236477 -0.04049116 0.71252775 -1.5312613 -0.80628943 -1.1643314 -2.7663736 -1.779502 -1.764115 -2.6679206 ]] 0

9 [torch.LongTensor of size 1]

[[ 3.0169618 0.21566215 -0.64600635 -1.0604596 -2.5471652 -1.1154206 -3.167088 -1.7345388 -1.3325107 -1.2756087 ]] 0

5 [torch.LongTensor of size 1]

[[ 3.2620628 -1.1842312 -0.96141076 -0.72385985 -1.6753035 -0.01387847 -2.4336383 -2.6121674 -1.9076045 -2.078348 ]] 0

0 [torch.LongTensor of size 1]

[[ 3.155985 -0.25471076 -0.89448035 -0.77628857 -1.8204114 -3.392403 -2.5437825 -1.4555902 -1.0910527 -1.2623619 ]] 0

8 [torch.LongTensor of size 1]

[[ 2.4467583 -0.54981095 0.5102633 -1.2237269 -1.3451892 -2.4299471 -1.9993426 -1.2083414 0.04519886 -3.9493613 ]] 0

0 [torch.LongTensor of size 1]

[[ 3.0312405 0.00999061 -0.29210752 -1.6024964 -0.9401326 -1.0996346 -3.5482233 -0.65459347 -2.6797504 -2.7330062 ]] 0

0 [torch.LongTensor of size 1]

[[ 2.0508249 0.30808404 -0.6483562 -0.70096767 -1.3534812 -2.8651845 -2.9115884 -1.5140661 -0.58172 -1.2605368 ]] 0

7 [torch.LongTensor of size 1]

[[ 3.8504605 -1.934954 -0.1308189 -0.9230577 -1.7006387 -0.39881432 -3.0715973 -2.162218 -2.7872374 -1.0572728 ]] 0

2 [torch.LongTensor of size 1]

[[ 1.6195637 -2.3086352 -0.5728828 -0.86222374 0.429138 -0.6708926 -2.159588 -0.8012347 -2.1825366 -2.1155794 ]] 0

5 [torch.LongTensor of size 1]

[[ 1.5269842 -0.49805775 -0.44842458 -0.5922584 -2.7392595 -2.0895157 -1.2918607 -1.4767127 -1.2701623 -1.2878953 ]] 0

4 [torch.LongTensor of size 1]

[[ 1.8214152 -0.39846689 1.6661385 -0.7838743 -1.4924386 -1.0132811 -3.5224247 -1.7450149 -2.133103 -2.6991496 ]] 0

0 [torch.LongTensor of size 1]

[[ 3.3604963 -0.46506485 1.5834907 -3.2729144 -2.377539 -0.6647626 -3.1641421 -1.3123829 -1.9374268 -1.6866504 ]] 0

3 [torch.LongTensor of size 1]

[[ 1.7083087 1.0932902 -0.30605602 -0.89276785 -1.7285749 -1.6361132 -3.7625558 -1.6642044 -0.58260405 -2.6053936 ]] 0

3 [torch.LongTensor of size 1]

[[ 1.1230315 1.3429782 -0.7060108 -2.4044423 -1.0088397 -1.5541636 -0.94885933 -1.4849153 -1.6033367 -2.5828755 ]] 1

0 [torch.LongTensor of size 1]

[[ 1.9963155 -0.16534638 0.46809655 -1.1736008 -2.8804379 -0.66240954 -2.0466976 -2.3514454 -0.99034363 -1.7793173 ]] 0

5 [torch.LongTensor of size 1]

[[ 2.2264035 0.34485406 0.73350465 -1.9414191 -1.8649687 -3.4865122 -1.9899611 -1.1546313 -0.43400905 -2.308626 ]] 0

2 [torch.LongTensor of size 1]

alldbi commented 5 years ago

Hi, it seems the model is in 'train' mode. Just add ''model_raw.eval()" before the main for-loop.

aaron-xichen commented 4 years ago

It seems fixed, please check