'Helper function for reading in next sample.'

def next_sample(self):

    if (self.seq is not None):
        if (self.cur >= len(self.seq)):
            raise StopIteration
        idx = self.seq[self.cur]
        self.cur += 1
        if (self.imgrec is not None):
            s = self.imgrec.read_idx(idx)
            (header, img) = recordio.unpack(s)
            if (self.imglist is None):
                return (header.label, img)
            else:
                return (self.imglist[idx][0], img)
        else:
            (label, fname) = self.imglist[idx]
            return (label, self.read_image(fname))
    else:
        s = self.imgrec.read()
        if (s is None):
            raise StopIteration
        (header, img) = recordio.unpack(s)
        return (header.label, img)
