batches counts error in logistic_sgd.py
Huarong opened this issue · 3 comments
n_train_batches = train_set_x.get_value(borrow=True).shape[0] / batch_size
n_valid_batches = valid_set_x.get_value(borrow=True).shape[0] / batch_size
n_test_batches = test_set_x.get_value(borrow=True).shape[0] / batch_size
should be:
n_train_batches = train_set_x.get_value(borrow=True).shape[0] / batch_size + 1
n_valid_batches = valid_set_x.get_value(borrow=True).shape[0] / batch_size + 1
n_test_batches = test_set_x.get_value(borrow=True).shape[0] / batch_size + 1
Yes, I found the current version could not include all the samples if the sample number could not be divided with no remainder by the batch_size.
I do not agree with your solution because every batch must have exact batch_size samples.
@Lancelod-Liu Every batch is not required to have exact batch_size samples. I've tested my modification.
@Huarong I have reviewed the code and you are right when the case you are working on is the mlp model.
However, if you have tested the LeNet5 code (convolutional_mlp.py), you will find that the input to the LeNet5 is required to have the same batch_size:
self.W = theano.shared(
numpy.asarray(
rng.uniform(low=-W_bound, high=W_bound, size=filter_shape),
dtype=theano.config.floatX
),
borrow=True
)
W is the kernels that one convolutional layer owns and referring to the code, the filter_shape contains the batch_size info and once the model is built, the model only accepts with input of batch_size samples.