Open nghuixin opened 6 months ago
Hi, hope this message finds you well. For the first bug, I think it's because your input matrix size is not (256, 256, 256). Would you pls double check your input matrix size? The secound bug is also a size error, would you please check the shape of this data_new before this line and send it to me (121 data_new = np.expand_dims(data_new, axis=4) # reshape the brain MRI from 3D to 4D)?
Hello Chenzhong, glad to hear from you. It looks like the error occurs far earlier than the line you called out above.
I added print statements to lines 19 and 20 of the preprocess.py file.
print('Shape of X:', np.shape(X)) print('X.shape[0]:', X.shape[0])
This is what I obtained when running the sample.mgz file, which is obtained from here
`['sample1'
/content/drive/MyDrive/Colab Notebooks/test_brain_age/brain_mri/sample1/brain.mgz
processmgz
Shape of X: (1, 128, 128, 64)
X.shape[0]: 1
Shape of buf: (128, 128, 64)
ValueError Traceback (most recent call last)
[<ipython-input-5-d40b992e75a4>](https://localhost:8080/#) in <cell line: 13>()
11
12 # the mainfunction will automatically save and output the predicted BAs and saliency maps.
---> 13 predicted_BA, repadded_saliency_maps = mainfunction(dir_test_brain_age, path_to_model_weights, path_to_brain_mri)
1 frames
[<ipython-input-4-524288d4abb0>](https://localhost:8080/#) in mainfunction(dir_test_brain_age, path_to_model_weights, path_to_brain_mri)
12
13
---> 14 brains, coordinates = processmgz(brains_tmp)
15 (
16 brain_save_path,
[/content/drive/MyDrive/Colab Notebooks/test_brain_age/function/preprocess.py](https://localhost:8080/#) in processmgz(brains)
23 buf = X[i, :, :, :]
24 print('Shape of buf: ', np.shape(buf))
---> 25 buf = buf.reshape((128, 128, 128))
26 xmin = 0
27 xmax = 0
ValueError: cannot reshape array of size 1048576 into shape (128,128,128)`
Similarly, when I run it on my own data, I also get an error:
`['s223']
/content/drive/MyDrive/Colab Notebooks/test_brain_age/brain_mri/s223/brain.mgz
processmgz
Shape of X: (1, 128, 128, 86)
X.shape[0]: 1
Shape of buf: (128, 128, 86)
ValueError Traceback (most recent call last)
[<ipython-input-21-d40b992e75a4>](https://localhost:8080/#) in <cell line: 13>()
11
12 # the mainfunction will automatically save and output the predicted BAs and saliency maps.
---> 13 predicted_BA, repadded_saliency_maps = mainfunction(dir_test_brain_age, path_to_model_weights, path_to_brain_mri)
1 frames
[<ipython-input-20-524288d4abb0>](https://localhost:8080/#) in mainfunction(dir_test_brain_age, path_to_model_weights, path_to_brain_mri)
12
13
---> 14 brains, coordinates = processmgz(brains_tmp)
15 (
16 brain_save_path,
[/content/drive/MyDrive/Colab Notebooks/test_brain_age/function/preprocess.py](https://localhost:8080/#) in processmgz(brains)
23 buf = X[i, :, :, :]
24 print('Shape of buf: ', np.shape(buf))
---> 25 buf = buf.reshape((128, 128, 128))
26 xmin = 0
27 xmax = 0
ValueError: cannot reshape array of size 1409024 into shape (128,128,128)`
When both mgz files are in the brain_mri folder, each in its separate folder, this is what I see:
`['sample1']
/content/drive/MyDrive/Colab Notebooks/test_brain_age/brain_mri/sample1/brain.mgz
['sample1', 's223']
/content/drive/MyDrive/Colab Notebooks/test_brain_age/brain_mri/s223/brain.mgz
processmgz
ValueError Traceback (most recent call last)
[<ipython-input-15-d40b992e75a4>](https://localhost:8080/#) in <cell line: 13>()
11
12 # the mainfunction will automatically save and output the predicted BAs and saliency maps.
---> 13 predicted_BA, repadded_saliency_maps = mainfunction(dir_test_brain_age, path_to_model_weights, path_to_brain_mri)
1 frames
[<ipython-input-13-524288d4abb0>](https://localhost:8080/#) in mainfunction(dir_test_brain_age, path_to_model_weights, path_to_brain_mri)
12
13
---> 14 brains, coordinates = processmgz(brains_tmp)
15 (
16 brain_save_path,
[/content/drive/MyDrive/Colab Notebooks/test_brain_age/function/preprocess.py](https://localhost:8080/#) in processmgz(brains)
16 # brains = np.asarray(brains)
17
---> 18 X = np.asarray(brains)
19 print('Shape of X:', np.shape(X))
20 print('X.shape[0]:', X.shape[0])
ValueError: setting an array element with a sequence. The requested array has an inhomogeneous shape after 3 dimensions. The detected shape was (2, 128, 128) + inhomogeneous part.`
Hi! By any chance you'd have updates on this? @chenzhoy
Hi. Sorry for the late update. It looks like your input size is (1, 128, 128, 64) which suggest that the input MRI size could be (1, 256, 256, 128). However, our model can only support MRI with 256x256x256 which caused this error.
Would you recommend zero padding or interpolation, in this case?
From: chenzhoy @.> Sent: Thursday, April 25, 2024 11:32 PM To: irimia-laboratory/USC_BA_estimator @.> Cc: Hui Xin Ng @.>; Author @.> Subject: Re: [irimia-laboratory/USC_BA_estimator] Axis error and Value error in processmgz (Issue #4)
Hi. Sorry for the late update. It looks like your input size is (1, 128, 128, 64) which suggest that the input MRI size could be (1, 256, 256, 128). However, our model can only support MRI with 256x256x256 which caused this error.
— Reply to this email directly, view it on GitHubhttps://github.com/irimia-laboratory/USC_BA_estimator/issues/4#issuecomment-2078279392, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEAMWV53UZ2YODVFHQVLBSLY7F77PAVCNFSM6AAAAABDPZ2JMOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZYGI3TSMZZGI. You are receiving this because you authored the thread.Message ID: @.***>
I am sorry but I think padding may highly influence the model's performance.
I've tried running
mainfunction
provided in the example code on two different mgz files: the first one is from my dataset, the second file is the standard sample file that comes with freesurfer software, and have run into different errors in both. Any pointers would be helpful, thank you!This is the error when I run it on one test subject from my own dataset.
The sample freesurfer file is $FREESURFER_HOME/subjects/sample-001.mgz This is the error: