def test(): classifierLocation = "/home/amb/dev/mrf/classifiers/logisticRegression/superpixel/logReg_miniMSRC.pkl" classifier = pomio.unpickleObject(classifierLocation) carFile = "7_3_s.bmp" msrcData = "/home/amb/dev/mrf/data/MSRC_ObjCategImageDatabase_v2" car = pomio.msrc_loadImages(msrcData, ["Images/" + carFile])[0] groundTruth = car.m_gt mask = superPixels.getSuperPixels_SLIC(car.m_img, 400, 10) spLabels = SuperPixelClassifier.predictSuperPixelLabels( classifier, car.m_img, 400, 10, True)[0] prediction = SuperPixelClassifier.getSuperPixelLabelledImage( car.m_img, mask, spLabels) # save prediction to file pomio.writeMatToCSV(prediction, "/home/amb/dev/mrf/eval/testPrediction1.labels") results = evaluatePrediction(prediction, groundTruth, carFile) print "\nINFO: Car test eval results::\n\t", results classResults = evaluateClassPerformance(prediction, groundTruth) print "\nINFO: Car test eval class results::\n\t", classResults confusionResults = evaluateConfusionMatrix(prediction, groundTruth) print "\nINFO: Car test eval confusion matrix results::\n\t", "Just sum up entries... ", np.sum( confusionResults)
def test(): # TODO use reference classifier classifierName = "/home/amb/dev/mrf/classifiers/randomForest/superpixel/randyForest_superPixel_maxDepth15_0.6Data.pkl" classifier = pomio.unpickleObject(classifierName) carFile = "7_3_s.bmp" msrcData = "/home/amb/dev/mrf/data/MSRC_ObjCategImageDatabase_v2" car = pomio.msrc_loadImages(msrcData, ["Images/" + carFile])[0] groundTruth = car.m_gt mask = SuperPixels.getSuperPixels_SLIC(car.m_img, 400, 10) spLabels = SuperPixelClassifier.predictSuperPixelLabels( classifier, car.m_img, 400, 10)[0] prediction = SuperPixelClassifier.getSuperPixelLabelledImage( car.m_img, mask, spLabels) # save prediction to file pomio.writeMatToCSV( prediction, "/home/amb/dev/eval/test/predict/testPrediction1.labels") results = evaluatePrediction(prediction, groundTruth) print "\nINFO: Car test eval results::\n\t", results
def test(): # TODO use reference classifier classifierName = "/home/amb/dev/mrf/classifiers/randomForest/superpixel/randyForest_superPixel_maxDepth15_0.6Data.pkl" classifier = pomio.unpickleObject(classifierName) carFile = "7_3_s.bmp" msrcData = "/home/amb/dev/mrf/data/MSRC_ObjCategImageDatabase_v2" car = pomio.msrc_loadImages(msrcData , [ "Images/" + carFile ] )[0] groundTruth = car.m_gt mask = SuperPixels.getSuperPixels_SLIC(car.m_img, 400, 10) spLabels = SuperPixelClassifier.predictSuperPixelLabels(classifier, car.m_img,400,10)[0] prediction = SuperPixelClassifier.getSuperPixelLabelledImage(car.m_img, mask, spLabels) # save prediction to file pomio.writeMatToCSV(prediction, "/home/amb/dev/eval/test/predict/testPrediction1.labels") results = evaluatePrediction(prediction, groundTruth) print "\nINFO: Car test eval results::\n\t" , results
def createAndSaveFeatureLabelData( msrcData, outfileBase, dataType, outfileType, nbSuperPixels, superPixelCompactness ): if dataType == None or dataType == "": outfileFtrs = '%s_ftrs.%s' % ( outfileBase, outfileType ) outfileLabs = '%s_labs.%s' % ( outfileBase, outfileType ) outfileAdj = '%s_adj.%s' % ( outfileBase, outfileType ) else: outfileFtrs = '%s_%s_ftrs.%s' % ( outfileBase, dataType, outfileType ) outfileLabs = '%s_%s_labs.%s' % ( outfileBase, dataType, outfileType ) outfileAdj = '%s_%s_adj.%s' % ( outfileBase, dataType, outfileType ) # Check can write these files. f=open(outfileFtrs,'w') f.close() f=open(outfileLabs,'w') f.close() # Edited getSuperPixelTrainingData to allow user-defined data split ratios superPixelData = SuperPixelClassifier.getSuperPixelData(msrcData,nbSuperPixels,superPixelCompactness) superPixelFeatures = superPixelData[0] superPixelLabels = superPixelData[1].astype(np.int32) superPixelClassAdj = superPixelData[2] assert np.all( np.isfinite( superPixelFeatures ) ) #print superPixelClassAdj # Output if outfileType == 'pkl': pomio.pickleObject( superPixelFeatures, outfileFtrs ) pomio.pickleObject( superPixelLabels, outfileLabs ) pomio.pickleObject( superPixelClassAdj, outfileAdj ) elif outfileType == 'csv': pomio.writeMatToCSV( superPixelFeatures, outfileFtrs ) pomio.writeMatToCSV( superPixelLabels, outfileLabs ) pomio.writeMatToCSV( superPixelClassAdj, outfileAdj ) else: assert False, 'unknown output file format ' + outfileType print 'Output written to file ', outfileFtrs, ' and ', outfileLabs, ' and ', outfileAdj
def createAndSaveFeatureLabelData(msrcData, outfileBase, dataType, outfileType, nbSuperPixels, superPixelCompactness): if dataType == None or dataType == "": outfileFtrs = '%s_ftrs.%s' % (outfileBase, outfileType) outfileLabs = '%s_labs.%s' % (outfileBase, outfileType) outfileAdj = '%s_adj.%s' % (outfileBase, outfileType) else: outfileFtrs = '%s_%s_ftrs.%s' % (outfileBase, dataType, outfileType) outfileLabs = '%s_%s_labs.%s' % (outfileBase, dataType, outfileType) outfileAdj = '%s_%s_adj.%s' % (outfileBase, dataType, outfileType) # Check can write these files. f = open(outfileFtrs, 'w') f.close() f = open(outfileLabs, 'w') f.close() # Edited getSuperPixelTrainingData to allow user-defined data split ratios superPixelData = SuperPixelClassifier.getSuperPixelData( msrcData, nbSuperPixels, superPixelCompactness) superPixelFeatures = superPixelData[0] superPixelLabels = superPixelData[1].astype(np.int32) superPixelClassAdj = superPixelData[2] assert np.all(np.isfinite(superPixelFeatures)) #print superPixelClassAdj # Output if outfileType == 'pkl': pomio.pickleObject(superPixelFeatures, outfileFtrs) pomio.pickleObject(superPixelLabels, outfileLabs) pomio.pickleObject(superPixelClassAdj, outfileAdj) elif outfileType == 'csv': pomio.writeMatToCSV(superPixelFeatures, outfileFtrs) pomio.writeMatToCSV(superPixelLabels, outfileLabs) pomio.writeMatToCSV(superPixelClassAdj, outfileAdj) else: assert False, 'unknown output file format ' + outfileType print 'Output written to file ', outfileFtrs, ' and ', outfileLabs, ' and ', outfileAdj
def createAndSaveFeatureLabelData( msrcData, outfileBase, dataType, outfileType, nbSuperPixels, superPixelCompactness, ftype, aggtype, verbose ): if verbose: print "Creating feature set ", outfileBase if dataType == None or dataType == "": outfileFtrs = "%s_ftrs.%s" % (outfileBase, outfileType) outfileLabs = "%s_labs.%s" % (outfileBase, outfileType) else: outfileFtrs = "%s_%s_ftrs.%s" % (outfileBase, dataType, outfileType) outfileLabs = "%s_%s_labs.%s" % (outfileBase, dataType, outfileType) # Check can write these files. f = open(outfileFtrs, "w") f.close() f = open(outfileLabs, "w") f.close() if verbose: print " - computing superpixels" allSuperPixels = superPixels.computeSuperPixelGraphMulti( [z.m_img for z in msrcData], "slic", [nbSuperPixels, superPixelCompactness], nbCores=args.nbCores ) if verbose: print " - computing features" superPixelFeatures = features.computeSuperPixelFeaturesMulti( [z.m_img for z in msrcData], allSuperPixels, ftype, aggtype, asMatrix=True, nbCores=args.nbCores ) if verbose: print " - extracting labels" superPixelLabels = classification.computeSuperPixelLabelsMulti([z.m_gt for z in msrcData], allSuperPixels) assert np.all(np.isfinite(superPixelFeatures)) # Don't save features with void labels. good = superPixelLabels != pomio.getVoidIdx() if not np.all(good): if verbose: print " - discarding %d superpixels with void labels" % np.count_nonzero(np.logical_not(good)) superPixelLabels = superPixelLabels[good] superPixelFeatures = superPixelFeatures[good, :] if verbose: print " - writing %d feature vectors of dimension %d to output files" % ( superPixelFeatures.shape[0], superPixelFeatures.shape[1], ) # Output if outfileType == "pkl": pomio.pickleObject(superPixelFeatures, outfileFtrs) pomio.pickleObject(superPixelLabels, outfileLabs) elif outfileType == "csv": pomio.writeMatToCSV(superPixelFeatures, outfileFtrs) pomio.writeMatToCSV(superPixelLabels, outfileLabs) else: assert False, "unknown output file format " + outfileType print "Output written to file ", outfileFtrs, " and ", outfileLabs
def createAndSaveFeatureLabelData(msrcData, outfileBase, dataType, outfileType, nbSuperPixels, superPixelCompactness, ftype, aggtype, verbose): if verbose: print 'Creating feature set ', outfileBase if dataType == None or dataType == "": outfileFtrs = '%s_ftrs.%s' % (outfileBase, outfileType) outfileLabs = '%s_labs.%s' % (outfileBase, outfileType) else: outfileFtrs = '%s_%s_ftrs.%s' % (outfileBase, dataType, outfileType) outfileLabs = '%s_%s_labs.%s' % (outfileBase, dataType, outfileType) # Check can write these files. f = open(outfileFtrs, 'w') f.close() f = open(outfileLabs, 'w') f.close() if verbose: print ' - computing superpixels' allSuperPixels = superPixels.computeSuperPixelGraphMulti( \ [ z.m_img for z in msrcData ], 'slic', [nbSuperPixels, superPixelCompactness], nbCores=args.nbCores ) if verbose: print ' - computing features' superPixelFeatures = features.computeSuperPixelFeaturesMulti( [z.m_img for z in msrcData], allSuperPixels, ftype, aggtype, asMatrix=True, nbCores=args.nbCores) if verbose: print ' - extracting labels' superPixelLabels = classification.computeSuperPixelLabelsMulti( \ [z.m_gt for z in msrcData], allSuperPixels ) assert np.all(np.isfinite(superPixelFeatures)) # Don't save features with void labels. good = (superPixelLabels != pomio.getVoidIdx()) if not np.all(good): if verbose: print ' - discarding %d superpixels with void labels' % np.count_nonzero( np.logical_not(good)) superPixelLabels = superPixelLabels[good] superPixelFeatures = superPixelFeatures[good, :] if verbose: print ' - writing %d feature vectors of dimension %d to output files' % \ (superPixelFeatures.shape[0], superPixelFeatures.shape[1]) # Output if outfileType == 'pkl': pomio.pickleObject(superPixelFeatures, outfileFtrs) pomio.pickleObject(superPixelLabels, outfileLabs) elif outfileType == 'csv': pomio.writeMatToCSV(superPixelFeatures, outfileFtrs) pomio.writeMatToCSV(superPixelLabels, outfileLabs) else: assert False, 'unknown output file format ' + outfileType print 'Output written to file ', outfileFtrs, ' and ', outfileLabs