Skip to content

Commit

Permalink
make hmdb train/val list generation robust
Browse files Browse the repository at this point in the history
  • Loading branch information
dreamerlin committed Apr 14, 2021
1 parent 36271bb commit b00fd22
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions tools/data/parse_file_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -430,15 +430,23 @@ def generate_class_index_file():

class_list = sorted(os.listdir(frame_path))
class_dict = dict()
with open(class_index_file, 'w') as f:
content = []
for class_id, class_name in enumerate(class_list):
# like `ClassInd.txt` in UCF-101, the class_id begins with 1
class_dict[class_name] = class_id + 1
cur_line = ' '.join([str(class_id + 1), class_name])
content.append(cur_line)
content = '\n'.join(content)
f.write(content)
if not osp.exists(class_index_file):
with open(class_index_file, 'w') as f:
content = []
for class_id, class_name in enumerate(class_list):
# like `ClassInd.txt` in UCF-101,
# the class_id begins with 1
class_dict[class_name] = class_id + 1
cur_line = ' '.join([str(class_id + 1), class_name])
content.append(cur_line)
content = '\n'.join(content)
f.write(content)
else:
print(f'{class_index_file} has been generated before.')
class_dict = {
class_name: class_id + 1
for class_id, class_name in enumerate(class_list)
}

for i in range(1, 4):
train_content = []
Expand Down Expand Up @@ -469,8 +477,7 @@ def generate_class_index_file():
with open(test_file_template.format(i), 'w') as fout:
fout.write(test_content)

if not osp.exists(class_index_file):
generate_class_index_file()
generate_class_index_file()

with open(class_index_file, 'r') as fin:
class_index = [x.strip().split() for x in fin]
Expand Down

0 comments on commit b00fd22

Please # to comment.