def datasetFillFERA2015(dsFolder, feraImageFolder, auCodingFolder, config, vperc=0.3, vseed=0): print "Looking for the following AU: {0}".format( config["SEARCH_LIST"] ) # Configuration Details # These are the AU you are looking for # auList = [int(x) for x in config["SEARCH_LIST"].split(",")] auList = config["SEARCH_LIST"] limits = {} limits["train"] = extractImageLimits(config, auList, True) limits["valid"] = extractImageLimits(config, auList, False)["valid"] print "Limits for training: {}".format(limits["train"]) print "Limits for validation: {}".format(limits["valid"]) #Read in FACS info [] in the format (path, fileName) processCount = 0 for (path, fileName) in locateFile("*.csv", auCodingFolder): processCount += 1 count = 1 # process all AuCoding into a single dataset for (path, fileName) in locateFile("*.csv", auCodingFolder): info = fileName.replace(".csv", "").split("_") subject = info[0] shot = info[1] imageSearchPath = join(feraImageFolder, subject, shot) print "[%3d /%3d] Processing Subject: %s Set: %s"%(count, processCount, subject, shot) # Read in FACS Info File facsAuInfo = readFERA2015AUCoding(os.path.join(path, fileName)) # need to find smallest + largest file (for padding mystery) # since some files are label 312.jpg and others 0312.jpg maxLength = findMaxDigits(imageSearchPath) for auDetails in facsAuInfo: # Check that one of the AU is at least present or not present (just not unknown) auPresent = [au for au in auList if au in auDetails.presentAU] auNotPresent = [au for au in auList if au in auDetails.notPresentAU] if len(auPresent) > 0 or len(auNotPresent) > 0: imageFile = "{}.jpg".format(auDetails.imageFileRef).rjust(maxLength, "0") image2Copy = join(imageSearchPath, locateFirstFile(imageFile, imageSearchPath)) # Next Image goes to... if (random.random() <= vperc) and (limits["valid"] > 0): # Copy image into root of Validation /images folder picFileDest = "{}_{}_{}".format(subject, shot, os.path.basename(image2Copy)) dest = join(dsFolder, join(config['VALIDATION_IMAGES'], picFileDest)) copyImageFile(picFileDest, dest) # Copy AU information for later validation validationDataPath = join(dsFolder, join(config['VALIDATION_DATA'], picFileDest)) writeValidationData(validationDataPath, auDetails.presentAU, True) limits["valid"] = limits["valid"] - 1 else: checkAuSetLimits = False for au in auList: if au in auDetails.notPresentAU: # First find images which are NOT the AU you are looking for currentAUCount = limits["train"]["NotAU{}".format(au)] if (currentAUCount != 0): copyFile(image2Copy, subject, shot, "NotAU{}".format(au), dsFolder, config, "train", auDetails.presentAU) currentAUCount = currentAUCount - 1 limits["train"]["NotAU{}".format(au)] = currentAUCount if currentAUCount == 0: checkAuSetLimits = True elif au in auDetails.presentAU: # Next find images which are the AU you are looking for currentAUCount = limits["train"]["AU{}".format(au)] if (currentAUCount != 0): copyFile(image2Copy, subject, shot, "AU{}".format(au), dsFolder, config, "train", auDetails.presentAU) currentAUCount = currentAUCount - 1 limits["train"]["AU{}".format(au)] = currentAUCount if currentAUCount == 0: checkAuSetLimits = True # Check if search limit for AU reached, then remove if (checkAuSetLimits): removeAu = [] for au in auList: if (limits["train"]["AU{}".format(au)] == 0) and (limits["valid"]["AU{}".format(au)] == 0) and (limits["train"]["NotAU{}".format(au)] == 0) and (limits["valid"]["NotAU{}".format(au)] == 0): removeAu.append(au) for au in removeAu: auList.remove(au); print "No Longer looking for .... AU: {}".format(au) if (len(auList) == 0): print "Finished..." return count += 1
def findMaxDigits(searchPath): fileName = locateFirstFile("*.jpg", searchPath) if (fileName == None): return 0 else: return len( fileName )
def datasetFillFERA2015(dsFolder, feraImageFolder, auCodingFolder, config, vperc=0.3, vseed=0): print "Looking for the following AU: {0}".format(config["SEARCH_LIST"]) # Configuration Details # These are the AU you are looking for # auList = [int(x) for x in config["SEARCH_LIST"].split(",")] auList = config["SEARCH_LIST"] limits = {} limits["train"] = extractImageLimits(config, auList, True) limits["valid"] = extractImageLimits(config, auList, False)["valid"] print "Limits for training: {}".format(limits["train"]) print "Limits for validation: {}".format(limits["valid"]) #Read in FACS info [] in the format (path, fileName) processCount = 0 for (path, fileName) in locateFile("*.csv", auCodingFolder): processCount += 1 count = 1 # process all AuCoding into a single dataset for (path, fileName) in locateFile("*.csv", auCodingFolder): info = fileName.replace(".csv", "").split("_") subject = info[0] shot = info[1] imageSearchPath = join(feraImageFolder, subject, shot) print "[%3d /%3d] Processing Subject: %s Set: %s" % ( count, processCount, subject, shot) # Read in FACS Info File facsAuInfo = readFERA2015AUCoding(os.path.join(path, fileName)) # need to find smallest + largest file (for padding mystery) # since some files are label 312.jpg and others 0312.jpg maxLength = findMaxDigits(imageSearchPath) for auDetails in facsAuInfo: # Check that one of the AU is at least present or not present (just not unknown) auPresent = [au for au in auList if au in auDetails.presentAU] auNotPresent = [ au for au in auList if au in auDetails.notPresentAU ] if len(auPresent) > 0 or len(auNotPresent) > 0: imageFile = "{}.jpg".format(auDetails.imageFileRef).rjust( maxLength, "0") image2Copy = join(imageSearchPath, locateFirstFile(imageFile, imageSearchPath)) # Next Image goes to... if (random.random() <= vperc) and (limits["valid"] > 0): # Copy image into root of Validation /images folder picFileDest = "{}_{}_{}".format( subject, shot, os.path.basename(image2Copy)) dest = join(dsFolder, join(config['VALIDATION_IMAGES'], picFileDest)) copyImageFile(picFileDest, dest) # Copy AU information for later validation validationDataPath = join( dsFolder, join(config['VALIDATION_DATA'], picFileDest)) writeValidationData(validationDataPath, auDetails.presentAU, True) limits["valid"] = limits["valid"] - 1 else: checkAuSetLimits = False for au in auList: if au in auDetails.notPresentAU: # First find images which are NOT the AU you are looking for currentAUCount = limits["train"]["NotAU{}".format( au)] if (currentAUCount != 0): copyFile(image2Copy, subject, shot, "NotAU{}".format(au), dsFolder, config, "train", auDetails.presentAU) currentAUCount = currentAUCount - 1 limits["train"]["NotAU{}".format( au)] = currentAUCount if currentAUCount == 0: checkAuSetLimits = True elif au in auDetails.presentAU: # Next find images which are the AU you are looking for currentAUCount = limits["train"]["AU{}".format(au)] if (currentAUCount != 0): copyFile(image2Copy, subject, shot, "AU{}".format(au), dsFolder, config, "train", auDetails.presentAU) currentAUCount = currentAUCount - 1 limits["train"]["AU{}".format( au)] = currentAUCount if currentAUCount == 0: checkAuSetLimits = True # Check if search limit for AU reached, then remove if (checkAuSetLimits): removeAu = [] for au in auList: if (limits["train"]["AU{}".format(au)] == 0) and ( limits["valid"]["AU{}".format(au)] == 0 ) and (limits["train"]["NotAU{}".format(au)] == 0 ) and (limits["valid"]["NotAU{}".format(au)] == 0): removeAu.append(au) for au in removeAu: auList.remove(au) print "No Longer looking for .... AU: {}".format( au) if (len(auList) == 0): print "Finished..." return count += 1