简体   繁体   English

在 Colab 中运行我的代码时,为什么我的运行时内存不足?

[英]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)

When I run the code above my session uses up all its ram and I am unsure why.当我运行上面的代码时,我的会话用完了所有的内存,我不确定为什么。 Any help would be appreciated.任何帮助,将不胜感激。

You are uploading all your images to the RAM.您正在将所有图像上传到 RAM。 This could be the reason for the error.这可能是错误的原因。

I don't really understand what is the end goal of this script, I am assuming that you want to upload a training set for a learning process.我真的不明白这个脚本的最终目标是什么,我假设你想上传一个学习过程的训练集。 If that is true you can use different techniques to only uploading a batch of images at a time.如果这是真的,您可以使用不同的技术一次只上传一批图像。 You can use the tensorflow Dataset object that will take care of the work for you.您可以使用tensorflow Dataset对象来处理您的工作。

However if you must open all the images Then you should consider compressing them or resizing them.但是,如果您必须打开所有图像,那么您应该考虑压缩它们或调整它们的大小。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 内存不足 - Google Colab - Running Out of RAM - Google Colab 为什么我在Beaglebone Black上运行这个i2c示例代码时会出现IOError? - Why am I getting an IOError when running this i2c example code on my Beaglebone Black? 当我运行相同的python代码但处于for循环中时,为什么matplotlib条形图会更改 - Why does my matplotlib bar diagram change when I am running the same python code but in a for-loop 为什么我的 Colab 会话会耗尽 RAM? - Why does my Colab session run out of RAM? 为什么我的 Google Colab Session 内存不足? - Why does my Google Colab Session run out of ram? 为什么在运行我的代码时出现错误:'ValueError: Found array with 0 sample(s) (shape=(0, 1)) while a minimum of 1 is required'? - Why am I getting the error: 'ValueError: Found array with 0 sample(s) (shape=(0, 1)) while a minimum of 1 is required' when running my code? 在我的本地机器上运行django webapp时,为什么我用firefox 7.0.1出现黑屏 - When running my django webapp on my local box, why am I getting a blank screen with firefox 7.0.1 为什么我会在我的代码中找到我的移动球命令的跟踪,因为它正在阻止我的其余代码运行 - why am i getting a trace back in my code for my move ball command as it is stopping the rest of my code from running 为什么我无法使用列表 object 语法并且遇到 AttributeError: when running my program - why am i unable to use list object syntax and am met with AttributeError: when running my program 我在 google colab 上运行我的代码。 我收到 RuntimeError: CUDA 错误:设备端断言已触发。错误显示为 torch.manual_seed(seed) - I am running my code on google colab. Am getting RuntimeError: CUDA error: device-side assert triggered.Error is showing for torch.manual_seed(seed)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM