[英]Why am I running out of RAM in my runtime when running my code in Colab?
IMAGE_SIZE = 128
IMAGE_CHANNELS = 3
ImageFile.LOAD_TRUNCATED_IMAGES = True
for filename in tdqm(os.listdir(images_path)):
path = os.path.join(images_path, filename)
image = Image.open(path).resize((IMAGE_SIZE, IMAGE_SIZE), Image.NEAREST)
if (np.asarray(image).size != 49152):
bad = bad + 1
print(bad)
print(path)
picarray = np.asarray(image)
#picarray = (picarray>>16).astype(np.int16)
training_data.append(picarray)
training_data = np.reshape(training_data, (-1, IMAGE_SIZE, IMAGE_SIZE, IMAGE_CHANNELS))
#print(training_data.)
training_data = training_data / 127.5 - 1
print('saving file...')
np.save('/content/drive/MyDrive/Art/cubism_data.npy', training)
當我運行上面的代碼時,我的會話用完了所有的內存,我不確定為什么。 任何幫助,將不勝感激。
您正在將所有圖像上傳到 RAM。 這可能是錯誤的原因。
我真的不明白這個腳本的最終目標是什么,我假設你想上傳一個學習過程的訓練集。 如果這是真的,您可以使用不同的技術一次只上傳一批圖像。 您可以使用tensorflow Dataset對象來處理您的工作。
但是,如果您必須打開所有圖像,那么您應該考慮壓縮它們或調整它們的大小。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.