OBJECT - Type of object being annotatedANNOTATION - Type of annotationFEATURE - Type of feature produced by extractorpublic class KNNAnnotator<OBJECT,ANNOTATION,FEATURE> extends IncrementalAnnotator<OBJECT,ANNOTATION>
ObjectNearestNeighboursExact to perform the kNN search, so is
applicable to any objects that can be compared with a
DistanceComparator.| Modifier and Type | Field and Description |
|---|---|
protected List<Collection<ANNOTATION>> |
annotations |
protected Set<ANNOTATION> |
annotationsSet |
protected DistanceComparator<? super FEATURE> |
comparator |
protected FeatureExtractor<FEATURE,OBJECT> |
extractor |
protected List<FEATURE> |
features |
protected int |
k |
protected ObjectNearestNeighbours<FEATURE> |
nn |
protected float |
threshold |
| Constructor and Description |
|---|
KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor,
DistanceComparator<? super FEATURE> comparator)
Construct with the given extractor and comparator.
|
KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor,
DistanceComparator<? super FEATURE> comparator,
float threshold)
Construct with the given extractor, comparator and threshold.
|
KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor,
DistanceComparator<? super FEATURE> comparator,
int k)
Construct with the given extractor, comparator and number of neighbours.
|
KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor,
DistanceComparator<? super FEATURE> comparator,
int k,
float threshold)
Construct with the given extractor, comparator, number of neighbours and
threshold.
|
| Modifier and Type | Method and Description |
|---|---|
List<ScoredAnnotation<ANNOTATION>> |
annotate(OBJECT object)
Generate annotations for the given object.
|
static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> |
create(EXTRACTOR extractor,
DistanceComparator<FEATURE> comparator)
Create a new
KNNAnnotator with the given extractor and
comparator. |
static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> |
create(EXTRACTOR extractor,
DistanceComparator<FEATURE> comparator,
float threshold)
Create a new
KNNAnnotator with the given extractor, comparator
and threshold. |
static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> |
create(EXTRACTOR extractor,
DistanceComparator<FEATURE> comparator,
int k)
Create a new
KNNAnnotator with the given extractor, comparator
and number of neighbours. |
static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> |
create(EXTRACTOR extractor,
DistanceComparator<FEATURE> comparator,
int k,
float threshold)
Create a new
KNNAnnotator with the given extractor, comparator,
number of neighbours and threshold. |
Set<ANNOTATION> |
getAnnotations() |
int |
getK() |
void |
reset()
Reset the object to its initial condition, as if
it hasn't seen any training data.
|
void |
setK(int k)
Set the number of neighbours
|
void |
train(Annotated<OBJECT,ANNOTATION> annotated)
Train/update object using a new instance.
|
train, train, trainMultiClassclassifyprotected int k
protected final List<Collection<ANNOTATION>> annotations
protected final Set<ANNOTATION> annotationsSet
protected ObjectNearestNeighbours<FEATURE> nn
protected DistanceComparator<? super FEATURE> comparator
protected final float threshold
protected FeatureExtractor<FEATURE,OBJECT> extractor
public KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor, DistanceComparator<? super FEATURE> comparator, float threshold)
If the comparator defines a distance, then only scores below the distance will be accepted. If the threshold defines a similarity, then only scores above the threshold will be accepted.
extractor - the extractorcomparator - the comparatorthreshold - the threshold for successful matchespublic KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor, DistanceComparator<? super FEATURE> comparator)
extractor - the extractorcomparator - the comparatorpublic KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor, DistanceComparator<? super FEATURE> comparator, int k)
extractor - the extractorcomparator - the comparatork - the number of neighbourspublic KNNAnnotator(FeatureExtractor<FEATURE,OBJECT> extractor, DistanceComparator<? super FEATURE> comparator, int k, float threshold)
If the comparator defines a distance, then only scores below the distance will be accepted. If the threshold defines a similarity, then only scores above the threshold will be accepted.
extractor - the extractorcomparator - the comparatork - the number of neighboursthreshold - the threshold on distance for successful matchespublic static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> KNNAnnotator<OBJECT,ANNOTATION,FEATURE> create(EXTRACTOR extractor, DistanceComparator<FEATURE> comparator, float threshold)
KNNAnnotator with the given extractor, comparator
and threshold. The number of neighbours is set to 1.
If the comparator defines a distance, then only scores below the distance will be accepted. If the threshold defines a similarity, then only scores above the threshold will be accepted.
OBJECT - Type of object being annotatedANNOTATION - Type of annotationEXTRACTOR - Type of feature extractorFEATURE - Type of feature produced by extractorextractor - the extractorcomparator - the comparatorthreshold - the threshold for successful matchesKNNAnnotatorpublic static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> KNNAnnotator<OBJECT,ANNOTATION,FEATURE> create(EXTRACTOR extractor, DistanceComparator<FEATURE> comparator)
KNNAnnotator with the given extractor and
comparator. The number of neighbours is set to 1. The threshold test is
disabled.OBJECT - Type of object being annotatedANNOTATION - Type of annotationEXTRACTOR - Type of feature extractorFEATURE - Type of feature produced by extractorextractor - the extractorcomparator - the comparatorKNNAnnotatorpublic static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> KNNAnnotator<OBJECT,ANNOTATION,FEATURE> create(EXTRACTOR extractor, DistanceComparator<FEATURE> comparator, int k)
KNNAnnotator with the given extractor, comparator
and number of neighbours. The distance threshold is disabled.OBJECT - Type of object being annotatedANNOTATION - Type of annotationEXTRACTOR - Type of feature extractorFEATURE - Type of feature produced by extractorextractor - the extractorcomparator - the comparatork - the number of neighboursKNNAnnotatorpublic static <OBJECT,ANNOTATION,EXTRACTOR extends FeatureExtractor<FEATURE,OBJECT>,FEATURE> KNNAnnotator<OBJECT,ANNOTATION,FEATURE> create(EXTRACTOR extractor, DistanceComparator<FEATURE> comparator, int k, float threshold)
KNNAnnotator with the given extractor, comparator,
number of neighbours and threshold.
If the comparator defines a distance, then only scores below the distance will be accepted. If the threshold defines a similarity, then only scores above the threshold will be accepted.
OBJECT - Type of object being annotatedANNOTATION - Type of annotationEXTRACTOR - Type of feature extractorFEATURE - Type of feature produced by extractorextractor - the extractorcomparator - the comparatork - the number of neighboursthreshold - the threshold on distance for successful matchesKNNAnnotatorpublic void train(Annotated<OBJECT,ANNOTATION> annotated)
IncrementalTrainerannotated - instance to train withpublic void reset()
IncrementalTrainerpublic Set<ANNOTATION> getAnnotations()
public List<ScoredAnnotation<ANNOTATION>> annotate(OBJECT object)
Annotatorobject - the imagepublic int getK()
public void setK(int k)
k - the number of neighbours