forked from matthp/Physionet2018_Challenge_Submission
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProducePredictions.py
executable file
·101 lines (77 loc) · 3.82 KB
/
ProducePredictions.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# Imports
from scipy.io import loadmat
from scipy.signal import fftconvolve
import numpy as np
import os
import random
import gc as garbageCollector
from multiprocessing import Pool
import subprocess
########################################################################################################################
# Function to compute consistent train/validation/test split by a constant random seed
def computeTrainValidationTestRecords(dataPath, foldName='Default'):
"""
Function to compute consistent train/validation/test split by a constant random seed on the Physionet 2018 challenge data
:return: Names of records for training, validation, testing data sets
"""
print('////////////////////')
print('Computing train/validation/test data split, Test results are:')
# Define consistent mappings for the index from training data to the actual returned value to ensure shuffling
r = random.Random()
r.seed(29)
requestRecordMap = list(range(994))
r.shuffle(requestRecordMap)
#########
if foldName == 'Default':
testIndices = requestRecordMap[0:200]
validationIndices = requestRecordMap[894::]
trainIndices = requestRecordMap[200:894]
elif foldName == 'Auxiliary1':
testIndices = requestRecordMap[0:100]
validationIndices = requestRecordMap[100:200]
trainIndices = requestRecordMap[200::]
elif foldName == 'Auxiliary2':
testIndices = requestRecordMap[0:100]
validationIndices = requestRecordMap[300:400]
trainIndices = requestRecordMap[100:300]
trainIndices.extend(requestRecordMap[400::])
elif foldName == 'Auxiliary3':
testIndices = requestRecordMap[0:100]
validationIndices = requestRecordMap[600:700]
trainIndices = requestRecordMap[100:600]
trainIndices.extend(requestRecordMap[700::])
elif foldName == 'Auxiliary4':
testIndices = requestRecordMap[0:100]
validationIndices = requestRecordMap[894::]
trainIndices = requestRecordMap[100:894]
#########
recordList = list(filter(lambda x: os.path.isdir(dataPath + x),
os.listdir(dataPath)))
trainRecordList = [recordList[ind] for ind in trainIndices]
validationRecordList = [recordList[ind] for ind in validationIndices]
testRecordList = [recordList[ind] for ind in testIndices]
# Small test to make sure the sets are non overlapping and use all of the data
areUnique = len(list(set(trainRecordList).intersection(set(validationRecordList).intersection(testRecordList)))) == 0
isComplete = len(list(set(trainRecordList).union(set(validationRecordList).union(testRecordList)).union(set(recordList)))) == len(recordList)
print('Uniqueness Test: ' + str(areUnique) + ' Completeness Test: ' + str(isComplete))
print('////////////////////\n')
return trainRecordList, validationRecordList, testRecordList
def computeUnseenRecords(dataPath):
"""
"""
recordList = filter(lambda x: os.path.isdir(dataPath + x),
os.listdir(dataPath))
return list(recordList)
#dataPath='/mnt/HD/Physionet2018_SourceFiles/training/'
#trainRecordList, validationRecordList, testRecordList = computeTrainValidationTestRecords(dataPath, foldName='Auxiliary1')
dataPath='/mnt/HD/Physionet2018_SourceFiles/unseen/'
testRecordList = computeUnseenRecords(dataPath)
for record in testRecordList:
print('Computing Record: ' + str(record))
sourcePath = dataPath + record + '/' + record + '.mat'
destinationPath = './' + record + '.mat'
cmdString = 'cp ' + str(sourcePath) + ' ' + str(destinationPath)
subprocess.call(cmdString, shell=True)
cmdString = 'export PATH="/home/matthp/anaconda3/bin/:$PATH"; source activate condaVirtualEnv3; bash next.sh ' + record
subprocess.call(cmdString, shell=True)
os.remove(destinationPath)