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

Maximum recursion level reached on input_process #5

Open
ideznaby opened this issue Nov 29, 2019 · 6 comments
Open

Maximum recursion level reached on input_process #5

ideznaby opened this issue Nov 29, 2019 · 6 comments

Comments

@ideznaby
Copy link

I am getting this error when I run input_process.py on physionet data, the error is happening on this line:
rec = json.dumps(rec)
do you have any solution for this?
Thanks

@Ubikas
Copy link

Ubikas commented Dec 11, 2019

Hi @ideznaby ,
I've been experimenting with BRITS model recently. In my opinion data format output is incorrect in input_process.py. I've changed parse_rec to

def parse_rec(values, masks, evals, eval_masks, dir_):
    deltas = parse_delta(masks, dir_)
    ts_list = []
    for r in range(values.shape[0]):
        rec = {}
        rec['values'] = np.nan_to_num(values[r]).tolist()
        rec['masks'] = masks[r].astype('int32').tolist()
        # imputation ground-truth
        rec['evals'] = np.nan_to_num(evals[r]).tolist()
        rec['eval_masks'] = eval_masks[r].astype('int32').tolist()
        rec['deltas'] = deltas[r].tolist()
        ts_list.append(rec)

    return ts_list

@ideznaby
Copy link
Author

Hi @Ubikas thank you for your answer, I tried this but I am still getting the same error, were you able to run the code on Physionet data?

Thanks

@Ubikas
Copy link

Ubikas commented Dec 19, 2019

Hi @ideznaby ,

as far as I remember I was getting the same error with physionet data, but I adopted algorithm to my dataset and it has 19 attributes instead of 35. In my opinion to use json is not the best idea, I'd rather use numpy array with strict ts type order like [sample, ts_type, ts_length, attribute]. So in this case would be [2000,5,49,35]. Unfortunately I didn't have time to code it and as json format worked fine for me I left it as it was.

@CavaJ
Copy link

CavaJ commented Apr 12, 2020

Instead of using usjon, just use python's original json API as follows in data_loader.py and input_process.py files:

# import ujson as json
import json

dumps() and loads() functions are the same. In input_process.py, define your own JSON encoder and dump rec as follows:

class NpEncoder(json.JSONEncoder):
    def default(self, obj):
        if isinstance(obj, np.integer):
            return int(obj)
        elif isinstance(obj, np.floating):
            return float(obj)
        elif isinstance(obj, np.ndarray):
            return obj.tolist()
        else:
            return super(NpEncoder, self).default(obj)
rec = json.dumps(rec,  cls=NpEncoder)

This effectively mitigated Maximum recursion level reached error in my code.

@TanmDL
Copy link

TanmDL commented Oct 30, 2020

cls=NpEncoder

Thank you for your suggestions. It solved the problem of maximum recursion level issues. Btw have you got exact paper claimed results?

@CavaJ
Copy link

CavaJ commented Jan 11, 2021

No, because PyTorch itself is non-deterministic. Please check: https://pytorch.org/docs/stable/notes/randomness.html

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

4 participants