@Override public List<ScoredAnnotation<ANNOTATION>> annotate(OBJECT image) { final int nAnnotations = numAnnotations.numAnnotations(); final List<ScoredAnnotation<ANNOTATION>> annos = new ArrayList<ScoredAnnotation<ANNOTATION>>(); for (int i = 0; i < nAnnotations; i++) { final int annotationIdx = rnd.nextInt(); annos.add(new ScoredAnnotation<ANNOTATION>(annotations.get(annotationIdx), 1.0f / annotations.size())); } return annos; }
@Override public List<ScoredAnnotation<ANNOTATION>> annotate(OBJECT object) { final FEATURE f = extractor.extractFeature(object); final List<ScoredAnnotation<ANNOTATION>> result = new ArrayList<ScoredAnnotation<ANNOTATION>>(); result.add(new ScoredAnnotation<ANNOTATION>(model.predict(f), 1)); return result; } }
@Override protected <ANNOTATION> List<ScoredAnnotation<ANNOTATION>> getAnnotations(VectorNaiveBayesCategorizer<ANNOTATION, PDF> categorizer, Vector vec) { final List<ScoredAnnotation<ANNOTATION>> results = new ArrayList<ScoredAnnotation<ANNOTATION>>(); final DefaultWeightedValueDiscriminant<ANNOTATION> r = categorizer.evaluateWithDiscriminant(vec); results.add(new ScoredAnnotation<ANNOTATION>(r.getValue(), (float) Math.exp(r.getWeight()))); return results; } };
@Override public List<ScoredAnnotation<ANNOTATION>> annotate(OBJECT image) { final int nAnnotations = numAnnotations.numAnnotations(); final List<ScoredAnnotation<ANNOTATION>> annos = new ArrayList<ScoredAnnotation<ANNOTATION>>(); for (int i = 0; i < nAnnotations; i++) { final int annotationIdx = annotationProbability.nextInt(); annos.add(new ScoredAnnotation<ANNOTATION>(annotations.get(annotationIdx), (float) annotationProbability .pdf(annotationIdx + 1))); } return annos; }
@Override public List<ScoredAnnotation<ANNOTATION>> annotate(OBJECT object) { final List<ScoredAnnotation<ANNOTATION>> results = new ArrayList<ScoredAnnotation<ANNOTATION>>(); for (final ANNOTATION annotation : annotations) { // skip the negative class if (annotation.equals(negativeClass)) continue; final FeatureVector feature = extractor.extractFeature(object); final Vector vector = convert(feature); final double result = classifiers.get(annotation).evaluateAsDouble(vector); if (result > 0) { results.add(new ScoredAnnotation<ANNOTATION>(annotation, (float) Math.abs(result))); } } return results; }
@Override protected <ANNOTATION> List<ScoredAnnotation<ANNOTATION>> getAnnotations(VectorNaiveBayesCategorizer<ANNOTATION, PDF> categorizer, Vector vec) { final List<ScoredAnnotation<ANNOTATION>> results = new ArrayList<ScoredAnnotation<ANNOTATION>>(); double logDenominator = Double.NEGATIVE_INFINITY; for (final ANNOTATION category : categorizer.getCategories()) { final double logPosterior = categorizer.computeLogPosterior(vec, category); logDenominator = LogMath.add(logDenominator, logPosterior); results.add(new ScoredAnnotation<ANNOTATION>(category, (float) logPosterior)); } for (final ScoredAnnotation<ANNOTATION> scored : results) scored.confidence = (float) Math.exp(scored.confidence - logDenominator); Collections.sort(results, Collections.reverseOrder()); return results; } },
/** * For a given {@link GroupedDataset} that represents the results from a * single category, returns a list of scored annotations for each group, for * question 1 (contains depication of category). * * @param data * The data * @return a list of {@link ScoredAnnotation} linked to image URL */ public static Map<String, List<ScoredAnnotation<QuestionResponse>>> getAnnotationsQ1( final GroupedDataset<String, ListDataset<Response>, Response> data) { final Map<String, List<ScoredAnnotation<QuestionResponse>>> r = new HashMap<String, List<ScoredAnnotation<QuestionResponse>>>(); // Loop through the images in this dataset for (final String imgUrl : data.getGroups()) { final ListDataset<Response> l = data.get(imgUrl); final List<ScoredAnnotation<QuestionResponse>> l2 = new ArrayList<ScoredAnnotation<QuestionResponse>>(); r.put(imgUrl, l2); // Loop through the responses for this image for (final Response rr : l) l2.add(new ScoredAnnotation<QuestionResponse>( rr.containsCategoryDepiction, rr.familiarityWithCategory)); } return r; }
/** * For a given {@link GroupedDataset} that represents the results from a * single category, returns a list of scored annotations for each group, for * question 2 (is in category). * * @param data * The group name to retrieve * @return a list of {@link ScoredAnnotation} linked to image URL */ public static Map<String, List<ScoredAnnotation<QuestionResponse>>> getAnnotationsQ2( final GroupedDataset<String, ListDataset<Response>, Response> data) { final Map<String, List<ScoredAnnotation<QuestionResponse>>> r = new HashMap<String, List<ScoredAnnotation<QuestionResponse>>>(); // Loop through the images in this dataset for (final String imgUrl : data.getGroups()) { final ListDataset<Response> l = data.get(imgUrl); final List<ScoredAnnotation<QuestionResponse>> l2 = new ArrayList<ScoredAnnotation<QuestionResponse>>(); r.put(imgUrl, l2); // Loop through the responses for this image for (final Response rr : l) l2.add(new ScoredAnnotation<QuestionResponse>( rr.isInCorrectCategory, rr.familiarityWithCategory)); } return r; }
/** * For a given {@link GroupedDataset} that represents the results from a * single category, returns a list of scored annotations for each group, for * question 1 (contains depication of category). * * @param data * The data * @return a list of {@link ScoredAnnotation} linked to image URL */ public static Map<String, List<ScoredAnnotation<QuestionResponse>>> getAnnotationsQ1( final GroupedDataset<String, ListDataset<Response>, Response> data) { final Map<String, List<ScoredAnnotation<QuestionResponse>>> r = new HashMap<String, List<ScoredAnnotation<QuestionResponse>>>(); // Loop through the images in this dataset for (final String imgUrl : data.getGroups()) { final ListDataset<Response> l = data.get(imgUrl); final List<ScoredAnnotation<QuestionResponse>> l2 = new ArrayList<ScoredAnnotation<QuestionResponse>>(); r.put(imgUrl, l2); // Loop through the responses for this image for (final Response rr : l) l2.add(new ScoredAnnotation<QuestionResponse>( rr.containsCategoryDepiction, rr.familiarityWithCategory)); } return r; }
/** * {@inheritDoc} * @see org.openimaj.ml.annotation.Annotator#annotate(java.lang.Object) */ @Override public List<ScoredAnnotation<ANNOTATION>> annotate( final OBJECT object ) { // Extract the feature and convert to a svm_node[] final svm_node[] nodes = SVMAnnotator.featureToNode( this.extractor.extractFeature( object ) ); // Use the trained SVM model to predict the new buffer's annotation final double x = svm.svm_predict( this.model, nodes ); // Create a singleton list to contain the classified annotation. return Collections.singletonList( new ScoredAnnotation<ANNOTATION>( x > 0 ? this.classMap.get(SVMAnnotator.POSITIVE_CLASS) : this.classMap.get(SVMAnnotator.NEGATIVE_CLASS), 1.0f ) ); }
/** * For a given {@link GroupedDataset} that represents the results from a * single category, returns a list of scored annotations for each group, for * question 2 (is in category). * * @param data * The group name to retrieve * @return a list of {@link ScoredAnnotation} linked to image URL */ public static Map<String, List<ScoredAnnotation<QuestionResponse>>> getAnnotationsQ2( final GroupedDataset<String, ListDataset<Response>, Response> data) { final Map<String, List<ScoredAnnotation<QuestionResponse>>> r = new HashMap<String, List<ScoredAnnotation<QuestionResponse>>>(); // Loop through the images in this dataset for (final String imgUrl : data.getGroups()) { final ListDataset<Response> l = data.get(imgUrl); final List<ScoredAnnotation<QuestionResponse>> l2 = new ArrayList<ScoredAnnotation<QuestionResponse>>(); r.put(imgUrl, l2); // Loop through the responses for this image for (final Response rr : l) l2.add(new ScoredAnnotation<QuestionResponse>( rr.isInCorrectCategory, rr.familiarityWithCategory)); } return r; }
@Override public List<ScoredAnnotation<ANNOTATION>> annotate(OBJECT image) { final double[] fv = extractor.extractFeature(image).asDoubleVector(); final Matrix F = new Matrix(new double[][] { fv }); final Matrix res = F.times(transform); final List<ScoredAnnotation<ANNOTATION>> ann = new ArrayList<ScoredAnnotation<ANNOTATION>>(); for (int i = 0; i < terms.size(); i++) { ann.add(new ScoredAnnotation<ANNOTATION>(terms.get(i), (float) res.get(0, i))); } Collections.sort(ann, new Comparator<ScoredAnnotation<ANNOTATION>>() { @Override public int compare(ScoredAnnotation<ANNOTATION> o1, ScoredAnnotation<ANNOTATION> o2) { return o1.confidence < o2.confidence ? 1 : -1; } }); return ann; }
result.add(new ScoredAnnotation<ANNOTATION>(annotationsList.get(i), (float) prob)); result.add(new ScoredAnnotation<ANNOTATION>(annotationsList.get(i), (float) prob));
result.add(new ScoredAnnotation<ANNOTATION>(annotationsList.get((int) clz), (float) prob)); return result;
@Override public List<ScoredAnnotation<ANNOTATION>> annotate(final OBJECT object) { if (this.nn == null) this.nn = new ObjectNearestNeighboursExact<FEATURE>(this.features, this.comparator); final TObjectIntHashMap<ANNOTATION> selected = new TObjectIntHashMap<ANNOTATION>(); final List<FEATURE> queryfv = new ArrayList<FEATURE>(1); queryfv.add(this.extractor.extractFeature(object)); final int[][] indices = new int[1][this.k]; final float[][] distances = new float[1][this.k]; this.nn.searchKNN(queryfv, this.k, indices, distances); int count = 0; for (int i = 0; i < this.k; i++) { // Distance check if (distances[0][i] > this.threshold) { continue; } final Collection<ANNOTATION> anns = this.annotations.get(indices[0][i]); for (final ANNOTATION ann : anns) { selected.adjustOrPutValue(ann, 1, 1); count++; } } final TObjectIntIterator<ANNOTATION> iterator = selected.iterator(); final List<ScoredAnnotation<ANNOTATION>> result = new ArrayList<ScoredAnnotation<ANNOTATION>>(selected.size()); while (iterator.hasNext()) { iterator.advance(); result.add(new ScoredAnnotation<ANNOTATION>(iterator.key(), (float) iterator.value() / (float) count)); } return result; }
p.setSecondObject(new ScoredAnnotation<String>("Unknown", 1.0f));
p.setSecondObject(new ScoredAnnotation<String>("Unknown", 1.0f));