文件路径问题

2024-09-15 16:36:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试从以下路径加载文件:

path = 'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'

但是,文件未加载。如果我将文件上移一级并将路径更改为

path = 'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/S16309/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'

它加载。你知道吗

唯一的区别是S13893文件夹。你知道吗

我有以下代码:

import nibabel as nib
import matplotlib.pyplot as plt
from scipy.misc import imsave as imsave

path = 'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'

im = nib.load(path).get_data()
print(im.shape)

任何帮助都会很好。你知道吗


Tags: 文件pathtestnetworkusersb1correctionn3
2条回答

我尝试在路径的开头使用r,但是没有成功。你知道吗

另外,我尝试使用\\?\但还是没用。你知道吗

最后,我发现这实际上是路径长度的问题,并通过删除所有文件路径中的共性来缩短路径,效果很好。你知道吗

谢谢你的帮助。你知道吗

但是,这只是我执行的一个变通方法,建议的编辑/更改对我不起作用。你知道吗

在Windows中,您应该尝试:

path = r'C:/Users/Aman/Alzheimer/test-network/ADNI1_Complete_1Yr_1.5T/ADNI/002_S_0685/MPR__GradWarp__B1_Correction__N3__Scaled/2006-07-06_10_36_49.0/ADNI_002_S_0685_MR_MPR__GradWarp__B1_Correction__N3__Scaled_Br_20070216235850690_S16309_I40683.nii'

相关问题 更多 >