def get_one_hot_targets(target_file_path):
target = []
one_hot_targets = []
n_target = 0
try :
with open(target_file_path) as f :
target = f.readlines()
target = [t.strip('\n') for t in target]
n_target = len(target)
except IOError :
print('Could not load the labels.txt file in the dataset. A '
'dataset folder is expected in the "data/datasets" '
'directory with the name that has been passed as an '
'argument to this method. This directory should contain a '
'file called labels.txt which contains a list of labels and '
'corresponding folders for the labels with the same name as '
'the labels.')
traceback.print_stack()
lbl_idxs = np.arange(n_target)
one_hot_targets = np.zeros((n_target, n_target))
one_hot_targets[np.arange(n_target), lbl_idxs] = 1
return target, one_hot_targets, n_target
评论列表
文章目录