我正在做深度学习的东西。我有tensorflow 2.0(cpu版本),当我尝试在pycharm(或jupyter笔记本)中运行此代码(以下)时,它使用3GB的内存(RAM),但是我有6GB的RAM
我运行的数据集具有50000+培训图片和10k测试图片(我记得)。
代码是:
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
我希望任何人都可以帮助您解决一下您认为的答案。
非常感谢<3
最佳答案
使用批次进行培训,应该对其进行修复
关于python - 运行带有3GB RAM的python代码并使PC崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58824001/