Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

len() of a 0-d tensor #4

Open
mbenami opened this issue Mar 25, 2019 · 10 comments
Open

len() of a 0-d tensor #4

mbenami opened this issue Mar 25, 2019 · 10 comments

Comments

@mbenami
Copy link

mbenami commented Mar 25, 2019

Hi, Thanks for releasing this code
I try to train the model on my dataset
but sometimes when I run the visualize notebook I get an error:

/home/ubuntu/DeLF-pytorch/helper/delf_helper.pyc in GetDelfFeatureFromSingleScale(x, model, scale, pca_mean, pca_vars, pca_matrix, pca_dims, rf, stride, padding, attn_thres, use_pca)
    283     # use attention score to select feature.
    284     indices = None
--> 285     while(indices is None or len(indices) == 0):
    286         indices = torch.gt(scaled_scores, attn_thres).nonzero().squeeze()
    287         attn_thres = attn_thres * 0.5   # use lower threshold if no indexes are found.

/usr/local/lib/python2.7/dist-packages/torch/tensor.pyc in __len__(self)
    368     def __len__(self):
    369         if self.dim() == 0:
--> 370             raise TypeError("len() of a 0-d tensor")
    371         return self.shape[0]

any idea why ?

@lyakaap
Copy link

lyakaap commented Apr 4, 2019

How about to change
while(indices is None or len(indices) == 0):
to
while(indices is None or indices.dim == 0):

I can fix this issue by this in pytorch==1.0.

@TianMingChen
Copy link

How about to change
while(indices is None or len(indices) == 0):
to
while(indices is None or indices.dim == 0):

I can fix this issue by this in pytorch==1.0.

hello,whan you train PCA,do you get this problem?
image

@TianMingChen
Copy link

Hi, Thanks for releasing this code
I try to train the model on my dataset
but sometimes when I run the visualize notebook I get an error:

/home/ubuntu/DeLF-pytorch/helper/delf_helper.pyc in GetDelfFeatureFromSingleScale(x, model, scale, pca_mean, pca_vars, pca_matrix, pca_dims, rf, stride, padding, attn_thres, use_pca)
    283     # use attention score to select feature.
    284     indices = None
--> 285     while(indices is None or len(indices) == 0):
    286         indices = torch.gt(scaled_scores, attn_thres).nonzero().squeeze()
    287         attn_thres = attn_thres * 0.5   # use lower threshold if no indexes are found.

/usr/local/lib/python2.7/dist-packages/torch/tensor.pyc in __len__(self)
    368     def __len__(self):
    369         if self.dim() == 0:
--> 370             raise TypeError("len() of a 0-d tensor")
    371         return self.shape[0]

any idea why ?
hello,when you train PCA,do you get this problem?

image

@xytjcxy
Copy link

xytjcxy commented May 18, 2019

Can you tell me the size of your gpu memory please?
My gpu memory is 8G. However, out of memory always happen...

@TianMingChen
Copy link

Can you tell me the size of your gpu memory please?
My gpu memory is 8G. However, out of memory always happen...

it is 12G,and you can reduce the number of picture in your dataset

@xytjcxy
Copy link

xytjcxy commented May 19, 2019

no no no , when I loaded the model , more than 5G memory is used. When the single picture is large than 10001000, it reports OOM! So I have to resize the image to 720720, but the result seems too bad~

@xytjcxy
Copy link

xytjcxy commented May 19, 2019

Can you tell me the size of your gpu memory please?
My gpu memory is 8G. However, out of memory always happen...

it is 12G,and you can reduce the number of picture in your dataset

If you are Chinese, can we talk on wechat ?

@TianMingChen
Copy link

no no no , when I loaded the model , more than 5G memory is used. When the single picture is large than 1000_1000, it reports OOM! So I have to resize the image to 720_720, but the result seems too bad~

I resize the image to 128*128,maybe it's ok.

@xytjcxy
Copy link

xytjcxy commented May 19, 2019

no no no , when I loaded the model , more than 5G memory is used. When the single picture is large than 1000_1000, it reports OOM! So I have to resize the image to 720_720, but the result seems too bad~

I resize the image to 128*128,maybe it's ok.

OK,I think I have found where I was wrong,if I have a good message,I will rely soon~

@zhangqizky
Copy link

add a try...except block or judge if order.dim()==0,if so, i = order.item(),
I fixed the problem thisway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants