def fillPath(self, baseFolderName, folderName):
     'Returns a function that expands a fileName into a filePath'
     # Make sure that folderName is valid
     match = pattern_name.match(folderName)
     if not match: raise FolderError('Invalid name: %s\n%s' % (folderName, 'Names can have letters, digits, underscores, hyphens, spaces, parentheses, commas and periods.'))
     # Fill path
     baseFolderPath = store.makeFolderSafely(self.folderPathByName[baseFolderName])
     stampedFolderName = '%s-%s' % (store.makeTimestamp(), folderName)
     folderPath = store.makeFolderSafely(os.path.join(baseFolderPath, stampedFolderName))
     # Return
     return lambda fileName: os.path.join(folderPath, fileName)
 def fillPath(self, baseFolderName, folderName):
     # Make sure that folderName is valid
     match = pattern_name.match(folderName)
     if not match: 
         explanation = 'Names can have letters, digits, underscores, hyphens, spaces, parentheses, commas and periods.'
         raise FolderError('Invalid name: %s\n%s' % (folderName, explanation))
     # Fill path
     baseFolderPath = store.makeFolderSafely(self.folderPathByName[baseFolderName])
     template = templateByFolderName[baseFolderName]
     fileName = fileNameByFolderName[baseFolderName]
     folderPath = os.path.join(baseFolderPath, template % (store.makeTimestamp(), folderName))
     filePath = os.path.join(store.makeFolderSafely(folderPath), fileName)
     # Return
     return filePath
示例#3
0
 def fillPath(self, baseFolderName, folderName):
     'Returns a function that expands a fileName into a filePath'
     # Make sure that folderName is valid
     match = pattern_name.match(folderName)
     if not match:
         raise FolderError('Invalid name: %s\n%s' % (
             folderName,
             'Names can have letters, digits, underscores, hyphens, spaces, parentheses, commas and periods.'
         ))
     # Fill path
     baseFolderPath = store.makeFolderSafely(
         self.folderPathByName[baseFolderName])
     stampedFolderName = '%s-%s' % (store.makeTimestamp(), folderName)
     folderPath = store.makeFolderSafely(
         os.path.join(baseFolderPath, stampedFolderName))
     # Return
     return lambda fileName: os.path.join(folderPath, fileName)
def train(targetClassifierPath, trainingPath, testPath, parameterByName):
    # Set paths
    temporaryFolder = tempfile.mkdtemp()
    trainingSamplePath, trainingLabelPath = makeSampleLabelPaths(trainingPath)
    testSamplePath, testLabelPath = makeSampleLabelPaths(testPath)
    # Make layer combinations
    ratioRange = store.unstringifyFloatList(parameterByName['ratio range'])
    kernelRange = store.unstringifyIntegerList(parameterByName['kernel range'])
    samplePixelLength = getSamplePixelLength(testPath)
    layerCombinations = makeLayerCombinations(samplePixelLength, ratioRange, kernelRange)
    length0, ratio0, length1, ratio1 = layerCombinations[parameterByName['which layer combination']]
    # Convert connection tables if necessary
    connectionTable0Path = verifyConnectionTable(parameterByName['connection table0 path'])
    connectionTable1Path = verifyConnectionTable(parameterByName['connection table1 path'])
    # Run
    timestamp = store.makeTimestamp()
    runLush('trainClassifier', trainingSamplePath, trainingLabelPath, testSamplePath, testLabelPath,
        length0, ratio0, connectionTable0Path,
        length1, ratio1, connectionTable1Path,
        parameterByName['hidden count'], parameterByName['iteration count'], 
        os.path.join(temporaryFolder, timestamp))
    errorPacks = getClassifierPacksByTimestamp(temporaryFolder, timestamp)
    # Save the best classifier
    bestTestPercentError, bestTrainingPercentError, bestIterationIndex, bestClassifierPath = errorPacks[0]
    parameterByName.update(length0=length0, ratio0=ratio0, length1=length1, ratio1=ratio1)
    shutil.copy(bestClassifierPath, targetClassifierPath)
    shutil.rmtree(temporaryFolder)
    # Evaluate
    resultByName = evaluate(targetClassifierPath, testPath)
    resultByName['iteration index'] = bestIterationIndex
    resultByName['iteration history'] = errorPacks
    resultByName['sample pixel length'] = samplePixelLength
    resultByName['layer combinations'] = layerCombinations
    resultByName['layer combination count'] = len(layerCombinations)
    # Plot
    plotIterationHistory(targetClassifierPath, errorPacks)
    # Return
    return resultByName