havakv / havakv/pycox

Survival time predictions (with CoxPH) using medical images

Open
#64 5 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Python
Stars
995
Forks
203
PR merge metrics
No merged PRs in 30d

Description

Hello,

I'd like to build a model which takes images and predicts overall survival time as continuous. For that reason, I followed the model shown in this jupyter notebook [04_mnist_dataloaders_cnn.ipynb](https://nbviewer.jupyter.org/github/havakv/pycox/blob/master/examples/04_mnist_dataloaders_cnn.ipynb) by using CoxPH instead of LogisticHazards. However, I got 2 different errors. I am using databatchloader by the way.

When I tried with CoxPH and fit the model with:

`callbacks = [tt.cb.EarlyStopping()]
epochs = 100
verbose = True
log = model.fit_dataloader(dl_train, epochs, callbacks, verbose, val_dataloader=dl_val)`

Running this code : `net` is same with the sample notebook stated above.
`model = CoxPH(net, tt.optim.Adam(0.01))
surv = model.predict_surv_df(dl_test_x)` gave me this error:

`---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 surv = model.predict_surv_df(dl_test_x)

/usr/local/anaconda/lib/python3.6/site-packages/pycox/models/cox.py in predict_surv_df(self, input, max_duration, batch_size, verbose, baseline_hazards_, eval_, num_workers)
153 """
154 return np.exp(-self.predict_cumulative_hazards(input, max_duration, batch_size, verbose, baseline_hazards_,
--> 155 eval_, num_workers))
156
157 def predict_surv(self, input, max_duration=None, batch_size=8224, numpy=None, verbose=False,

/usr/local/anaconda/lib/python3.6/site-packages/pycox/models/cox.py in predict_cumulative_hazards(self, input, max_duration, batch_size, verbose, baseline_hazards_, eval_, num_workers)
123 if baseline_hazards_ is None:
124 if not hasattr(self, 'baseline_hazards_'):
--> 125 raise ValueError('Need to compute baseline_hazards_. E.g run `model.compute_baseline_hazards()`')
126 baseline_hazards_ = self.baseline_hazards_
127 assert baseline_hazards_.index.is_monotonic_increasing,\

ValueError: Need to compute baseline_hazards_. E.g run `model.compute_baseline_hazards()` `

Hence, once I tried to run `model.compute_baseline_hazards()` it gave me this error:

`---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
in ()
----> 1 _ = model.compute_baseline_hazards()

/usr/local/anaconda/lib/python3.6/site-packages/pycox/models/cox.py in compute_baseline_hazards(self, input, target, max_duration, sample, batch_size, set_hazards, eval_, num_workers)
82 if (input is None) and (target is None):
83 if not hasattr(self, 'training_data'):
---> 84 raise ValueError("Need to give a 'input' and 'target' to this function.")
85 input, target = self.training_data
86 df = self.target_to_df(target)#.sort_values(self.duration_col)

ValueError: Need to give a 'input' and 'target' to this function.`

Since the training data is shape of (torch.Size([16, 1, 128, 128]), (torch.Size([16]), torch.Size([16]))), I didn't understand how to give the input and target to the `model.compute_baseline_hazards()`. I basically fed the image as input and tuples of time and event values as target then it throw another error saying that to much to unpack.

Could you please help me to understand how can I solve this issue?

I really appreciate any help.
Regards,
Asli Y.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with examples/04_mnist_dataloaders_cnn.ipynb and the CoxPH methods predict_surv_df and compute_baseline_hazards shown in the traceback. Reproduce the fit_dataloader call with the image batch and time/event targets, then verify that baseline hazards can be computed and survival predictions complete without either ValueError.

Written by the indexing model from the issue text.

Assessment

Tech stack
jupyter-notebook, python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.