Week 3 assignment: epoch_cost


at the end of the week 3 assignment under the section “3.3 - Train the model” I have a question about the line of code, where the “epoch_cost” is accumulated:

epoch_cost += minibatch_cost / minibatch_size

Why do we divide by “minibatch_size”? Does the function “compute_cost”, which we had to define beforehand, not return a cost value which already was normalized based on the number of training examples?

To put it differently: In “compute_cost” we had to use “tf_reduce_mean” and as far as I know this function already takes care about dividing by the number of training examples, right?
So in my opinion dividing the “minibatch_cost” by the minibatch_size again in the line of code above is not correct. Or am I missing something here?

Thanks in advance!

1 Like

Hi @benjoman,

Good catch. I would like it to be

epoch_cost += minibatch_cost / num_minibatches

I am going to report this to the lab devs. I will get back to you.

1 Like

Hi @jonaslalin and thanks for your kind reply!

I totally agree with your suggested correction

1 Like