def loadData(self, dataFolder, augment):
        def shuffle_unison(a, b):
            assert len(a) == len(b)
            p = numpy.random.permutation(len(a))
            return a[p], b[p]

        assert (not dataFolder == None
                or not dataFolder == ""), "Empty Data Folder!"

        dataX = []
        dataLabels = []
        classesDictionary = []

        gestures = self.orderClassesFolder(dataFolder + "/")
        self.logManager.write("Gestures reading order: " + str(gestures))

        lastImage = None

        numberOfVideos = 0
        gestureNumber = 0
        for e in gestures:

            gestureNumber = gestureNumber + 1
            loadedDataPoints = 0
            classesDictionary.append("'" + str(gestureNumber) + "':'" +
                                     str(e) + "',")

            numberOfVideos = numberOfVideos + 1

            time = datetime.datetime.now()

            #print dataFolder + "/" + v+"/"+dataPointLocation
            dataFrames = self.orderDataFolder(dataFolder + "/" + e)
            for dataFrame in dataFrames:
                dataPoint = self.preProcess(
                    dataFolder + "/" + e + "/" + dataFrame, augment)

                dataX.append(dataPoint)
                dataLabels.append(gestureNumber - 1)
                loadedDataPoints = loadedDataPoints + 1

            self.logManager.write("--- Gestures: " + str(e) + "(" +
                                  str(loadedDataPoints) + " Data points - " +
                                  str((datetime.datetime.now() -
                                       time).total_seconds()) + " seconds" +
                                  ")")

        dataLabels = np_utils.to_categorical(dataLabels, gestureNumber)

        dataX = numpy.array(dataX)

        print "Shape Labels:", dataLabels.shape
        print "Shape DataX:", dataX.shape

        dataX, dataLabels = shuffle_unison(dataX, dataLabels)

        dataX = numpy.array(dataX)
        dataLabels = numpy.array(dataLabels)

        return Data.Data(dataX, dataLabels, classesDictionary)
Exemplo n.º 2
0
    def loadData(self, dataFolder):
        def shuffle_unison(a, b):
            assert len(a) == len(b)
            p = numpy.random.permutation(len(a))
            return a[p], b[p]

        assert (not dataFolder == None
                or not dataFolder == ""), "Empty Data Folder!"

        dataX = []
        dataLabels = []
        classesDictionary = []

        emotions = self.orderClassesFolder(dataFolder + "/")
        self.logManager.write("Emotions reading order: " + str(emotions))

        emotionNumber = 0
        for e in emotions:
            if not e == "Surprised":
                emotionNumber = emotionNumber + 1
                loadedDataPoints = 0
                classesDictionary.append("'" + str(emotionNumber) + "':'" +
                                         str(e) + "',")

                time = datetime.datetime.now()

                audios = os.listdir(dataFolder + "/" + e + "/")

                for audio in audios:

                    dataPoint = self.preProcess(dataFolder + "/" + e + "/" +
                                                audio)

                    for audio in dataPoint:
                        dataX.append(audio)
                        dataLabels.append(emotionNumber - 1)
                        loadedDataPoints = loadedDataPoints + 1

                self.logManager.write("--- Emotion: " + str(e) + "(" +
                                      str(loadedDataPoints) +
                                      " Data points - " +
                                      str((datetime.datetime.now() -
                                           time).total_seconds()) +
                                      " seconds" + ")")

        dataLabels = np_utils.to_categorical(dataLabels, emotionNumber)

        dataX = numpy.array(dataX)

        dataX, dataLabels = shuffle_unison(dataX, dataLabels)

        dataX = numpy.array(dataX)
        dataLabels = numpy.array(dataLabels)

        return Data.Data(dataX, dataLabels, classesDictionary)
    def loadData(self, dataFolder, labelDirectory, augmentData):

        assert (not dataFolder == None
                or not dataFolder == ""), "Empty Data Folder!"

        dataX = []
        dataLabels = []
        classesDictionary = []

        labelsFile = open(labelDirectory, "r")

        classesDictionary.append("Neutral:0")
        classesDictionary.append("Happiness:1")
        classesDictionary.append("Surprise:2")
        classesDictionary.append("Sadness:3")
        classesDictionary.append("Anger:4")
        classesDictionary.append("Disgust:5")
        classesDictionary.append("Fear:6")
        classesDictionary.append("Contempt:7")

        time = datetime.datetime.now()
        for line in labelsFile:
            lineSplitted = line.split(",")

            fileName = lineSplitted[0]
            labelDistribution = [float(i) for i in lineSplitted[5:13]]
            dataPoint = self.preProcess(dataFolder + "/" + fileName,
                                        augmentData)

            if augmentData:
                for dp in dataPoint:
                    dataX.append(dp)
                    dataLabels.append(labelDistribution)
            else:
                dataX.append(dataPoint)
                dataLabels.append(labelDistribution)

        dataLabels = numpy.array(dataLabels)

        dataX = numpy.array(dataX)

        dataX = dataX.astype('float32')

        dataX, dataLabels = self.shuffleData(dataX, dataLabels)

        self.logManager.write("--- Folder: " + dataFolder + "(" +
                              str((datetime.datetime.now() -
                                   time).total_seconds()) + " seconds" + ")")
        dataX = numpy.array(dataX)
        dataLabels = numpy.array(dataLabels)

        return Data.Data(dataX, dataLabels, classesDictionary)
    def loadData(self, dataFolder, dataFile):
        def shuffle_unison(a, b):
            assert len(a) == len(b)
            p = numpy.random.permutation(len(a))
            return a[p], b[p]

        dataX = []
        dataLabels = []
        classesDictionary = []

        time = datetime.datetime.now()
        with open(dataFile, 'rb') as csvfile:
            #print "Reading From:", dataFile
            # raw_input(("here"))
            reader = csv.reader(csvfile)
            rownum = 0
            for row in reader:
                # print "Row:", row
                if not len(row) == 0:
                    if rownum >= 1:

                        video = row[3]
                        utterance = row[4]
                        arousal = row[5]
                        valence = row[6]
                        readFrom = dataFolder + "/" + video + "/video/" + utterance
                        imageFaces = os.listdir(readFrom)
                        shuffle(imageFaces)
                        imageFaces = imageFaces[0:10]

                        for imageName in imageFaces:
                            try:
                                dataPoint = self.preProcess(
                                    readFrom + "/" + imageName, False)
                                dataX.append(dataPoint)
                                dataLabels.append(
                                    [float(arousal),
                                     float(valence)])
                            except:
                                print "problem:", readFrom + "/" + imageName

                rownum = rownum + 1
        dataX = numpy.array(dataX)
        dataLabels = numpy.array(dataLabels)
        self.logManager.write("(" + str(len(dataX)) + " Data points - " +
                              str((datetime.datetime.now() -
                                   time).total_seconds()) + " seconds" + ")")

        dataX, dataLabels = shuffle_unison(dataX, dataLabels)

        return Data.Data(dataX, dataLabels, classesDictionary)
Exemplo n.º 5
0
    def loadData(self, dataFolder, dataFile):
        def shuffle_unison(a, b):
            assert len(a) == len(b)
            p = numpy.random.permutation(len(a))
            return a[p], b[p]

        dataX = []
        dataLabels = []
        classesDictionary = []

        time = datetime.datetime.now()
        with open(dataFile, 'rb') as csvfile:

            reader = csv.reader(csvfile)
            rownum = 0
            for row in reader:

                if not len(row) == 0:
                    if rownum >= 1:

                        video = row[3]
                        utterance = row[4]
                        arousal = row[5]
                        valence = row[6]
                        readFrom = dataFolder + "/" + video + "/audio/" + utterance + "/audio.wav"
                        dataPoint = self.preProcess(readFrom)

                        for audio in dataPoint:
                            dataX.append(audio)
                            dataLabels.append([float(arousal), float(valence)])

                rownum = rownum + 1
        dataX = numpy.array(dataX)
        dataLabels = numpy.array(dataLabels)
        self.logManager.write("(" + str(len(dataX)) + " Data points - " +
                              str((datetime.datetime.now() -
                                   time).total_seconds()) + " seconds" + ")")

        dataX, dataLabels = shuffle_unison(dataX, dataLabels)

        return Data.Data(dataX, dataLabels, classesDictionary)
Exemplo n.º 6
0
    def loadData(self, dataFolder, augment):

        def shuffle_unison(a, b):
            assert len(a) == len(b)
            p = numpy.random.permutation(len(a))
            return a[p], b[p]

        assert (not dataFolder == None or not dataFolder == ""), "Empty Data Folder!"

        dataX = []
        dataLabels = []
        classesDictionary = []

        objects = self.orderClassesFolder(dataFolder + "/")
        self.logManager.write("Objects reading order: " + str(objects))

        lastImage = None

        numberOfVideos = 0
        emotionNumber = 0
        for e in objects:
            # if numberOfVideos < 5:
            emotionNumber = emotionNumber + 1
            loadedDataPoints = 0
            classesDictionary.append("'" + str(emotionNumber) + "':'" + str(e) + "',")

            numberOfVideos = numberOfVideos + 1

            time = datetime.datetime.now()

            # print dataFolder + "/" + v+"/"+dataPointLocation

            dataFrames = self.orderDataFolder(dataFolder + "/" + e)
            for dataFrame in dataFrames:
                try:
                    dataPoint = self.preProcess(dataFolder + "/" + e + "/" + dataFrame,
                                                augment)
                    if augment:
                        lastImage = dataPoint[0]
                    else:
                        lastImage = dataPoint
                except:
                    print "Error:", dataFolder + "/" + e + "/" + dataFrame
                    if augment:
                        dataPoint = [lastImage]
                    else:
                        dataPoint = lastImage

                dataX.append(dataPoint)
                dataLabels.append(emotionNumber - 1)
                loadedDataPoints = loadedDataPoints + 1

            self.logManager.write(
                "--- Position: " + str(e) + "(" + str(loadedDataPoints) + " Data points - " + str(
                    (datetime.datetime.now() - time).total_seconds()) + " seconds" + ")")

        # print "Labels before:", dataLabels
        dataLabels = np_utils.to_categorical(dataLabels, emotionNumber)
        # print "Labels After:", dataLabels
        dataX = numpy.array(dataX)
        # dataX = numpy.swapaxes(dataX, 1, 2)

        # print "Shape Labels:", dataLabels.shape
        # print "Shape DataX:", dataX.shape
        # dataLabels = numpy.array(dataLabels).reshape((len(dataLabels), 2))

        #        dataX = dataX.astype('float32')


        dataX, dataLabels = shuffle_unison(dataX, dataLabels)

        #        print "dataX shape:", numpy.array(dataX).shape
        # raw_input("here")

        dataX = numpy.array(dataX)
        dataLabels = numpy.array(dataLabels)

        return Data.Data(dataX, dataLabels, classesDictionary)
    def loadData(self, dataLipsFolder, dataArmsFolder, dataSoundFolder, dataParticipantsFolder,participantNumbers, augmentData):

        def shuffle_unison(a, b):
            assert len(a) == len(b)
            p = numpy.random.permutation(len(a))
            return a[p], b[p]

        assert (not dataParticipantsFolder == None or not dataParticipantsFolder == ""), "Empty Participants Folder!"

        dataX = []
        dataLabels = []



        readingFrom = ""
        participantsCSVs = os.listdir(dataParticipantsFolder)
        participantNumber = 0
        for participantCSV in participantsCSVs:
            loadedDataPoints = 0
            time = datetime.datetime.now()
            if participantNumber in participantNumbers:

                with open(dataParticipantsFolder+"/"+ participantCSV, 'rb') as csvfile:
                    readingFrom = dataParticipantsFolder+"/"+ participantCSV
                    #print "Reading From:", readingFrom
                    #raw_input(("here"))
                    reader = csv.reader(csvfile)
                    rownum = 0
                    for row in reader:
                        #print "Row:", row
                        if rownum >= 1:

                          #print "Row:", row
                          audioLabel = row[6]
                          lipsLabel = row[7]
                          armsLabel = row[8]
                          congruencyLabel = row[9]
                          conditionLabel = row[10]
                          phonemeLabel = row[-2]
                          decisionLabel = row[-1]

                          if not decisionLabel == "Na":
                                # partialLabel = str(audioLabel) + "_" + str(lipsLabel) + "_" + str(
                                #   armsLabel) + "_" + str(congruencyLabel) + "_" + str(conditionLabel) + "_" + str(
                                #   phonemeLabel)

                                partialLabel = str(audioLabel) + "_" + str(lipsLabel) + "_" + str(
                                    armsLabel)


                                #Load Arms
                                armsFolderList = os.listdir(dataArmsFolder +"/"+str(armsLabel)+"/")

                                matchingarms = [s for s in armsFolderList if partialLabel in s]
                                shuffle(matchingarms)

                                armDataPoint = self.preProcess(dataArmsFolder +"/"+str(armsLabel)+"/"+matchingarms[0],imageSize=(80,60), grayScale=True, augment=False)


                                #Load Lips
                                lipsFolderList = os.listdir(dataLipsFolder+"/"+str(lipsLabel)+"/")
                                matchingLips = [s for s in lipsFolderList if partialLabel in s]
                                shuffle(matchingLips)

                                lipsImagesList = self.orderDataFolder(dataLipsFolder+"/"+str(lipsLabel)+"/"+matchingLips[0])
                                lipsDataPoint = []
                                for lipsImage in lipsImagesList:
                                    #print "Opening:", dataLipsFolder + "/" + str(lipsLabel) + "/" + matchingLips[0] + "/" + lipsImage
                                    lipDataPoint = self.preProcess(
                                        dataLipsFolder + "/" + str(lipsLabel) + "/" + matchingLips[0] + "/" + lipsImage,
                                        imageSize=(120, 120), grayScale=True, augment=False)
                                    lipsDataPoint.append(lipDataPoint)

                                lipsDataPoint = numpy.array(lipsDataPoint)
                                lipsDataPoint = lipsDataPoint.squeeze(axis=1)

                                #Load Sound

                                soundFolderList = os.listdir(dataSoundFolder + "/" + str(audioLabel) + "/")
                                matchingAudio = [s for s in soundFolderList if partialLabel in s]
                                shuffle(matchingAudio)

                                # print "Sounds:", matchingAudio
                                # print "List:", dataSoundFolder + "/" + str(audioLabel) + "/"
                                # print "Label:", partialLabel
                                # print "Opening:", dataSoundFolder + "/" + str(audioLabel) + "/"+matchingAudio[0]

                                audioDataPoint = self.preProcessAudio(dataSoundFolder + "/" + str(audioLabel) + "/"+matchingAudio[0])[0]


                                # print "Shape Arms:", armDataPoint.shape
                                # print "Shape Lips:", lipsDataPoint.shape
                                # print "Shape Audio:", audioDataPoint.shape
                                # print "Label:", decisionLabel


                                dataX.append([numpy.array(armDataPoint).astype('float32'), numpy.array(lipsDataPoint).astype('float32'),numpy.array(audioDataPoint).astype('float32')])
                                dataLabels.append(int(decisionLabel)-1)
                                loadedDataPoints = loadedDataPoints+1

                        rownum += 1
                        # if rownum == 30:
                        #     break
                self.logManager.write(
                                        "--- Participant: " + str(participantNumber) + "(" + str(
                                            loadedDataPoints) + " Data points - " + str(
                                            (datetime.datetime.now() - time).total_seconds()) + " seconds" + ")")


            participantNumber = participantNumber + 1



        dataLabels = np_utils.to_categorical(dataLabels, 4)


        dataX = numpy.array(dataX)
        #print "dataX shape:", numpy.array(dataX).shape
        # dataX = numpy.swapaxes(dataX, 1, 2)
        #dataX = numpy.squeeze(dataX, axis=2)

        # dataLabels = numpy.array(dataLabels).reshape((len(dataLabels), 2))

 #       print "Shape DataX:", dataX.shape
#        dataX = dataX.astype('float32')

        #dataX, dataLabels = shuffle_unison(dataX, dataLabels)

        print "dataX shape:", numpy.array(dataX).shape
        print "dataY shape:", numpy.array(dataLabels).shape
        # raw_input("here")

        dataX = numpy.array(dataX)
        dataLabels = numpy.array(dataLabels)

        return Data.Data(dataX, dataLabels, []), readingFrom
Exemplo n.º 8
0
    def loadData(self, dataFolder, augment):
        def shuffle_unison(a, b):
            assert len(a) == len(b)
            p = numpy.random.permutation(len(a))
            return a[p], b[p]

        assert (not dataFolder == None
                or not dataFolder == ""), "Empty Data Folder!"

        dataX = []
        dataLabels = []
        classesDictionary = []

        classes = self.orderClassesFolder(dataFolder + "/")
        self.logManager.write("Videos reading order: " + str(classes))

        lastImage = None

        numberOfVideos = 0
        classNumber = 0
        for c in classes:
            videos = self.orderClassesFolder(dataFolder + "/" + str(c) + "/")
            loadedDataPoints = 0
            time = datetime.datetime.now()

            for v in videos:

                # if numberOfVideos < 5:
                numberOfVideos = numberOfVideos + 1

                # print dataFolder + "/" + v+"/"+dataPointLocation
                dataFrames = self.orderDataFolder(dataFolder + "/" + str(c) +
                                                  "/" + v)
                sequenceFrames = []

                for i in range(len(dataFrames)):
                    dataFrame = dataFrames[i]

                    try:
                        dataPoint = self.preProcess(
                            dataFolder + "/" + str(c) + "/" + v + "/" +
                            dataFrame, augment)

                        if augment:
                            lastImage = dataPoint[0]
                        else:
                            lastImage = dataPoint
                    except:
                        print "Error:", dataFolder + "/" + str(
                            c) + "/" + v + "/" + dataFrame

                        if augment:
                            dataPoint = [lastImage]
                        else:
                            dataPoint = lastImage
                    #print "DataPoint Shape:", dataPoint.shape
                    sequenceFrames.append(dataPoint)

                sequenceFrames = numpy.array(sequenceFrames)
                # print "Shape:", sequenceFrames.shape
                dataX.append(sequenceFrames)
                dataLabels.append(classNumber)
                loadedDataPoints = loadedDataPoints + 1

            classNumber = classNumber + 1

            self.logManager.write("--- Arm Position: " + str(c) + "(" +
                                  str(loadedDataPoints) + " Data points - " +
                                  str((datetime.datetime.now() -
                                       time).total_seconds()) + " seconds" +
                                  ")")

        dataLabels = np_utils.to_categorical(dataLabels, classNumber)

        dataX = numpy.array(dataX)
        print "dataX shape:", numpy.array(dataX).shape
        # dataX = numpy.swapaxes(dataX, 1, 2)
        dataX = numpy.squeeze(dataX, axis=2)

        # dataLabels = numpy.array(dataLabels).reshape((len(dataLabels), 2))

        dataX = dataX.astype('float32')

        dataX, dataLabels = shuffle_unison(dataX, dataLabels)

        print "dataX shape:", numpy.array(dataX).shape
        print "dataY shape:", numpy.array(dataLabels).shape
        # raw_input("here")

        dataX = numpy.array(dataX)
        dataLabels = numpy.array(dataLabels)

        return Data.Data(dataX, dataLabels, classesDictionary)