Discussions>Numpy functions take the whole memory>

Numpy functions take the whole memory

I'm using numpy and trying to pad images. When I add padding actions, after couple of epochs my memory gets full and it kills the process. Even swap gets full. What is the problem? Why am I getting this?

2 votesJW330.00
1 Answers

You need to copy your numpy array after your actions, cause it's gonna store in the memory anyway and after certain time your memory will get full. Numpy has copy function, you can use it as well.

Solution 1

import numpy as np

np.copy(np.pad(img, padding_size))

But sometimes these solution also lefts memory busy, then you can use the second one, which copies deeply.

Solution 2

import copy
import numpy as np

copy.deepcopy(np.pad(img, padding_size))
Couldn't find what you were looking for?and we will find an expert to answer.
How helpful was this page?