nengo / nengo-dl

Deep learning integration for Nengo
https://www.nengo.ai/nengo-dl
Other
88 stars 22 forks source link

More informative error message for input data with wrong shape #154

Open arvoelke opened 4 years ago

arvoelke commented 4 years ago

Context: https://github.com/nengo/nengo-examples/issues/26

Taking an introductory example (such as docs/examples/from-nengo.ipynb) and modifying:

with nengo_dl.Simulator(net) as sim:
    sim.run(1.0, data={inpt: np.reshape(np.linspace(-1, 1, 1000), 
                                        (1, 1000, 1))})

to:

with nengo_dl.Simulator(net) as sim:
    sim.run(1.0, data={inpt: np.linspace(-1, 1, 1000)})

results in a stack trace and error message that is difficult to understand:

~/anaconda3/envs/*/lib/python3.7/site-packages/nengo_dl/simulator.py in _call_keras(self, func_type, x, y, n_steps, stateful, **kwargs)
    971         # maybe move it into a callback where the generated data is available?
    972 
--> 973         x = self._generate_inputs(x, n_steps=n_steps)
    974         self._check_data(
    975             x,

~/anaconda3/envs/*/lib/python3.7/site-packages/nengo_dl/simulator.py in _generate_inputs(self, data, n_steps)
   1814             data_batch = data_steps = None
   1815         else:
-> 1816             data_batch, data_steps = next(iter(data.values())).shape[:2]
   1817 
   1818         batch_size = self.minibatch_size if data_batch is None else data_batch

ValueError: not enough values to unpack (expected 2, got 1)

This kind of issue seems likely for people who are new to libraries like TensorFlow and are unfamiliar with array shaping. A more helpful error message could be provided.