This might seem a basic question, but I am stuck on it and would like to get some help.
I am trying to load and preprocess some images in DICOM Format in order to feed them to my Keras model, since I have about 2 thousand of images, RAM got consumed before I finish the preprocessing step. here is the code of the preprocessing step:
(directory, labels are predefined variables)
shape=(256,256)
patients_filename=tf.constant([directory+'/'+path for path in os.listdir(directory)])
dataset = tf.data.Dataset.from_tensor_slices((patients_filename,labels))
def parse_function(patientfilename,label):
var=tf.data.Dataset.list_files(patientfilename+'/*')
for image in var:
image=tf.io.read_file(image)
image = tfio.image.decode_dicom_image(image,dtype=tf.uint64)
image = tf.cast(image, tf.float32)
image=tf.image.resize(image,size=shape)/65535.0
image=tf.reshape(image,shape+(1,))
return image,label
dataset = dataset.map(parse_function).batch(8).prefetch(1)
Then I feed the model with the preprocessed data (dataset).
Do you have any idea how can I do better ?