Optimization methods 6.1

Hi There,
Please help! Thanks very much!

My codes run well before 6.1 - Mini-Batch Gradient Descent, no error showing up.
However, after running 6.1, i get this:

TypeError Traceback (most recent call last)
in
1 # train 3-layer model
2 layers_dims = [train_X.shape[0], 5, 2, 1]
----> 3 parameters = model(train_X, train_Y, layers_dims, optimizer = “gd”)
4
5 # Predict

in model(X, Y, layers_dims, optimizer, learning_rate, mini_batch_size, beta, beta1, beta2, epsilon, num_epochs, print_cost)
44 # Define the random minibatches. We increment the seed to reshuffle differently the dataset after each epoch
45 seed = seed + 1
—> 46 minibatches = random_mini_batches(X, Y, mini_batch_size, seed)
47 cost_total = 0
48

in random_mini_batches(X, Y, mini_batch_size, seed)
19
20 # Step 1: Shuffle (X, Y)
—> 21 permutation = list(np.random.permutation(m))
22 shuffled_X = X[:, permutation]
23 shuffled_Y = Y[:, permutation].reshape((1, m))

TypeError: ‘numpy.ndarray’ object is not callable

The only way that line 21 throws that error is if there is a problem with your code in random_mini_batches() where it computes ‘m’. So that’s the first place to look.

One way that could happen is if there is a mistake in your model() function, which is triggered the first time the model() is called using the ‘gd’ optimizer.

One mistake that could cause that error message is that if you have assigned a value to the variable list which is a numpy array. list is originally a python function, but in python you can overwrite any variable name with a different value. It is a very dangerous practice to overwrite python’s predefined objects.

1 Like