运行带有3GB RAM的python代码并使PC崩溃

我正在做深度学习的东西。我有tensorflow 2.0(cpu版本),当我尝试在pycharm(或jupyter笔记本)中运行此代码(以下)时,它使用3GB的内存(RAM),但是我有6GB的RAM

我运行的数据集有50000张以上的训练图片和1万张测试图片(我记得)。 代码是:

import tensorflow as tf
from tensorflow import keras
import matplotlib.pyplot as plt
import numpy as np

data_mnist = keras.datasets.cifar10
(x_train,y_train),(x_test,y_test) = data_mnist.load_data()

class_names = ['airplane','automobile','bird','cat','deer','dog','frog','horse','ship','truck'
               ]

x_train = x_train/255.0
x_test = x_test/255.0

model = keras.Sequential([
    keras.layers.flatten(input_shape=(32,32,3)),keras.layers.Dense(128,activation='relu'),keras.layers.Dense(10,activation='softmax'),])

model.compile(optimizer='Adam',loss='sparse_categorical_crossentropy',metrics=['accuracy'])
model.fit(x_train,y_train,epochs=1)

image_label = 1

prediction = model.predict(x_test)
plt.grid(False)
plt.imshow(x_test[image_label])
plt.title('actual Img: ' +  class_names[image_label])
plt.xlabel('Predicted: ' + class_names[np.argmax(prediction[image_label])])
plt.show

每当我尝试训练模型时都会发生。

代码没有问题,但是正如我所说,当我尝试运行此代码时,计算机几乎崩溃了(请看下面的图片): enter image description here

我希望任何人都可以帮助您放弃您认为的答案。 非常感谢

yqfjh 回答:运行带有3GB RAM的python代码并使PC崩溃

使用批次进行培训,应该对其进行修复

,

另外3 GB的空间正在被您的操作系统和其他东西占用,这可能会导致您的PC崩溃...批量加载数据进行培训

本文链接:https://www.f2er.com/3115345.html

大家都在问