简体   繁体   English

MemoryError: Unable to allocate 137. MiB for an array with shape (3000, 4000, 3) and data type float32

[英]MemoryError: Unable to allocate 137. MiB for an array with shape (3000, 4000, 3) and data type float32

I am facing this issue while running a model of 10 positive and 10 negative training data.我在运行包含 10 个正数和 10 个负数训练数据的 model 时遇到了这个问题。


MemoryError: Unable to allocate 137. MiB for an array with shape (3000, 4000, 3) and data type float32 MemoryError: Unable to allocate 137. MiB for an array with shape (3000, 4000, 3) and data type float32


My code is this:我的代码是这样的:

# Define a single function that can extract features using hog sub-sampling and make predictions
def find_cars(img, ystart, ystop, scale, svc,orient, 
              pix_per_cell, cell_per_block,show_all_rectangles=False):
    
    # array of rectangles where cars were detected
    rectangles = []
    
    img = img.astype(np.float32)/255
    
    img_tosearch = img[ystart:ystop,:,:]

    # apply color conversion if other than 'RGB'
    ctrans_tosearch = cv2.cvtColor(img_tosearch, cv2.COLOR_RGB2YUV)
    
    # rescale image if other than 1.0 scale
    imshape = ctrans_tosearch.shape
    ctrans_tosearch = cv2.resize(ctrans_tosearch, (np.int(imshape[1]/scale), np.int(imshape[0]/scale)))
    
    ch1 = ctrans_tosearch[:,:,0]
    ch2 = ctrans_tosearch[:,:,1]
    ch3 = ctrans_tosearch[:,:,2]
    
    # Define blocks and steps as above
    nxblocks = (ch1.shape[1] // pix_per_cell)+1  #-1
    nyblocks = (ch1.shape[0] // pix_per_cell)+1  #-1 
    
    nfeat_per_block = orient*(cell_per_block**2)
    
    # 64 was the orginal sampling rate, with 8 cells and 8 pix per cell
    window = 64
    nblocks_per_window = (window // pix_per_cell)-1 
    cells_per_step = 2  # Instead of overlap, define how many cells to step
    nxsteps = (nxblocks - nblocks_per_window) // cells_per_step
    nysteps = (nyblocks - nblocks_per_window) // cells_per_step
    
    # Compute individual channel HOG features for the entire image
    hog1 = get_hog_features(ch1, orient, pix_per_cell, cell_per_block, feature_vec=False)   
    hog2 = get_hog_features(ch2, orient, pix_per_cell, cell_per_block, feature_vec=False)
    hog3 = get_hog_features(ch3, orient, pix_per_cell, cell_per_block, feature_vec=False)
    
    for xb in range(nxsteps):
        for yb in range(nysteps):
            ypos = yb*cells_per_step
            xpos = xb*cells_per_step
            
            # Extract HOG for this patch
            hog_feat1 = hog1[ypos:ypos+nblocks_per_window, xpos:xpos+nblocks_per_window].ravel()
            hog_feat2 = hog2[ypos:ypos+nblocks_per_window, xpos:xpos+nblocks_per_window].ravel() 
            hog_feat3 = hog3[ypos:ypos+nblocks_per_window, xpos:xpos+nblocks_per_window].ravel() 
            hog_features = np.hstack((hog_feat1, hog_feat2, hog_feat3))
            xleft = xpos*pix_per_cell
            ytop = ypos*pix_per_cell
                                  
            test_prediction = svc.predict(hog_features.reshape(1,-1))
            
            if test_prediction == 1 or show_all_rectangles:
                xbox_left = np.int(xleft*scale)
                ytop_draw = np.int(ytop*scale)
                win_draw = np.int(window*scale)
                rectangles.append(((xbox_left, ytop_draw+ystart),(xbox_left+win_draw,ytop_draw+win_draw+ystart)))
                
    return rectangles

test_img = mpimg.imread('C:/Users/shrey/Desktop/Mod1-IITR/DJI_0314.JPG')

ystart = 20
ystop = 50
scale = 1
orient = 11
pix_per_cell = 16
cell_per_block = 2

rectangles = find_cars(test_img, ystart, ystop, scale, svc,orient, pix_per_cell, cell_per_block)

print(len(rectangles), 'rectangles found in image')

I am working on Windows- Jupyter notebook.我正在使用 Windows-Jupyter 笔记本。 How can I correct this code issue?如何更正此代码问题?

The error is as it says, it is unable to allocate memory, because there isn't enough.错误正如它所说,它无法分配memory,因为没有足够的。

However, chances are you have much more memory on your system available than 137MiB, jupyter is simply limiting how much memory can be used from your system, because it has to reserve some memory before you start running your code.但是,您的系统上可用的 memory 可能比 137MiB 多得多,jupyter 只是限制了您的系统可以使用多少 memory,因为它必须在您开始运行代码之前保留一些 ZCD69B4957F06CD818D7BF3D61 See here for how to increase the memory limit in jupyter请参阅此处了解如何在 jupyter 中增加 memory 限制

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 numpy.core._exceptions.MemoryError:无法为形状为 (1073741824, 0) 且数据类型为 float32 的数组分配 0 个字节 - numpy.core._exceptions.MemoryError: Unable to allocate 0 bytes for an array with shape (1073741824, 0) and data type float32 MemoryError: 无法分配形状为 (2515, 406272) 且数据类型为 float32 的数组 - MemoryError: Unable to allocate array with shape (2515, 406272) and data type float32 MemoryError:在python中使用word2vec时无法分配形状和数据类型为float32的数组 - MemoryError: unable to allocate array with shape and data type float32 while using word2vec in python 当显示带有 plt.show() 的图像时 -> MemoryError: Unable to allocate array with shape (3600, 7200, 4) and data type float32 - When showing an image with plt.show() -> MemoryError : Unable to allocate array with shape (3600, 7200, 4) and data type float32 MemoryError: Unable to allocate 5.62 GiB for an array with shape (16384, 30720, 3) and data type float32 when training StyleGan2 - MemoryError: Unable to allocate 5.62 GiB for an array with shape (16384, 30720, 3) and data type float32 When training StyleGan2 MemoryError: Unable to allocate 797. MiB for an array with shape (51, 51, 40169) and data type float64 - MemoryError: Unable to allocate 797. MiB for an array with shape (51, 51, 40169) and data type float64 MemoryError:无法为形状为 (5004, 96) 且数据类型为 int32 的数组分配 1.83 MiB - MemoryError: Unable to allocate 1.83 MiB for an array with shape (5004, 96) and data type int32 Keras,内存错误 - 数据 = data.astype(“float”) / 255.0。 无法为形状为 (13165, 32, 32, 3) 的数组分配 309.MiB - Keras, memoryerror - data = data.astype(“float”) / 255.0. Unable to allocate 309. MiB for an array with shape (13165, 32, 32, 3) MemoryError: 无法为 DIPY 图像配准中具有形状 (344, 344, 127) 和数据类型 float64 的数组分配 115. MiB - MemoryError: Unable to allocate 115. MiB for an array with shape (344, 344, 127) and data type float64 in DIPY image registration MemoryError:在 sklearn 中使用 anymodel.fit() 时,无法为具有形状和数据类型的数组分配 MiB - MemoryError: Unable to allocate MiB for an array with shape and data type, when using anymodel.fit() in sklearn
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM