我使用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