January 2019
Intermediate to advanced
342 pages
9h 17m
English
In the train function, we will use a batch generator to produce random batches, based on the batch sizes passed. The generator functions can be defined as follows. Note that the functions use yield in place of return. By calling the functions with the required parameters, an iterator object of batches will be created. The batches can be retrieved by applying the next method to the iterator object. We will call the generator functions at the start of each epoch, so that the batches will be random in each epoch.
The following code snippet illustrates the function used to generate the batch iterator object:
def batch_gen(self,X,y,batch_size): index = list(range(X.shape[0])) np.random.shuffle(index) batches = int(X.shape[0]//batch_size) ...
Read now
Unlock full access