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

Sketch-RNN ln7 Error: could not cast hparam #27

Open
antocreo opened this issue Mar 8, 2018 · 4 comments
Open

Sketch-RNN ln7 Error: could not cast hparam #27

antocreo opened this issue Mar 8, 2018 · 4 comments

Comments

@antocreo
Copy link

antocreo commented Mar 8, 2018

I am trying to run the Sketch-RN demo Sketch_RNN.ipynb.
when I run:
[train_set, valid_set, test_set, hps_model, eval_hps_model, sample_hps_model] = load_env(data_dir, model_dir)

this is the error I get:

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-7-c072ee5d7a3f> in <module>()
----> 1 [train_set, valid_set, test_set, hps_model, eval_hps_model, sample_hps_model] = load_env(data_dir, model_dir)

/Users/libphd/anaconda3/envs/magenta/lib/python2.7/site-packages/magenta/models/sketch_rnn/sketch_rnn_train.pyc in load_env(data_dir, model_dir)
     73   model_params = sketch_rnn_model.get_default_hparams()
     74   with tf.gfile.Open(os.path.join(model_dir, 'model_config.json'), 'r') as f:
---> 75     model_params.parse_json(f.read())
     76   return load_dataset(data_dir, model_params, inference_mode=True)
     77 

/Users/libphd/anaconda3/envs/magenta/lib/python2.7/site-packages/tensorflow/contrib/training/python/training/hparam.pyc in parse_json(self, values_json)
    585     """
    586     values_map = json.loads(values_json)
--> 587     return self.override_from_dict(values_map)
    588 
    589   def values(self):

/Users/libphd/anaconda3/envs/magenta/lib/python2.7/site-packages/tensorflow/contrib/training/python/training/hparam.pyc in override_from_dict(self, values_dict)
    537     """
    538     for name, value in values_dict.items():
--> 539       self.set_hparam(name, value)
    540     return self
    541 

/Users/libphd/anaconda3/envs/magenta/lib/python2.7/site-packages/tensorflow/contrib/training/python/training/hparam.pyc in set_hparam(self, name, value)
    499         raise ValueError(
    500             'Must pass a list for multi-valued parameter: %s.' % name)
--> 501       setattr(self, name, _cast_to_type_if_compatible(name, param_type, value))
    502 
    503   def parse(self, values):

/Users/libphd/anaconda3/envs/magenta/lib/python2.7/site-packages/tensorflow/contrib/training/python/training/hparam.pyc in _cast_to_type_if_compatible(name, param_type, value)
    173   # Avoid converting a number or string type to a boolean or vice versa.
    174   if issubclass(param_type, bool) != isinstance(value, bool):
--> 175     raise ValueError(fail_msg)
    176 
    177   # Avoid converting float to an integer (the reverse is fine).

ValueError: Could not cast hparam 'conditional' of type '<type 'bool'>' from value 1

Can't figure out the problem though...

@antocreo
Copy link
Author

antocreo commented Mar 8, 2018

seems the problem is with TF 1.6
I've installed TF 1.2.1 and it works well...

@ShusenTang
Copy link

this problem will appear since TF 1.5.
the reason is tf can't recognise the 0/1 as the bool type da in the model's json file such as "site-packages/magenta/models/aaron_sheep/layer_norm/model_config.json".
If you don't want to install old version tensorflow, you should change all ''0/1'' into ''false/true" if the paramter type is bool.
for example, the changed model_config.json file should like this:
image

@antocreo
Copy link
Author

@ShusenTang thanks for replying. I am using 1.2.1 at the moment and it works alright. I'll definitely do what you suggested if I switch to TF>1.5 :) cheers

@hardmaru
Copy link
Contributor

Hi @ShusenTang

Thanks for the suggestion. When TF was in the 1.2 days the casting was limited so I used 0/1 but your suggestion works well for current TF versions (including 1.8)

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

3 participants