2014-06-21 2 views
2

총 7000 개의 이미지가 있는데 여기에서 HoG 기능을 추출했습니다. 그런 다음 목록을 추가 처리를 위해 np 배열로 변환하려고합니다. 그러나 변환 중에 메모리 오류가 발생합니다.목록을 numpy 배열로 변환하는 중 메모리 오류가 발생했습니다.

from skimage import data, io, filter, color, exposure 
from skimage.feature import hog 
from skimage.transform import resize 
import matplotlib.pyplot as plt 
import numpy as np 

tmp_hogs = [] # this is the list I need to convert into a numpy array 
for group in samplegroups: 
    for myimg in group: 
     curr_img = np.array(myimg, dtype=float) 
     imgs.append(curr_img) 
     fd, hog_image = hog(curr_img, orientations=8, pixels_per_cell=(4, 4), 
       cells_per_block=(1, 1), visualise=True, normalise=True) 
     tmp_hogs.append(fd) 

img_hogs = np.array(tmp_hogs, dtype =float) 

내가 오류는 다음과 같습니다 :

Exception in thread Thread-1: 
Traceback (most recent call last): 
    File "C:\Users\app\anacondasoftware\lib\threading.py", line 810, in __bootstrap_inner 
    self.run() 
    File "C:\Users\app\anacondasoftware\lib\site-packages\spyderlib\widgets\externalshell\monitor.py", line 582, in run 
    already_pickled=True) 
    File "C:\Users\app\anacondasoftware\lib\site-packages\spyderlib\utils\bsdsocket.py", line 45, in write_packet 
    nsend -= temp_fail_retry(socket.error, sock.send, sent_data) 
    File "C:\Users\app\anacondasoftware\lib\site-packages\spyderlib\utils\bsdsocket.py", line 25, in temp_fail_retry 
    return fun(*args) 
error: [Errno 10054] An existing connection was forcibly closed by the remote host 

Traceback (most recent call last): 
    File "C:\Users\app\Documents\Python Scripts\gbc_carclassify.py", line 63, in <module> 
    img_hogs = np.array(tmp_hogs, dtype =float) 
MemoryError 

은 어떻게 고칠 수

여기 내 코드의 관련 부분이다?

+0

tmp_hogs의 크기는 얼마입니까? 그리고 그것은 1D입니까? – Davidmh

+0

얼마나 많은 메모리가 있습니까? 얼마나 많은 양의 메모리가 필요합니까? 32 또는 64 비트 Python을 사용하고 있습니까? – DrV

+0

64 비트 컴퓨터에서 32 비트 파이썬 (Anaconda의 스파이더). – user961627

답변

4

RGB 또는 RGBA 이미지의 경우 값 당 8 비트 만 필요하며 float을 사용하면 값당 64 비트가 할당됩니다. np.uint8 대신 다음을 사용해보세요.

img_hogs = np.array(tmp_hogs, dtype=np.uint8) 
+2

또 다른 개선점은 빈 배열을 만들고 중간 배열을 피하면서이 배열에 이미지를 직접 저장하는 것입니다. –

관련 문제