Skip to content

Commit

Permalink
lazy loading for large dataset (#20)
Browse files Browse the repository at this point in the history
* Update image.py

change loading of image for drawing instead of loading it for Dataset. Make the tool much more memory efficient for large dataset

* Update image.py

* Update image.py

* Update image.py

* Update test_image.py

change of the test as the array is not memorized anymore
  • Loading branch information
EtienneDavid authored and jsbroks committed Dec 9, 2019
1 parent 453b862 commit 5141652
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
12 changes: 8 additions & 4 deletions imantics/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,11 @@ def __init__(self, image_array=None, annotations=[], path="", id=0, metadata={},

# Create empty image if not provided
if image_array is None:
self.array = np.zeros((height, width, 3)).astype(np.uint8)
self.height, self.width = (height,width)

else:
self.array = image_array

self.height, self.width, _ = self.array.shape
self.height, self.width, _ = image_array.shape

self.size = (self.width, self.height)
self.file_name = os.path.basename(self.path)
Expand Down Expand Up @@ -172,7 +172,11 @@ def draw(self, bbox=True, outline=True, mask=True, text=True, thickness=3, \
:returns: Image array with annotations
:rtype: numpy.ndarray
"""
temp_image = self.array.copy()


temp_image = cv2.imread(self.path)
if temp_image is None:
temp_image = np.zeros((self.height,self.width,3)).astype(np.uint8)
temp_image.setflags(write=True)

for annotation in self.iter_annotations():
Expand Down
3 changes: 1 addition & 2 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ def test_create_empty(self):

assert image.height == height
assert image.width == width
assert image.array.shape == (height, width, 3)
assert len(image.annotations) == 0
assert len(image.categories) == 0

Expand All @@ -28,4 +27,4 @@ def test_images_from_folder(self):
images = Image.from_path(path)

assert isinstance(images, list)
assert len(images) == 1
assert len(images) == 1

0 comments on commit 5141652

Please sign in to comment.