soroushj / keras-balanced-batch-generator Goto Github PK
View Code? Open in Web Editor NEWA Keras-compatible generator for creating balanced batches
License: MIT License
A Keras-compatible generator for creating balanced batches
License: MIT License
Doesn't with Pandas dataframes, and doesnt throw an exception when a pandas df is given to init
Hello.
If my model is not a Sequential() one because it has several inputs, X is the tuple that contains the vectors (these vectors DO have the same lenght than 'y', but X does not). Do you have any plans of allowing this?
Thanks
ZeroDivisionError Traceback (most recent call last)
in
15 steps_per_epoch=steps,
16 validation_steps=stepsval,
---> 17 callbacks=callbacks
18 )
/usr/local/lib/python3.6/dist-packages/tensorflow/python/util/deprecation.py in new_func(*args, **kwargs)
322 'in a future version' if date is None else ('after %s' % date),
323 instructions)
--> 324 return func(*args, **kwargs)
325 return tf_decorator.make_decorator(
326 func, new_func, 'deprecated',
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in fit_generator(self, generator, steps_per_epoch, epochs, verbose, callbacks, validation_data, validation_steps, validation_freq, class_weight, max_queue_size, workers, use_multiprocessing, shuffle, initial_epoch)
1827 use_multiprocessing=use_multiprocessing,
1828 shuffle=shuffle,
-> 1829 initial_epoch=initial_epoch)
1830
1831 @deprecation.deprecated(
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/training.py in _method_wrapper(self, *args, **kwargs)
106 def _method_wrapper(self, *args, **kwargs):
107 if not self._in_multi_worker_mode(): # pylint: disable=protected-access
--> 108 return method(self, *args, **kwargs)
109
110 # Running inside run_distribute_coordinator
already.
/usr/local/lib/python3.6/dist-packages/tensorflow/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_batch_size, validation_freq, max_queue_size, workers, use_multiprocessing)
1120 use_multiprocessing=use_multiprocessing,
1121 model=self,
-> 1122 steps_per_execution=self._steps_per_execution)
1123 val_logs = self.evaluate(
1124 x=val_x,
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py in init(self, x, y, sample_weight, batch_size, steps_per_epoch, initial_epoch, epochs, shuffle, class_weight, max_queue_size, workers, use_multiprocessing, model, steps_per_execution)
1115 use_multiprocessing=use_multiprocessing,
1116 distribution_strategy=ds_context.get_strategy(),
-> 1117 model=model)
1118
1119 strategy = ds_context.get_strategy()
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py in init(self, x, y, sample_weights, workers, use_multiprocessing, max_queue_size, model, **kwargs)
784 # Since we have to know the dtype of the python generator when we build the
785 # dataset, we have to look at a batch to infer the structure.
--> 786 peek, x = self._peek_and_restore(x)
787 peek = self._standardize_batch(peek)
788 peek = _process_tensorlike(peek)
/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/engine/data_adapter.py in _peek_and_restore(x)
841 @staticmethod
842 def _peek_and_restore(x):
--> 843 peek = next(x)
844 return peek, itertools.chain([peek], x)
845
in make_generator(x, y, batch_size, categorical, seed)
46 random_class = rand.randrange(num_classes)
47 current_index = indexes[random_class]
---> 48 indexes[random_class] = (current_index + 1) % len(samples[random_class])
49 if current_index == 0:
50 rand.shuffle(samples[random_class])
ZeroDivisionError: integer division or modulo by zero`
this is your snippet code I modified
else: batch_y[i] = random_class batch_y_bin = np.argmax(batch_y, axis=1).astype('float32') yield ([batch_x, batch_y_bin],[batch_y,batch_y_bin])
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.