hyperas icon indicating copy to clipboard operation
hyperas copied to clipboard

NotJSONError: Notebook does not appear to be JSON

Open yylonly opened this issue 7 years ago • 1 comments

When I use hyperas in Google Colab, I also get the error about


JSONDecodeError Traceback (most recent call last) /usr/local/lib/python3.6/dist-packages/nbformat/reader.py in parse_json(s, **kwargs) 13 try: ---> 14 nb_dict = json.loads(s, **kwargs) 15 except ValueError:

/usr/lib/python3.6/json/init.py in loads(s, encoding, cls, object_hook, parse_float, parse_int, parse_constant, object_pairs_hook, **kw) 353 parse_constant is None and object_pairs_hook is None and not kw): --> 354 return _default_decoder.decode(s) 355 if cls is None:

/usr/lib/python3.6/json/decoder.py in decode(self, s, _w) 338 """ --> 339 obj, end = self.raw_decode(s, idx=_w(s, 0).end()) 340 end = _w(s, end).end()

/usr/lib/python3.6/json/decoder.py in raw_decode(self, s, idx) 354 try: --> 355 obj, end = self.scan_once(s, idx) 356 except StopIteration as err:

JSONDecodeError: Unterminated string starting at: line 1 column 19940 (char 19939)

During handling of the above exception, another exception occurred:

NotJSONError Traceback (most recent call last) in () ----> 1 best_run, best_model = optim.minimize(model=ServeNet, data=data, algo=tpe.suggest, max_evals=5, trials=Trials(), rseed = seed, verbose=1, notebook_name='2ServeNet-2D-CNN-1-BI-LTSM-FC(Hyperas)') 2 3 print("Evalutation of best performing model:") 4 print(best_model.evalµºuate(X_test, Y_test)) 5 print("Best performing model chosen hyper-parameters:")

/usr/local/lib/python3.6/dist-packages/hyperas/optim.py in minimize(model, data, algo, max_evals, trials, functions, rseed, notebook_name, verbose, eval_space, return_space) 65 full_model_string=None, 66 notebook_name=notebook_name, ---> 67 verbose=verbose) 68 69 best_model = None

/usr/local/lib/python3.6/dist-packages/hyperas/optim.py in base_minimizer(model, data, functions, algo, max_evals, trials, rseed, full_model_string, notebook_name, verbose, stack) 94 model_str = full_model_string 95 else: ---> 96 model_str = get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack) 97 temp_file = './temp_model.py' 98 write_temp_files(model_str, temp_file)

/usr/local/lib/python3.6/dist-packages/hyperas/optim.py in get_hyperopt_model_string(model, data, functions, notebook_name, verbose, stack) 171 notebook_path = os.getcwd() + "/{}.ipynb".format(notebook_name) 172 with open(notebook_path, 'r') as f: --> 173 notebook = nbformat.reads(f.read(), nbformat.NO_CONVERT) 174 exporter = PythonExporter() 175 source, _ = exporter.from_notebook_node(notebook)

/usr/local/lib/python3.6/dist-packages/nbformat/init.py in reads(s, as_version, **kwargs) 72 The notebook that was read. 73 """ ---> 74 nb = reader.reads(s, **kwargs) 75 if as_version is not NO_CONVERT: 76 nb = convert(nb, as_version)

/usr/local/lib/python3.6/dist-packages/nbformat/reader.py in reads(s, **kwargs) 56 from . import versions, NBFormatError 57 ---> 58 nb_dict = parse_json(s, **kwargs) 59 (major, minor) = get_version(nb_dict) 60 if major in versions:

/usr/local/lib/python3.6/dist-packages/nbformat/reader.py in parse_json(s, **kwargs) 15 except ValueError: 16 # Limit the error message to 80 characters. Display whatever JSON will fit. ---> 17 raise NotJSONError(("Notebook does not appear to be JSON: %r" % s)[:77] + "...") 18 return nb_dict 19

NotJSONError: Notebook does not appear to be JSON: '{"nbformat":4,"nbformat_minor":0,"metad...

I need clear the output serval times, save notebook, then run again. The error will be disappear. But when I change some thing, run again, error will be there again.

I really wanna to use hyperas, but this is really a annoying...

yylonly avatar May 15 '18 15:05 yylonly

@yylonly sorry, I don't really know colab. This might be one of the cases in which you're simply better off using plain hyperopt + keras (not hyperas).

maxpumperla avatar May 15 '18 15:05 maxpumperla