public double singleSearch(int docNum) throws IOException, InstantiationException, IllegalAccessException { IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(indexPath))); // ----------- String query = reader.document(docNum).getValues("hash")[0]; CEDD ceddQuery = new CEDD(); ceddQuery.setByteArrayRepresentation( reader.document(docNum).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().bytes, reader.document(docNum).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().offset, reader.document(docNum).getField(DocumentBuilder.FIELD_NAME_CEDD).binaryValue().length); // ----------- HashSet<String> gold = new HashSet<String>(numImagesEval); ImageSearcher cis = ImageSearcherFactory.createCEDDImageSearcher(100); ImageSearchHits hits = cis.search(reader.document(docNum), reader); for (int i = 0; i < 10; i++) { gold.add(hits.doc(i).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]); } // ------------ IndexSearcher searcher = new IndexSearcher(reader); searcher.setSimilarity( new SimilarityBase() { @Override protected float score(BasicStats basicStats, float freq, float v2) { return 1; } @Override public String toString() { return null; } }); TopDocs topDocs = searcher.search(createQuery(query), 500); topDocs = rerank(topDocs, ceddQuery, reader); // System.out.println("topDocs.scoreDocs.length = " + topDocs.scoreDocs.length); double numMatches = 0; for (int i = 0; i < topDocs.scoreDocs.length; i++) { ScoreDoc scoreDoc = topDocs.scoreDocs[i]; // System.out.print(scoreDoc.score + ": "); String file = reader.document(scoreDoc.doc).getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]; // System.out.println(file.substring(file.lastIndexOf('/') + 1) + // (gold.contains(file)?" x":" o")); if (gold.contains(file)) numMatches++; } return numMatches; }
public void tttestMAPLocalFeatureHistogram() throws IOException { int maxSearches = 200; int maxHits = 100; IndexReader reader = IndexReader.open(FSDirectory.open(new File(indexPath))); IndexSearcher is = new IndexSearcher(reader); ImageSearcher searcher; // searcher = new SiftLocalFeatureHistogramImageSearcher(maxHits); searcher = ImageSearcherFactory.createColorHistogramImageSearcher(maxHits); // searcher = ImageSearcherFactory.createCEDDImageSearcher(maxHits); // searcher = ImageSearcherFactory.createFCTHImageSearcher(maxHits); Pattern p = Pattern.compile("\\\\\\d+\\.jpg"); double map = 0; for (int i = 0; i < sampleQueries.length; i++) { int id = sampleQueries[i]; System.out.print("id = " + id + ": "); String file = testExtensive + "/" + id + ".jpg"; ImageSearchHits hits = searcher.search(findDoc(reader, id + ".jpg"), reader); int goodOnes = 0; double avgPrecision = 0; for (int j = 0; j < hits.length(); j++) { Document d = hits.doc(j); String hitsId = d.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]; Matcher matcher = p.matcher(hitsId); if (matcher.find()) hitsId = hitsId.substring(matcher.start() + 1, hitsId.lastIndexOf(".")); else fail("Did not get the number ..."); int testID = Integer.parseInt(hitsId); // System.out.print(". " + hitsId + "/" + // d.getValues(DocumentBuilder.FIELD_NAME_IDENTIFIER)[0]+ " "); if ((int) Math.floor(id / 100) == (int) Math.floor(testID / 100)) { goodOnes++; System.out.print("x"); } else { System.out.print("o"); } // System.out.print(" (" + testID + ") "); avgPrecision += (double) goodOnes / (double) (j + 1); } avgPrecision = avgPrecision / hits.length(); map += avgPrecision; System.out.println(" " + avgPrecision + " (" + map / (i + 1) + ")"); } map = map / sampleQueries.length; System.out.println("map = " + map); }
public void testLsaFilter() throws IOException { // index images // indexFiles(); // search System.out.println("---< searching >-------------------------"); IndexReader reader = IndexReader.open(FSDirectory.open(new File(indexPath))); Document document = reader.document(0); ImageSearcher searcher = ImageSearcherFactory.createCEDDImageSearcher(100); ImageSearchHits hits = searcher.search(document, reader); // rerank System.out.println("---< filtering >-------------------------"); LsaFilter filter = new LsaFilter(CEDD.class, DocumentBuilder.FIELD_NAME_CEDD); hits = filter.filter(hits, document); // output FileUtils.saveImageResultsToHtml( "filtertest", hits, document.getField(DocumentBuilder.FIELD_NAME_IDENTIFIER).stringValue()); }
public void testPrecision() throws IOException, IllegalAccessException, InstantiationException { int maxHits = 200; // SimpleColorHistogram.DEFAULT_DISTANCE_FUNCTION = // SimpleColorHistogram.DistanceFunction.JSD; // computeErrorRate(ImageSearcherFactory.createColorHistogramImageSearcher(10), "Color // Histogram-L2"); // System.out.println("> CEDD"); // computeErrorRate(ImageSearcherFactory.createCEDDImageSearcher(maxHits), "CEDD"); // System.out.println("> FCTH"); // computeErrorRate(ImageSearcherFactory.createFCTHImageSearcher(maxHits), "FCTH"); // System.out.println("> JCD"); // computeErrorRate(new GenericImageSearcher(maxHits, JCD.class, "FIELD_JCD"), "CEDD"); System.out.println("> FuzzyColorHist"); // computeErrorRate(new GenericImageSearcher(maxHits, FuzzyColorHistogram.class, // "FIELD_FUZZYCOLORHIST"), "FuzzyColorHistogram"); // System.out.println("> JpegCoeffHist"); // computeErrorRate(new GenericImageSearcher(maxHits, JpegCoefficientHistogram.class, // "FIELD_JPEGCOEFFHIST"), "JpegCoefficientHistogram"); // System.out.println("> HSVColorHistogram"); // computeErrorRate(new GenericImageSearcher(maxHits, HSVColorHistogram.class, // "FIELD_HSVCOLORHIST"), "HSVColorHistogram"); // System.out.println("> SimpleColorHistogram"); // computeErrorRate(new GenericImageSearcher(maxHits, SimpleColorHistogram.class, // "FIELD_CH"), "SimpleColorHistogram"); // System.out.println("> AutoColorCorrelogram"); // computeErrorRate(new GenericImageSearcher(maxHits, AutoColorCorrelogram.class, // "FIELD_ACC"), "AutoColorCorrelogram"); // System.out.println("> Tamura"); // computeErrorRate(new GenericImageSearcher(maxHits, Tamura.class, "FIELD_TAMURA"), // "Tamura"); // System.out.println("> GeneralColorLayout"); // computeErrorRate(new GenericImageSearcher(maxHits, GeneralColorLayout.class, // "FIELD_GENCL"), "GeneralColorLayout"); // System.out.println("> ScalableColor"); // computeErrorRate(new SimpleImageSearcher(maxHits, 1.0f, 0f, 0f), "ScalableColor"); System.out.println("> ColorLayout"); computeErrorRate(ImageSearcherFactory.createColorLayoutImageSearcher(maxHits), "ColorLayout"); System.out.println("> ColorLayout (LSA)"); // computeErrorRateLsa(new SimpleImageSearcher(maxHits, 0f, 1f, 0f), "ColorLayout-Lsa"); // System.out.println("> Edgehist"); // computeErrorRate(new SimpleImageSearcher(maxHits, 0f, 0f, 1f), "EdgeHist"); }
public void testPerformance() throws IOException { MetricSpacesInvertedListIndexing mes = MetricSpacesInvertedListIndexing.getDefaultInstance(); int numSearches = 10; IndexReader reader = mes.getIndexReader(indexPath); System.out.println(reader.maxDoc() + " documents"); TopDocs docs; long ms = System.currentTimeMillis(); for (int i = 0; i < numSearches; i++) { docs = mes.search(reader.document(i), indexPath); } ms = System.currentTimeMillis() - ms; System.out.println("ms = " + ms); ImageSearcher ceddSearcher = ImageSearcherFactory.createCEDDImageSearcher(100); ms = System.currentTimeMillis(); for (int i = 0; i < numSearches; i++) { ceddSearcher.search(reader.document(i), reader); } ms = System.currentTimeMillis() - ms; System.out.println("ms = " + ms); }