Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
fix im2rec index (#3839)
Browse files Browse the repository at this point in the history
  • Loading branch information
piiswrong authored Nov 15, 2016
1 parent 46d0d1b commit aa2520b
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions tools/im2rec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


def list_image(root, recursive, exts):
image_list = []
i = 0
if recursive:
cat = {}
for path, subdirs, files in os.walk(root, followlinks=True):
Expand All @@ -25,13 +25,15 @@ def list_image(root, recursive, exts):
if os.path.isfile(fpath) and (suffix in exts):
if path not in cat:
cat[path] = len(cat)
yield (len(image_list), os.path.relpath(fpath, root), cat[path])
yield (i, os.path.relpath(fpath, root), cat[path])
i += 1
else:
for fname in os.listdir(root):
fpath = os.path.join(root, fname)
suffix = os.path.splitext(fname)[1].lower()
if os.path.isfile(fpath) and (suffix in exts):
yield (len(image_list), os.path.relpath(fpath, root), 0)
yield (i, os.path.relpath(fpath, root), 0)
i += 1

def write_list(path_out, image_list):
with open(path_out, 'w') as fout:
Expand Down

0 comments on commit aa2520b

Please sign in to comment.