forked from vlomonaco/core50
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_filelist_utils.py
64 lines (47 loc) · 2.29 KB
/
create_filelist_utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
# Copyright (c) 2017. Vincenzo Lomonaco. All rights reserved. #
# See the accompanying LICENSE file for terms. #
# #
# Date: 28-04-2017 #
# Author: Vincenzo Lomonaco #
# E-mail: [email protected] #
# Website: vincenzolomonaco.com #
################################################################################
"""
This file contains some utility and common methods for creating the filelists
for the different scenarios and from the CORe50 dataset.
"""
# Depenencies
from glob import glob
def scale_labes(orig_list):
""" This method given a list of number returns a dict with a scaled
conversion. """
convdict = {}
ordered_list = sorted(orig_list)
for i, num in enumerate(ordered_list):
convdict[num] = i
return convdict
def load_filelist_per_sess(glob_file):
""" This method returns a dictionary {batch_name : (path, label)}. """
batches = {}
for filepath in sorted(glob(glob_file)):
batch_name, label, filename = filepath.split('/')[-3:]
batch_id = int(batch_name[1:])-1
if batch_id not in batches.keys():
batches[batch_id] = []
batches[batch_id].append((filename, int(label[1:])-1))
return batches
def create_filelist(filelist_name, batches, sess, objs, label_map=None):
""" This method create a single filelist given a list of objs and sess. """
with open(filelist_name + "_filelist.txt", 'w') as f:
for batch_id, patterns in batches.items():
for filename, label in patterns:
if batch_id in sess and label in objs:
if label_map:
new_label = label_map[label]
else:
new_label = label
f.write('s' + str(batch_id+1) + '/o' + str(label+1) + '/' +
filename + ' ' + str(new_label) + '\n')