vikasverma1077 / manifold_mixup

Code for reproducing Manifold Mixup results (ICML 2019)
483 stars 65 forks source link

Error running Semi-supervised Manifold mixup for Cifar10 #1

Closed gtcslance closed 6 years ago

gtcslance commented 6 years ago

Hi,

I run the Semi-supervised Manifold mixup for Cifar10 and the following error appears, I'm using python 2.7, torch 0.3.1 and torchvision 0.2.0

Traceback (most recent call last): File "main_mixup_hidden_ssl.py", line 357, in train(epoch) File "main_mixup_hidden_ssl.py", line 216, in train lam = lam.data.cpu().numpy().item() ValueError: can only convert an array of size 1 to a Python scalar

I saw Iam here is an array of size 2, not 1, so I used item(0) to replace item() in line 216, then a similar error appears

File "main_mixup_hidden_ssl.py", line 357, in train(epoch) File "main_mixup_hidden_ssl.py", line 241, in train mixedup_target = target_alam.expand_as(target_a) + target_b(1-lam.expand_as(target_b)) File "/home/wei.z/anaconda2/lib/python2.7/site-packages/torch/autograd/variable.py", line 433, in expand_as return self.expand(tensor.size()) RuntimeError: The expanded size of the tensor (10) must match the existing size (2) at non-singleton dimension 1. at /pytorch/torch/lib/THC/generic/THCTensor.c:340

alexmlamb commented 6 years ago

I don't know why this happened but lam should be a single scalar.

On Fri, Jul 13, 2018, 2:39 AM gtcslance notifications@github.com wrote:

Hi,

I run the Semi-supervised Manifold mixup for Cifar10 and the following error appears, I'm using python 2.7, torch 0.3.1 and torch 0.2.0

Traceback (most recent call last): File "main_mixup_hidden_ssl.py", line 357, in train(epoch) File "main_mixup_hidden_ssl.py", line 216, in train lam = lam.data.cpu().numpy().item() ValueError: can only convert an array of size 1 to a Python scalar

I saw Iam here is an array of size 2, not 1, so I used item(0) to replace item() in line 216, then a similar error appears

File "main_mixup_hidden_ssl.py", line 357, in train(epoch) File "main_mixup_hidden_ssl.py", line 241, in train mixedup_target = target_alam.expand_as(target_a) + target_b (1-lam.expand_as(target_b)) File "/home/wei.z/anaconda2/lib/python2.7/site-packages/torch/autograd/variable.py", line 433, in expand_as return self.expand(tensor.size()) RuntimeError: The expanded size of the tensor (10) must match the existing size (2) at non-singleton dimension 1. at /pytorch/torch/lib/THC/generic/THCTensor.c:340

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/vikasverma1077/manifold_mixup/issues/1, or mute the thread https://github.com/notifications/unsubscribe-auth/AFvbTFc9-RwXByPpueRovdd-1WMO4oNMks5uF4nTgaJpZM4VNbyz .

alexmlamb commented 6 years ago

What's the exact command that you're running and can you give the outputs?

I just got it to run with:

python == 2.7.13 numpy == 1.14.5 pytorch == 0.4.0 torchvision == 0.2.1

Perhaps the numpy version is the issue?

Before line 216, lam should look like: tensor([ 0.8576], device='cuda:0')

and after line 216 it should just be a float like:

0.857638716698

gtcslance commented 6 years ago

I figured out I'm having this error as I have 2 gpus, everything is fine now by adding the following line to main_mixup_hidden_ssl.py

os.environ["CUDA_VISIBLE_DEVICES"]="0"