Git Product home page Git Product logo

Comments (14)

mailcorahul avatar mailcorahul commented on August 16, 2024

The expression "mask>=0.1" returns a tensor of size (1,N), hence the error. Squeeze out the 0th dimension to make it work.
Replace that line with the following line:
of_masked = torch.cat([of_masked[i][(mask>=0.1).squeeze(0)].unsqueeze(0) for i in range(of_masked.size(0))])

from deep-learning.

mailcorahul avatar mailcorahul commented on August 16, 2024

There was another issue i came across in the function "remap_hist", the following line:
idx = (cum_ref.unsqueeze(1) - rng.unsqueeze(2) < 0).sum(2).long()

It throws an error due to data type mismatch. Typecast tensor 'rng' into a float tensor.
Add the following before the above line:
rng = rng.type(torch.cuda.FloatTensor);

from deep-learning.

changchethu avatar changchethu commented on August 16, 2024

@mailcorahul I am getting the following error,Can you please help me with it

/usr/local/lib/python3.6/dist-packages/torch/nn/_reduction.py:43: UserWarning: size_average and reduce args will be deprecated, please use reduction='sum' instead.
warnings.warn(warning.format(ret))

RuntimeError Traceback (most recent call last)
in ()
1 n_iter=0
----> 2 while n_iter <= max_iter: optimizer.step(partial(step,final_loss))

4 frames
in remap_hist(x, hist_ref)
13 ratio = ratio.squeeze().clamp(0,1)
14 new_x = ymin + (ratio + idx.float()) * step
---> 15 new_x[:,-1] = ymax
16 _, remap = sort_idx.sort()
17 new_x = select_idx(new_x,idx)

RuntimeError: expand(torch.cuda.FloatTensor{[64, 1]}, size=[64]): the number of sizes provided (1) must be greater or equal to the number of dimensions in the tensor (2)

from deep-learning.

mailcorahul avatar mailcorahul commented on August 16, 2024

This looks like the tensor on which expand is called has a shape of (64, 1), but trying to expand it to size (64), hence the error. From the code you posted I am not able to find out which tensor variable it is, but you can try calling .squeeze() on that tensor(before expand). It should solve it.

from deep-learning.

changchethu avatar changchethu commented on August 16, 2024

@mailcorahul im getting error when i try to call the below function

def remap_hist(x,hist_ref):
ch, n = x.size()
sorted_x, sort_idx = x.data.sort(1)
ymin, ymax = x.data.min(1)[0].unsqueeze(1), x.data.max(1)[0].unsqueeze(1)
hist = hist_ref * n/hist_ref.sum(1).unsqueeze(1)#Normalization between the different lengths of masks.
cum_ref = hist.cumsum(1)
cum_prev = torch.cat([torch.zeros(ch,1).cuda(), cum_ref[:,:-1]],1)
step = (ymax-ymin)/n_bins
rng = torch.arange(1,n+1).unsqueeze(0).cuda()
rng = rng.type(torch.cuda.FloatTensor)
idx = (cum_ref.unsqueeze(1) - rng.unsqueeze(2) < 0).sum(2).long()
ratio = (rng - select_idx(cum_prev,idx)) / (1e-8 + select_idx(hist,idx))
ratio = ratio.squeeze().clamp(0,1)
new_x = ymin + (ratio + idx.float()) * step
new_x[:,-1] = ymax
_, remap = sort_idx.sort()
new_x = select_idx(new_x,idx)
return new_x

from deep-learning.

disharameshh avatar disharameshh commented on August 16, 2024

@mailcorahul Hey even I got the same error as @changchethu has faced.Is there any possiblity that u could provide the solution asap..Please..

from deep-learning.

mailcorahul avatar mailcorahul commented on August 16, 2024

@disharameshh this error is related to tensor shape, please see if my above comment helps.

from deep-learning.

disharameshh avatar disharameshh commented on August 16, 2024

@mailcorahul I went through your above comment......but still I couldn't figure out the piece of code causing the error.....can you be more specific please....can you please tell what part of the code to be changed

from deep-learning.

mailcorahul avatar mailcorahul commented on August 16, 2024

can you post me the complete exception traceback? i need to know which code statement is throwing error.

from deep-learning.

disharameshh avatar disharameshh commented on August 16, 2024

@mailcorahul
/usr/local/lib/python3.6/dist-packages/torch/nn/_reduction.py:43: UserWarning: size_average and reduce args will be deprecated, please use reduction='sum' instead.
warnings.warn(warning.format(ret))
RuntimeError Traceback (most recent call last)
in ()
1 n_iter=0
----> 2 while n_iter <= max_iter: optimizer.step(partial(step,final_loss))

4 frames
in remap_hist(x, hist_ref)
13 ratio = ratio.squeeze().clamp(0,1)
14 new_x = ymin + (ratio + idx.float()) * step
---> 15 new_x[:,-1] = ymax
16 _, remap = sort_idx.sort()
17 new_x = select_idx(new_x,idx)

RuntimeError: expand(torch.cuda.FloatTensor{[64, 1]}, size=[64]): the number of sizes provided (1) must be greater or equal to the number of dimensions in the tensor (2)

from deep-learning.

disharameshh avatar disharameshh commented on August 16, 2024

It's directing to this function

def remap_hist(x,hist_ref):
ch, n = x.size()
sorted_x, sort_idx = x.data.sort(1)
ymin, ymax = x.data.min(1)[0].unsqueeze(1), x.data.max(1)[0].unsqueeze(1)
hist = hist_ref * n/hist_ref.sum(1).unsqueeze(1)#Normalization between the different lengths of masks.
cum_ref = hist.cumsum(1)
cum_prev = torch.cat([torch.zeros(ch,1).cuda(), cum_ref[:,:-1]],1)
step = (ymax-ymin)/n_bins
rng = torch.arange(1,n+1).unsqueeze(0).cuda()
rng = rng.type(torch.cuda.FloatTensor)
idx = (cum_ref.unsqueeze(1) - rng.unsqueeze(2) < 0).sum(2).long()
ratio = (rng - select_idx(cum_prev,idx)) / (1e-8 + select_idx(hist,idx))
ratio = ratio.squeeze().clamp(0,1)
new_x = ymin + (ratio + idx.float()) * step
new_x[:,-1] = ymax
_, remap = sort_idx.sort()
new_x = select_idx(new_x,idx)
return new_x

from deep-learning.

disharameshh avatar disharameshh commented on August 16, 2024

Can anyone please help me with this issue

from deep-learning.

mailcorahul avatar mailcorahul commented on August 16, 2024

Can you print the shapes of new_x and ymax before the line "new_x[:,-1] = ymax"?
Post the shapes of both tensors here.

from deep-learning.

mailcorahul avatar mailcorahul commented on August 16, 2024

@disharameshh in remap_dist function, replace new_x[:,-1] = ymax withnew_x[:,-1] = ymax.squeeze()

from deep-learning.

Related Issues (6)

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.