ethanrosenthal / spacecutter Goto Github PK
View Code? Open in Web Editor NEWOrdinal regression models in PyTorch
Home Page: https://www.ethanrosenthal.com/2018/12/06/spacecutter-ordinal-regression/
License: MIT License
Ordinal regression models in PyTorch
Home Page: https://www.ethanrosenthal.com/2018/12/06/spacecutter-ordinal-regression/
License: MIT License
it's strange for me, why you use deepcopy in there? I have tested the model can work without deepcopy, is there any reason for use it?
line 77: self.predictor = deepcopy(predictor)
RuntimeError: The size of tensor a (5) must match the size of tensor b (6) at non-singleton dimension 1
I'm working on a six classification task[0, 1, 2, 3, 4, 5].I found that cutpoints = num_ class - 1 in the code。 But in this way, the dimensions of cutpoints and X are not equal. I've seen your example, but I still don't know how to solve it.
thank you!
Dear Torch friends
Perhaps I am missing something, but I think the docs of "reduction_" function is not correct. Shall it be?
def _reduction(loss: torch.Tensor, reduction: str) -> torch.Tensor:
"""
Reduce loss
Parameters
----------
loss : torch.Tensor, [batch_size, 1]
Batch losses.
reduction : str
Method for reducing the loss. Options include 'elementwise_mean',
'none', and 'sum'.
Returns
-------
loss : torch.Tensor
Reduced loss.
"""
if reduction == 'elementwise_mean':
return loss.mean()
elif reduction == 'none':
return loss
elif reduction == 'sum':
return loss.sum()
else:
raise ValueError(f'{reduction} is not a valid reduction')
?
Hello,
Firstly, thanks a lot for making this useful repo public.
My question is regarding the conversion of an OrdinalLogisticModel() wrapped model to its tensorRT equivalent.
I am unable to do it and I think it has something to do with the LogisticCumulativeLink at the end of the wrapper class.
Have you personally tried converting the model to tensorrt for faster inference?
If yes, would you be kind enough to let me know.
Thank you
spacecutter/spacecutter/models.py
Lines 81 to 82 in 37a6f73
solution: instead of accepting X
, accept *args
and **kwargs
happy to submit a PR to fix this
Hi,
I am trying to train an OrdinalLogit model and have stripped down the model to this:
pred_dosages_tensor = torch.tensor(pred_dosages)
true_dosages_tensor = torch.tensor(true_dosages, dtype=torch.long)
predictor = torch.nn.Sequential()
num_classes = len(np.unique(true_dosages))
scaling = NeuralNet(
module=OrdinalLogisticModel,
module__predictor=predictor,
module__num_classes=num_classes,
criterion=CumulativeLinkLoss,
train_split=None,
callbacks=[
('ascension', AscensionCallback()),
],
)
scaling.fit(true_dosages_tensor, pred_dosages_tensor)
However, when I try to run this code, I get the following error:
File "/home/unix/ssadhuka/.conda/envs/shuvomenv/lib/python3.7/site-packages/spacecutter/losses.py", line 68, in cumulative_link_loss
likelihoods = torch.clamp(torch.gather(y_pred, 1, y_true), eps, 1 - eps)
RuntimeError: gather_out_cpu(): Expected dtype int64 for index
EDIT: Resolved
Fix:
In losses.py, change
likelihoods = torch.clamp(torch.gather(y_pred, 1, y_true), eps, 1 - eps) to likelihoods = torch.clamp(torch.gather(y_pred, 1, y_true.to(torch.int64)), eps, 1 - eps)
Actually I dont want to use skorch (more flexible), so how should i change my training code? i dont know how to add callback to my train code ..... Thanks very much !!!
Hi could u help understand the below peace of code.
Why do we subtract the elements in linkmat ,then concatinating them .
Isnt just cutpoints-X is sufficient ?
sigmoids=cutpoints-X
link_mat = sigmoids[:, 1:] - sigmoids[:, :-1]
link_mat = torch.cat((
sigmoids[:, [0]],
link_mat,
(1 - sigmoids[:, [-1]])
),
dim=1
Hi! Thanks for your work, I think it's useful and inspiring, however, Skorch may support torch 0.4.1 no more. When I try to run 'from Skorch.callbacks import Callback, ProgressBar', I met 'ImportWarning: Skorch depends on a newer version of PyTorch (at least 1.1.0, not 0.4.1). Visit https://pytorch.org for installation details', may be spacecutter should upgrade torch version? Thanks a lot!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.