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

Minibatch size must evenly divide validation split #121

Closed
arvoelke opened this issue Dec 20, 2019 · 1 comment · Fixed by #139
Closed

Minibatch size must evenly divide validation split #121

arvoelke opened this issue Dec 20, 2019 · 1 comment · Fixed by #139

Comments

@arvoelke
Copy link
Contributor

arvoelke commented Dec 20, 2019

Steps to reproduce:

  • Open docs/examples/spiking-mnist.ipynb
  • Change sim.fit(...) to sim.fit(..., validation_split=0.55)
  • Set do_training = True and then run notebook
Train on 26999 samples, validate on 33001 samples
Epoch 1/200
26800/26999 [============================>.] - ETA: 0s - loss: 0.2636 - probe_loss: 0.2636
---------------------------------------------------------------------------
InvalidArgumentError                      Traceback (most recent call last)
<ipython-input-10-c2eaadcf9727> in <module>
      6         loss={out_p: tf.losses.SparseCategoricalCrossentropy(from_logits=True)}
      7     )
----> 8     sim.fit({inp: train_images}, {out_p: train_labels}, epochs=200, validation_split=0.55)
      9 
     10     # save the parameters to file

~/anaconda3/envs/nengo-dl/lib/python3.7/site-packages/nengo/utils/magic.py in __call__(self, *args, **kwargs)
    179                 return self.wrapper(wrapped, instance, args, kwargs)
    180             else:
--> 181                 return self.wrapper(self.__wrapped__, self.instance, args, kwargs)
    182         else:
    183             instance = getattr(self.__wrapped__, "__self__", None)

~/git/nengo-dl/nengo_dl/simulator.py in require_open(wrapped, instance, args, kwargs)
     64         )
     65 
---> 66     return wrapped(*args, **kwargs)
     67 
     68 

~/git/nengo-dl/nengo_dl/simulator.py in fit(self, x, y, n_steps, stateful, **kwargs)
    847 
    848         return self._call_keras(
--> 849             "fit", x=x, y=y, n_steps=n_steps, stateful=stateful, **kwargs
    850         )
    851 

~/anaconda3/envs/nengo-dl/lib/python3.7/site-packages/nengo/utils/magic.py in __call__(self, *args, **kwargs)
    179                 return self.wrapper(wrapped, instance, args, kwargs)
    180             else:
--> 181                 return self.wrapper(self.__wrapped__, self.instance, args, kwargs)
    182         else:
    183             instance = getattr(self.__wrapped__, "__self__", None)

~/git/nengo-dl/nengo_dl/simulator.py in with_self(wrapped, instance, args, kwargs)
     48         instance.tensor_graph.device
     49     ):
---> 50         output = wrapped(*args, **kwargs)
     51     tf.keras.backend.set_floatx(keras_dtype)
     52 

~/git/nengo-dl/nengo_dl/simulator.py in _call_keras(self, func_type, x, y, n_steps, stateful, **kwargs)
    995             func_args = dict(x=x, y=y, **kwargs)
    996 
--> 997         outputs = getattr(self.keras_model, func_type)(**func_args)
    998 
    999         # update n_steps/time

~/anaconda3/envs/nengo-dl/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training.py in fit(self, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, max_queue_size, workers, use_multiprocessing, **kwargs)
    726         max_queue_size=max_queue_size,
    727         workers=workers,
--> 728         use_multiprocessing=use_multiprocessing)
    729 
    730   def evaluate(self,

~/anaconda3/envs/nengo-dl/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_arrays.py in fit(self, model, x, y, batch_size, epochs, verbose, callbacks, validation_split, validation_data, shuffle, class_weight, sample_weight, initial_epoch, steps_per_epoch, validation_steps, validation_freq, **kwargs)
    672         validation_steps=validation_steps,
    673         validation_freq=validation_freq,
--> 674         steps_name='steps_per_epoch')
    675 
    676   def evaluate(self,

~/anaconda3/envs/nengo-dl/lib/python3.7/site-packages/tensorflow_core/python/keras/engine/training_arrays.py in model_iteration(model, inputs, targets, sample_weights, batch_size, epochs, verbose, callbacks, val_inputs, val_targets, val_sample_weights, shuffle, initial_epoch, steps_per_epoch, validation_steps, validation_freq, mode, validation_in_fit, prepared_feed_values_from_dataset, steps_name, **kwargs)
    391 
    392         # Get outputs.
--> 393         batch_outs = f(ins_batch)
    394         if not isinstance(batch_outs, list):
    395           batch_outs = [batch_outs]

~/anaconda3/envs/nengo-dl/lib/python3.7/site-packages/tensorflow_core/python/keras/backend.py in __call__(self, inputs)
   3578 
   3579     fetched = self._callable_fn(*array_vals,
-> 3580                                 run_metadata=self.run_metadata)
   3581     self._call_fetch_callbacks(fetched[-len(self._fetches):])
   3582     output_structure = nest.pack_sequence_as(

~/anaconda3/envs/nengo-dl/lib/python3.7/site-packages/tensorflow_core/python/client/session.py in __call__(self, *args, **kwargs)
   1470         ret = tf_session.TF_SessionRunCallable(self._session._session,
   1471                                                self._handle, args,
-> 1472                                                run_metadata_ptr)
   1473         if run_metadata:
   1474           proto_data = tf_session.TF_GetBuffer(run_metadata_ptr)

InvalidArgumentError: 2 root error(s) found.
  (0) Invalid argument: Input to reshape is a tensor with 156016 values, but the requested shape has 156800
	 [[{{node TensorGraph/while/iteration_0/DotIncBuilder/Reshape_1}}]]
	 [[loss_2/mul/_187]]
  (1) Invalid argument: Input to reshape is a tensor with 156016 values, but the requested shape has 156800
	 [[{{node TensorGraph/while/iteration_0/DotIncBuilder/Reshape_1}}]]
0 successful operations.
0 derived errors ignored.

This error seems to appear when the size of the validation split (here, 33001) is not evenly divisble by the minibatch size (here, 200).

Versions:

  • Python 3.7
  • master nengo-dl
  • latest conda install tensorflow-gpu
@kebitmatf
Copy link

still got same error too... I cannot find the solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants