我有50张尺寸为1028x1028的图片。我试图通过从50张图片中随机拍摄几张补丁来制作字典。
这是我的代码=>
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(data).components_ File“/usr/local/lib/python3.4/dist-packages/sklearn/base.py”,第494行,在fit_transform中
return self.fit(X,** fit_params).transform(X)File“/usr/local/lib/python3.4/dist-packages/sklearn/decomposition/dict_learning.py”, 第1238行,适合
return_n_iter = True)文件“/usr/local/lib/python3.4/dist-packages/sklearn/decomposition/dict_learning.py”, 第677行,在dict_learning_online
中random_state = random_state)文件“/usr/local/lib/python3.4/dist-packages/sklearn/utils/extmath.py”, 第364行,in 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 = True)文件“/usr/local/lib/python3.4/dist-packages/sklearn/utils/extmath.py”, 第189行,在safe_sparse_dot
中返回fast_dot(a,b)MemoryError
我不知道为什么会收到此错误?
答案 0 :(得分:2)
如评论中所述。
OP回答说:当你基本耗尽内存时会发生MemoryError。你没有 有足够的RAM。你的系统配置是什么?
我想,你是r8 ....如果我在10幅图像周围拍摄少量图像。然后 由于帮助,它的工作正常。 -
基本上用户的RAM空间不足。