2017-02-25 197 views
2

我有50個圖像的大小1028x1028。我試圖從50張圖片中隨機抽取幾張補丁製作一本字典。使用scikit學習字典學習中的內存錯誤學習

這裏是我的代碼=>

from os import listdir 
from time import time 
import matplotlib.pyplot as plt 
import numpy as np 
import scipy as sp 
from sklearn.decomposition import MiniBatchDictionaryLearning 
from sklearn.feature_extraction.image import extract_patches_2d 
from sklearn.feature_extraction.image import reconstruct_from_patches_2d 
from sklearn.utils.fixes import sp_version 
from sklearn.datasets import load_sample_image 
from scipy import ndimage 
from skimage import color 
from skimage import io 
from PIL import Image 
from sklearn.decomposition import SparseCoder 
from sklearn.decomposition import sparse_encode 
from skimage import data,restoration 
from scipy.misc import imfilter, imread 
from scipy.signal import convolve2d as conv2 
import sys 
from sklearn.feature_extraction import image 


x = [] 

path = 'resize/' 
c=0 
for e in listdir(path): 
    matrix = np.asarray(Image.open(path+e).convert('L')) 
    x.append(matrix)  

images = np.array(x) 

input = np.asarray(Image.open('H03.bmp').convert('L')) 
height , width = input.shape 

patchsize = (7,14) 
patches = image.PatchExtractor((7,14),10000,10).transform(images) 
print(patches.shape) 

data = patches.reshape(patches.shape[0], -1) 
n_iter = 1000 
dico = MiniBatchDictionaryLearning(n_components=100,alpha=3,n_iter=n_iter) 

V = dico.fit_transform(data).components_ 

但在最後一行我得到的MemoryError。這是錯誤=>

(480000,7,14) 回溯(最近最後調用):文件 「new.py」,第63行,在

V = dico.fit_transform(數據).components_ File「/usr/local/lib/python3.4/dist-packages/sklearn/base.py」,line 494,in fit_transform

return self.fit(X,** fit_params).transform( X)文件「/usr/local/lib/python3.4/dist-packages/sklearn/decomposition/dict_learning.py」, line 1238,in fit

return_n_it ER = TRUE)文件 「/usr/local/lib/python3.4/dist-packages/sklearn/decomposition/dict_learning.py」, 線677,在dict_learning_online

random_state = random_state)文件「在/ usr /本地/lib/python3.4/dist-packages/sklearn/utils/extmath.py 「 364行,在randomized_svd

power_iteration_normalizer,random_state)文件」 /usr/local/lib/python3.4/dist-packages /sklearn/utils/extmath.py 「 線258,在randomized_range_finder

Q,_ = linalg.lu(safe_sparse_dot(A,Q),permute_l =真)文件」 的/ usr /本地/ LIB/python3。 4/dist-packages/sklearn/utils/extmath.py「, 線189,在safe_sparse_dot

回報fast_dot(A,B)的MemoryError

我不知道爲什麼我收到這個錯誤?

+1

MemoryError基本上在內存不足時發生。你沒有足夠的內存。你的系統配置是什麼? –

+1

i3,4GB ram ...我認爲可以運行這個程序。 –

+1

ok @VikashSingh先生我只拍攝10張照片。讓看看發生了什麼等待一分鐘... –

回答

2

正如評論中所述。

MemoryError在基本上內存不足時發生。你不要 有足夠的內存。你的系統配置是什麼?

OP回答:

我想,你是R8 ....如果我需要大約10張幾張圖片。然後 其工作很好,多虧了幫助。 -

基本上用戶正在用盡RAM空間。