我使用Python进行图像分析。我的代码的第一步是将图像从磁盘加载到一个大的20GB uint8阵列。这一步需要很长时间,加载速度约为10MB/s,并且在任务期间CPU空闲。如何在Python中提高磁盘读取速度
这似乎非常缓慢。我是否犯了一个明显的错误?我该如何提高性能?这是否是numpy数组类型的问题?
# find all image files in working folder
FileNames = [] # FileNames is a list of image names
workingFolder = 'C:/folder'
for (dirpath, dirnames, filenames) in os.walk(workingFolder):
FileNames.extend(filenames)
FileNames.sort() # Sorted by image number
imNumber = len(FileNames) # Number of Images
# AllImages initialize
img = Image.open(workingFolder+'/'+FileNames[0])
AllImages = np.zeros((img.size[0],img.size[1], imNumber),dtype=np.uint8)
for ii in range(imNumber):
img = Image.open(workingFolder+'/'+FileNames[ii])
AllImages[:,:,ii] = img
非常感谢您的帮助。
这可能是因为你的硬盘速度很慢。你有没有通过其他方式测试它的速度?如果硬盘读/写速度是瓶颈,你的CPU将闲置。 –
传输文件时,传输速度始终高于150MB/s,相信计算机中较慢的HDD会造成瓶颈。 – LapLap