验证数据的 Tensorflow 内存问题

问题描述 投票:0回答:0

我正在尝试训练张量流神经网络。由于训练数据对于我的计算机 RAM 来说太大了,我将其划分为子数据集并按顺序训练它们。但是,我有一个问题,如果我使用validation_data参数调用

model.fit
,代码会返回错误。我没有通过任何验证数据,我工作得很好。

epochs = 30
optimizer = tf.keras.optimizers.SGD(learning_rate=lr)
model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])
x_val, y_val, x_test, y_test = read_val(3, val_ratio=0.5)
print("start training")
for epoch in range(epochs):
        print("\n" + str(epoch))
        for n in range(3):
            x_t, y_t = read_small(n)
            history = model.fit(x_t, y_t, epochs=1, batch_size=32, verbose=0, validation_data=(x_val, y_val))
            x_t = []; y_t = [];

read_small(n)
本质上是读取训练数据的子数据集。如果将该函数调用为:
history = model.fit(x_t, y_t, epochs=1, batch_size=32, verbose=0)
已完成 30 个 epoc 的完整训练,并且没有返回任何错误。

但是,如果我调用代码中给出的函数:

history = model.fit(x_t, y_t, epochs=1, batch_size=32, verbose=0, validation_data=(x_val, y_val))
程序返回以下错误:

“C:\Users\PC naconda3 nvs\CVISEnv\lib\site-packages ensorflow\python ramewor

tensorflow neural-network ram tensorflow-datasets
© www.soinside.com 2019 - 2024. All rights reserved.