forked from stevenwudi/CVPR_2014_code
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChalearnLAPTest.py
56 lines (49 loc) · 2.06 KB
/
ChalearnLAPTest.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
#-------------------------------------------------------------------------------
# Name: Chalearn LAP utils scripts
# Purpose: Provide scripts to add labels to Chalearn LAP challenge tracks samples
#
# Author: Xavier Baro
# Di Wu: stevenwudi@gmail.com
# Created: 25/04/2014
# Copyright: (c) Chalearn LAP 2014
# Licence: GPL
#-------------------------------------------------------------------------------
import os
import zipfile
import shutil
import glob
def main():
""" Main script. Created a labeled copy of validation samples """
# Data folder (Unlabeled data samples)
dataPath=r'I:\Kaggle_multimodal\Validation'
# Labels file (Unziped validation.zip)
labelsPath=r'I:\Kaggle_multimodal\validation_labels'
# Use the method for desired track
print('Uncoment the line for your track')
addLabels_Track3(dataPath, labelsPath)
def addLabels_Track3(dataPath, labelsPath):
""" Add labels to the samples"""
# Check the given data path
if not os.path.exists(dataPath) or not os.path.isdir(dataPath):
raise Exception("Data path does not exist: " + dataPath)
# Check the given labels path
if not os.path.exists(labelsPath) or not os.path.isdir(labelsPath):
raise Exception("Labels path does not exist: " + labelsPath)
# Get the list of samples
samplesList = os.listdir(dataPath)
# For each sample on the GT, search the given prediction
for sample in samplesList:
print "writing file" + sample
# Build paths for sample
sampleFile = os.path.join(dataPath, sample)
# Prepare sample information
file = os.path.split(sampleFile)[1]
sampleID = os.path.splitext(file)[0]
samplePath = dataPath + os.path.sep + sampleID
# Add the labels
srtFileName=sampleID + '_labels.csv'
srcSampleDataPath = os.path.join(labelsPath, srtFileName)
dstSampleDataPath = os.path.join(sampleFile, srtFileName)
shutil.copyfile(srcSampleDataPath, dstSampleDataPath)
if __name__ == '__main__':
main()