def filename_listener(request): predict, name = None, None if request.method == 'POST': filename = request.POST.get('filename') print filename imgFilesPathsWithLabels = {} imgFilesPathsWithLabels[filename] = 0 dictWordsImages=getWordsInImages(imgFilesPathsWithLabels, Dense=True, disableSIFTWrite=True) print "Using trained vocabulary or visual words" print "------------------------------------------------------" centroidFile = open('leaf/CENTROID.file') centroids=load(centroidFile) print "Computing Histogram from centroids" allwordVocabularyHistrogram=computeHistrogramByLevel(centroids,dictWordsImages) print "------------------------------------------------------" print "write the histogram.out" modelFile = open('leaf/model.file') clf = load(modelFile) predict, name = clf.predict(allwordVocabularyHistrogram.values())[0], allwordVocabularyHistrogram.keys()[0] jsonData = json.dumps({'predict':predict}) return HttpResponse(jsonData, content_type='application/json')
PRE_ALLOCATION_BUFFER = 1000 print "------------------------------------------------------" print "Generation SIFT words" print "------------------------------------------------------" if len(sys.argv) > 5 and sys.argv[5] == "Dense": Dense = True else: Dense = False centroids = getCentroids() f = open(sys.argv[2] + "/" + "histrogram.out", "w") datasetDir = sys.argv[2] + "/" + "Images" for file in os.listdir(datasetDir): name = datasetDir + "/" + file imgFilesPathsWithLabels = {} dictWordsImages = {} imgFilesPathsWithLabels[name] = "" dictWordsImages = getWordsInImages(imgFilesPathsWithLabels, disableSIFTWrite=True, Dense=Dense) allwordVocabularyHistrogram = computeHistrogramByLevel( centroids, dictWordsImages) #computeHistrogram(centroids,dictWordsImages) imgId = name.split("/")[3] print imgId d = map(str, (allwordVocabularyHistrogram[name]).tolist()) print >> f, imgId, " ".join(d)
datasetDir=sys.argv[2]+"/"+dirList for file in os.listdir(datasetDir): imgFilesPathsWithLabels[datasetDir+"/"+file]=dirList masksPath={} if len(sys.argv)>5 and sys.argv[5]=="Dense": print "Generation SIFT words" print "------------------------------------------------------" try: if sys.argv[6] and sys.argv[7]: for dirList in labels: masksDir=sys.argv[7]+"/"+dirList for file in os.listdir(masksDir): masksPath[sys.argv[2]+"/"+dirList+"/"+file]=masksDir+"/"+file dictWordsImages=getWordsInImages(imgFilesPathsWithLabels,masksPath,Dense=True) except IndexError: print "No masks avilable" print "------------------------------------------------------" dictWordsImages=getWordsInImages(imgFilesPathsWithLabels,Dense=True) else: print "Generation SIFT words" print "------------------------------------------------------" try: if sys.argv[6] and sys.argv[7]: for dirList in labels: masksDir=sys.argv[7]+"/"+dirList for file in os.listdir(masksDir): masksPath[sys.argv[2]+"/"+dirList+"/"+file]=masksDir+"/"+file dictWordsImages=getWordsInImages(imgFilesPathsWithLabels,masksPath,Dense=False) except IndexError:
labels=getImmediateSubdirectories(sys.argv[2]) pathToDatasetDir=[] imgFilesPathsWithLabels={} PRE_ALLOCATION_BUFFER=1000 print "------------------------------------------------------" print "Generation SIFT words" print "------------------------------------------------------" if len(sys.argv)>5 and sys.argv[5]=="Dense": Dense=True else: Dense=False centroids=getCentroids() f=open(sys.argv[2]+"/"+"histrogram.out","w") datasetDir=sys.argv[2]+"/"+"Images" for file in os.listdir(datasetDir): name=datasetDir+"/"+file imgFilesPathsWithLabels={} dictWordsImages={} imgFilesPathsWithLabels[name]="" dictWordsImages=getWordsInImages(imgFilesPathsWithLabels,disableSIFTWrite=True,Dense=Dense) allwordVocabularyHistrogram=computeHistrogramByLevel(centroids,dictWordsImages)#computeHistrogram(centroids,dictWordsImages) imgId=name.split("/")[3] print imgId d=map(str,(allwordVocabularyHistrogram[name]).tolist()) print >>f,imgId," ".join(d)
for dirList in labels: datasetDir=sys.argv[2]+"/"+dirList for file in os.listdir(datasetDir): imgFilesPathsWithLabels[datasetDir+"/"+file]=dirList masksPath={} if len(sys.argv)>5 and sys.argv[5]=="Dense": print "Generation SIFT words" print "------------------------------------------------------" try: if sys.argv[6] and sys.argv[7]: for dirList in labels: masksDir=sys.argv[7]+"/"+dirList for file in os.listdir(masksDir): masksPath[sys.argv[2]+"/"+dirList+"/"+file]=masksDir+"/"+file dictWordsImages=getWordsInImages(imgFilesPathsWithLabels,masksPath,Dense=True) except IndexError: print "No masks avilable" print "------------------------------------------------------" dictWordsImages=getWordsInImages(imgFilesPathsWithLabels,Dense=True) else: print "Generation SIFT words" print "------------------------------------------------------" try: if sys.argv[6] and sys.argv[7]: for dirList in labels: masksDir=sys.argv[7]+"/"+dirList for file in os.listdir(masksDir): masksPath[sys.argv[2]+"/"+dirList+"/"+file]=masksDir+"/"+file dictWordsImages=getWordsInImages(imgFilesPathsWithLabels,masksPath,Dense=False) except IndexError: