# Batch data before feed into CNN network

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?

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...