diff --git a/python/mxnet/recordio.py b/python/mxnet/recordio.py index eb861147b967..b1d972e9cfe4 100644 --- a/python/mxnet/recordio.py +++ b/python/mxnet/recordio.py @@ -245,10 +245,11 @@ def __init__(self, idx_path, uri, flag, key_type=int): def open(self): super(MXIndexedRecordIO, self).open() - self.idx = {} - self.keys = [] self.fidx = open(self.idx_path, self.flag) - if not self.writable: + if self.writable: + self.idx = {} + self.keys = [] + elif not self.idx: for line in iter(self.fidx.readline, ''): line = line.strip().split('\t') key = self.key_type(line[0])