簡體   English   中英

錯誤:Out of Memory,tensorflow cnn

[英]Error: Out Of Memory, tensorflow cnn

我正在使用Tensorflow CNN的入門示例並將參數更新為我自己的數據,但由於我的模型很大(244 * 244個功能),我得到OutOfMemory錯誤。

我正在Ubuntu 14.04上運行4個CPU和16個RAM的培訓。 有沒有辦法縮小我的數據,所以我沒有得到這個OOM錯誤?
我的代碼看起來像這樣:

# Create the Estimator
  mnist_classifier = tf.estimator.Estimator(
    model_fn=cnn_model_fn, model_dir="path/to/model")

# Load the data
train_input_fn = tf.estimator.inputs.numpy_input_fn(
  x={"x": np.array(training_set.data)},
  y=np.array(training_set.target),
  num_epochs=None,
  batch_size=5,
  shuffle=True)

# Train the model
mnist_classifier.train(
  input_fn=train_input_fn,
  steps=100,
  hooks=[logging_hook])

有沒有辦法縮小我的數據,所以我沒有得到這個OOM錯誤?

您可以對training_set進行切片以僅獲取數據集的一部分。 就像是:

x={"x": np.array(training_set.data)[:(len(training_set)/2)]},
y=np.array(training_set.target)[:(len(training_set)/2)],

在此示例中,您將獲得數據集的前半部分(您可以選擇要加載的數據集的哪個點)。

編輯:您可以這樣做的另一種方法是獲取訓練數據集的隨機子集。 這可以通過屏蔽數據集數組上的元素來實現。 例如:

import numpy as np
from random import random as rn

#obtain boolean mask to filter out some elements
#here you can define your sample %
r = 0.5 #say filter half the elements
mask = [True if rn() >= r else False for i in range(len(training_set))]

#finally, mask out those elements, 
#the result will have ~r times the original elements
reduced_ds = training_set[mask]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM