Categories
Misc

errors when trying to load dataset

I have been trying to develop my machine learning model dealing with Nifti files. I originally just loaded them into a numpy array but after augmentation the amount of data was too large for the RAM.

I discovered that one should make use of things such as generators / tools provided by tf.Data.

As such I attempted the following.

def load_images(imagePath): image = nib.load(imagePath) image = image.get_fdata() image = tf.image.per_image_standardization(image) label = (int)(imagePath.split('Grade')[1][0]) - 1 return (image, label) dataset = tf.data.Dataset.from_tensor_slices(all_paths) dataset = (dataset .shuffle(1024) .map(load_images, num_parallel_calls=AUTOTUNE) .cache() .repeat() .batch(64) .prefetch(AUTOTUNE) ) 

Hopefully the code is straightforward but if anything needs further clarification please do ask. Originally the first two lines of load_images() were it’s own function but I tried it like this to try and resolve the issue.

The issue is that I am getting the following error at the map line:

TypeError: in user code: File "<ipython-input-64-56e9744da5d3>", line 5, in load_images * image = nib.load(imagePath) File "/usr/local/lib/python3.7/dist-packages/nibabel/loadsave.py", line 42, in load * stat_result = os.stat(filename) TypeError: stat: path should be string, bytes, os.PathLike or integer, not Tensor 

I don’t think it likes me using nibabelfunctions in the mapping function but I cannot think of any other way to do it. I tried following the answer here but this just gave me another error about using tf.function

submitted by /u/15150776
[visit reddit] [comments]

Leave a Reply

Your email address will not be published. Required fields are marked *