1
$\begingroup$

I am working on a project to classify CT scan images using the CNN model, the image size is huge and I want to feed it into the network using the idea of batches, tried doing that with this pieces of code:

    # train_data size = 5460
    num_epochs = 14
    batch_size = 390
    batch = 0
    print("Starting training...")
    for epoch in range(num_epochs):
        train_batch = train_data[batch:batch_size]
        batch += batch_size
        batch_size += batch_size
        ep_loss = 0
        for data in train_batch:
            X = data[0]
            Y = data[1]
            _, c = sess.run([optimizer, cost], feed_dict={x_img: X, y_label: Y})

my questions are:

1- Is this a right way to do batching? or there is a better way?

2- with the above code I am using 'AdamOptimizer' is it a good optimization technique for the idea of batching or I should use another one?

$\endgroup$
1
$\begingroup$

It's is a good practice to use batches to train neural networks. As Yann LeCun said:

Training with large minibatches is bad for your health. More importantly, it's bad for your test error. Friends dont let friends use minibatches larger than 32.

Although, it will not help you deal with large images. This is what convolutions are for.

If you are using Keras, then the batch implementation is entirely made for you. If you use Tensorflow, then you can use the tf.data api or do your own implementation. The code you provided seem to work for your particular training size, but you may want to adapt it for all kinds of training size (namely using num_iterations = training_size // batch_size) and making sure that the case where not all examples where shown to the network, the last remaining examples are included as well before ending the epoch...

I have had good results with the Adam Optimizer, although you might want to tweak the hyperparameters to get better results.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.