stu1130 commented on a change in pull request #12131: [MXNET-737][WIP] Add last 
batch handle for imageiter
URL: https://github.com/apache/incubator-mxnet/pull/12131#discussion_r210178547
 
 

 ##########
 File path: python/mxnet/image/image.py
 ##########
 @@ -1149,22 +1158,44 @@ def __init__(self, batch_size, data_shape, 
label_width=1,
         else:
             self.auglist = aug_list
         self.cur = 0
+        self._is_allowed_reading = True
+        self._cached_data = None
+        # handle the last batch
+        if self.seq and last_batch == 'discard':
+            new_seq_n = len(self.seq) - len(self.seq) % batch_size
+            self.seq = self.seq[:new_seq_n]
+
+        self.last_batch = last_batch
+        self.num_image = len(self.seq) if self.seq is not None else None
         self.reset()
 
     def reset(self):
         """Resets the iterator to the beginning of the data."""
-        if self.shuffle:
-            random.shuffle(self.seq)
+        if self.last_batch != 'roll_over' or \
+            self._is_allowed_reading is True:
+            if self.imgrec is not None:
+                self.imgrec.reset()
+            self.cur = 0
+        self._is_allowed_reading = True
+
+    def hard_reset(self):
+        """Resets the iterator and ignore roll over data"""
         if self.imgrec is not None:
             self.imgrec.reset()
         self.cur = 0
+        self._is_allowed_reading = True
 
     def next_sample(self):
         """Helper function for reading in next sample."""
+        if self._is_allowed_reading is False:
+            raise StopIteration
         if self.seq is not None:
-            if self.cur >= len(self.seq):
+            if self.cur < self.num_image:
+                idx = self.seq[self.cur]
+            else:
+                if self.last_batch != 'discard':
 
 Review comment:
   No matter it is `pad` or `roll_over`, we need to "reset the cursor"(assign 0 
to the self.cur) to do the padding

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to