classDemoIter(mx.io.DataIter): self.__init__(self, data_names, data_shapes, data_gen, label_names, label_shapes, label_gen, num_batches = 10): self._provide_data = zip(data_names, data_shapes) # fixed and must-have self._provide_label = zip(label_names, label_shapes) # fixed and must-have self.num_batches = num_batches # total batches in this training procedure self.data_gen = data_gen # ? # method for generating data self.label_gen = label_gen # ? self.cur_batch = 0# indicate current batch index of total batches # method for generating label # returns an iterator object # and is called implicitly called at the beginning of the loop def__iter__(self): return self # for what use? # TODO: basic python iter impletation # ANS: need to implement __iter__(), next() for python2, __next__() for python3 # next method for python3: __next__() # the same as the next(self) for python2 # maybe in that case the code is compatibale with python2 and python3 def__next__(self): return self.next() defreset(self): self.cur_batch = 0 @property defprovide_data(self): return self._provide_data # refer to: # self._provide_data = zip(data_names, data_shapes) @property defprovide_label(self): return self._provide_label # refer to: # self._provide_label = zip(label_names, label_shapes) defnext(self): if self.cur_batch < self.num_batches: self.cur_batch += 1 # provide_data, provide a list of DataDesc object, the i-th item describe the name and shape of data[i] data = [mx.nd.array(g(d)) for d, g in zip(self._provide_data, self.data_gen)] label = [mx.nd.array(g(d)) for d, g in zip(self._provide_label, self.label_gen)] return mx.io.DataBatch(data, label) else: raise StopIteration
TODO: check and compare the code of DataIter for VID in R-FCN
A little worried about gf’s IELTS. Since the outcome of listening test tonight is totally catastrophe…
Nighty night, will resume this work tomorrow.
Oh, also need to buy knives for the fist meal. Remember this~