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

Example code not working #1

Open
guytenn opened this issue Jun 13, 2021 · 1 comment
Open

Example code not working #1

guytenn opened this issue Jun 13, 2021 · 1 comment

Comments

@guytenn
Copy link

guytenn commented Jun 13, 2021

import medkit as mk
synthetic_dataset = mk.batch_generate(
                                   domain = "Ward",
                                   environment = "CRN",
                                   policy = "LSTM",
                                   size = 1000,
                                   test_size = 200,
                                   max_length = 10,
                                   scale = True)

Gives an error:

Traceback (most recent call last):
  File "<stdin>", line 8, in <module>
  File "/home/gtennenholtz/medkit-learn/medkit/api.py", line 58, in batch_generate
    env = env_dict[environment](dom)
  File "/home/gtennenholtz/medkit-learn/medkit/environments/CounterfactualRNN.py", line 118, in __init__
    self.model = CRN_env(domain)
  File "/home/gtennenholtz/medkit-learn/medkit/environments/CounterfactualRNN.py", line 15, in __init__
    self.lstm_layers = self.hyper["lstm_layers"]
KeyError: 'lstm_layers'

Also:
env = mk.live_simulate(domain="ICU", environment="SVAE")

Gives an error:

Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/home/gtennenholtz/medkit-learn/medkit/api.py", line 214, in live_simulate
    env = env_dict[environment](dom)
  File "/home/gtennenholtz/medkit-learn/medkit/environments/SequentialVAE.py", line 188, in __init__
    self.load_pretrained()
  File "/home/gtennenholtz/medkit-learn/medkit/bases/base_env.py", line 30, in load_pretrained
    self.model.load_state_dict(torch.load(path))
  File "/home/gtennenholtz/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 1224, in load_state_dict
    self.__class__.__name__, "\n\t".join(error_msgs)))
RuntimeError: Error(s) in loading state_dict for SVAE_env:
        Missing key(s) in state_dict: "lstm.weight_ih_l0", "lstm.bias_ih_l0", "lstm.weight_hh_l0", "lstm.bias_hh_l0", "lstm.weight_ih_l1", "lstm.bias_ih_l1", "lstm.weight_hh_l1", "lstm.bias_hh_l1", "lstm.layers.0.cell.ih.weight", "lstm.layers.0.cell.ih.bias", "lstm.layers.0.cell.hh.weight", "lstm.layers.0.cell.hh.bias", "lstm.layers.1.cell.ih.weight", "lstm.layers.1.cell.ih.bias", "lstm.layers.1.cell.hh.weight", "lstm.layers.1.cell.hh.bias".
        Unexpected key(s) in state_dict: "lstm.ih.weight", "lstm.ih.bias", "lstm.hh.weight", "lstm.hh.bias".
        size mismatch for encoder.linear1.weight: copying a param with shape torch.Size([128, 24]) from checkpoint, the shape in current model is torch.Size([128, 37]).
        size mismatch for decoder.series_cont_mean.weight: copying a param with shape torch.Size([23, 128]) from checkpoint, the shape in current model is torch.Size([37, 128]).
        size mismatch for decoder.series_cont_mean.bias: copying a param with shape torch.Size([23]) from checkpoint, the shape in current model is torch.Size([37]).
        size mismatch for decoder.series_cont_lstd.weight: copying a param with shape torch.Size([23, 128]) from checkpoint, the shape in current model is torch.Size([37, 128]).
        size mismatch for decoder.series_cont_lstd.bias: copying a param with shape torch.Size([23]) from checkpoint, the shape in current model is torch.Size([37]).
        size mismatch for decoder.series_bin.weight: copying a param with shape torch.Size([1, 128]) from checkpoint, the shape in current model is torch.Size([0, 128]).
        size mismatch for decoder.series_bin.bias: copying a param with shape torch.Size([1]) from checkpoint, the shape in current model is torch.Size([0]).
@lucacorbucci
Copy link

I don't have these two errors, I'm using a virtual env and I installed the dependencies with:
pip install -r requirements.txt
and then Medkit with:
pip install -e .

Anyway, when I try to execute:
observation, reward, info, done = env.step(actions_test)

I have the following error:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/lucacorbucci/Downloads/tmp/Medkit/medkit-learn/medkit/scenario.py", line 85, in step observation, reward, info, done = self.env.step(action) File "/Users/lucacorbucci/Downloads/tmp/Medkit/medkit-learn/medkit/environments/SequentialVAE.py", line 197, in step action = action.reshape((1, 1)) ValueError: cannot reshape array of size 2000 into shape (1,1)

XanderJC pushed a commit that referenced this issue Oct 27, 2021
* add req dev

* linter fixes

* bandit issues

* cleanup

* update pip

* debug

* debug

* debug
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

2 participants